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

Regression in groovyc 3.0 and 4.0 and Compile static with generic static method in trait

    XMLWordPrintableJSON

Details

    Description

      After upgrading to groovy 3.0 this code fails to compile (can't pass type checker).

      import groovy.transform.CompileStatic
      
      @CompileStatic
      trait StaticTrait {
          static <T> T wrapClosure(Closure<T> callable) {
              callable()
          }
      }
      
      class ClassWithTrait implements StaticTrait {}
      
      @CompileStatic
      class ClassCaller {
          void call() {
              ClassWithTrait.wrapClosure {
                  println("fails to compile")
                  0
              }
          }
      }
      
      new ClassCaller().call()
       

      Error output:

      % groovyc test1.groovy
      org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
      test1.groovy: 15: [Static type checking] - Cannot find matching method ClassWithTrait#wrapClosure(groovy.lang.Closure <java.lang.Integer>). Please check if the declared type is correct and if the method exists.
       @ line 15, column 9.
                 ClassWithTrait.wrapClosure {
                 ^
      
      
      1 error 

      It compiles fine with 2.5.13.

      Attachments

        Activity

          People

            emilles Eric Milles
            arixmkii Arthur Sengileyev
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Time Tracking

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0h
                0h
                Logged:
                Time Spent - 50m
                50m