Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-8427

Issue With Static Compiler And Generics

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.4.13
    • 2.5.15, 3.0.8, 4.0.0-beta-1
    • Compiler
    • None

    Description

      This code will compile:

      src/main/groovy/demo/Bar.groovy
      package demo
      import java.util.function.Consumer
      import groovy.transform.CompileStatic
      
      @CompileStatic
      class Bar {
      
          static <T> void foo(T a, Consumer<T> c) {  }
      
          static void main(args) {
              def c = {
                  foo('') {
                      println 'hello'
                  }
              }
          }
      }
      

      This code will not compile:

      src/main/groovy/demo/Bar.groovy
      package demo
      import java.util.function.Consumer
      import groovy.transform.CompileStatic
      
      @CompileStatic
      class Bar {
      
          static <T> void foo(T a, Consumer<T> c) {  }
      
          static void main(args) {
              def c = {
                  // this following line is the only difference
                  int x = 0
                  foo('') {
                      println 'hello'
                  }
              }
          }
      }
      
      /Users/jeffbrown/projects/project/src/main/groovy/demo/Bar.groovy: 14: [Static type checking] - Cannot call <T> demo.Bar#foo(T, java.util.function.Consumer <T>) with arguments [java.lang.String, groovy.lang.Closure <java.lang.Void>] 
       @ line 14, column 13.
                     foo('') {
                     ^
      
      1 error
      

      I have only tested with Groovy 2.4.13.

      Attachments

        Activity

          People

            emilles Eric Milles
            jeffscottbrown Jeff Scott Brown
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: