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

Static type error when using generic methods and Closures as parameters

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.3.7, 2.4.1
    • 2.3.11, 2.4.2
    • Static compilation
    • None

    Description

      import groovy.transform.CompileStatic
      @CompileStatic
      class Test {
      
          static class Inner {
              private String baz
              
              void setBaz(String b) {
                  this.baz = b
              }
          }
          
          static <T> T fun(T t) {
              return t
          }
       
          static void main(String[] args) {
              Test.fun({ 1 }).resolveStrategy = Closure.DELEGATE_FIRST
              ((Closure)Test.fun({ 1 })).resolveStrategy = Closure.DELEGATE_FIRST
              Test.fun(new Test.Inner()).baz = 'foo'
              Test.fun('String').contains('ing')
          }
      }
      
      Test.main()
      

      With @CompileStatic this code produces the following error:
      [Static type checking] - No such property: resolveStrategy for class: java.lang.Object

      Without @CompileStatic the code runs without error.

      Attachments

        Issue Links

          Activity

            People

              melix Cédric Champeau
              gcadien Geoff Cadien
              Votes:
              1 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: