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

Bounded type parameter is not captured by closure

    XMLWordPrintableJSON

Details

    Description

      I have the following Groovy program

      class Bar {}
      
      class Foo<T extends Bar> {
        public T method(T x) {
          def bar = {x}
          return bar()
        }
      }
      

      Actual Behavior

      The compiler raise the following compile-time error 

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

      Expected Behavior

      Compile successfully. Notably, when I remove the "extends" keyword from the type parameter, the code type checks as expected.

       

      Attachments

        Activity

          People

            emilles Eric Milles
            theosot Thodoris Sotiropoulos
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: