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

Unexpected behaviour when the return type of a closure is a type parameter

    XMLWordPrintableJSON

    Details

      Description

      This may be a recent regression.

      I have the following program

      class Foo<T extends Number> {
        T f  Foo(T f) {
          this.f = f
        }
        T foo() {
          Closure<T> clos = { -> f}
          clos()
        }
      }
      

      Actual behaviour

      org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
      test.groovy: 10: [Static type checking] - Cannot return value of type java.lang.Object on method returning type T
       @ line 10, column 5.
             clos()
             ^1 error
      
      

      Expected behaviour

      Compile successfully

      Comment

      The code works as expected if I remove the bound from the type parameter of class `Foo`.

       

      Tested against https://github.com/apache/groovy/commit/f3d030afaaae44eca567ead74e68efb932831b08

        Attachments

          Activity

            People

            • Assignee:
              emilles Eric Milles
              Reporter:
              theosot Thodoris Sotiropoulos
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: