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

Incompatible generic argument types on closure's return type

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 4.0.0-beta-1
    • Component/s: Static Type Checker
    • Labels:
      None

      Description

      This is related to GROOVY-10082.

      I have the following program

       

      class Foo<T> {}
      
      class Bar<T> extends Foo<Integer> {}
      class Baz extends Foo<Integer> {}
      
      public class Main {
        public static void main(String[] args) {
          Closure<Foo<Integer>> z = { -> new Baz()} // this works
          Closure<Foo<Integer>> f = { -> new Bar<String>()} // this doesn't work
        } 
      }
      

       

      Actual Behaviour

       

      org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
      test.groovy: 9: [Static type checking] - Incompatible generic argument types. Cannot assign groovy.lang.Closure<Bar<java.lang.String>> to: groovy.lang.Closure<Foo<java.lang.Integer>>
       @ line 9, column 31.
             Closure<Foo<Integer>> f = { -> new Bar<String>()} // this doesn't work
                                       ^1 error
      
      

      Expected Behaviour

      Compile successfully

       

      Tested against https://github.com/apache/groovy/commit/200c0eaf4c477201429fc7dbc30557952eaa54da

       

       

       

        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: