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

ClosureParams type inference compilation error when wrapping closure with object

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.4.6, 2.5.15, 4.0.0-beta-1, 3.0.9
    • 3.0.14, 2.5.20, 4.0.7
    • Static compilation
    • None

    Description

      The following code does not compile:

      import groovy.transform.*
      import groovy.transform.stc.*
      
      @CompileStatic
      class Test {
      
          class A<IN> {
              Closure c
      
              A(@ClosureParams(value = FromString, options = 'IN') Closure c) {
                  this.c = c
              }
      
              void call(IN param) {
                  c.call(param)
              }
          }
      
          def <IN> A wrap(@ClosureParams(value = FromString, options = 'IN') Closure c) {
              new A<IN>(c)
          }
      
          def test() {
              (wrap { i -> i.size() }).call([])
          }
      
      }
      

      Compilation error:

      org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
      /tmp/groovy-2.4.6/test.groovy: 25: [Static type checking] - Cannot find matching method java.lang.Object#size(). Please check if the declared type is right and if the method exists.
       @ line 24, column 22.
                 (wrap { i -> i.size() }).call([])
      

      I'd expect 'i' being infered as java.util.List
      Explicit this.<List>wrap does not help neither

      Attachments

        Issue Links

          Activity

            People

              emilles Eric Milles
              kbialek Krzysztof BiaƂek
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: