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

Generic return type with raw upper bound is not inferred from argument properly

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Critical
    • Resolution: Cannot Reproduce
    • Affects Version/s: 2.5.11
    • Fix Version/s: None
    • Component/s: Static Type Checker
    • Labels:
      None

      Description

      classes.java
      interface I<T> {}
      
      class C implements I<Object> {}
      
      interface Container {
          <T extends I> T getInstance(Class<T> c);
      }
      
      playground.groovy
      @groovy.transform.CompileStatic
      def usage(Container pc) {
          C instance = pc.getInstance(C)
          println(instance)
      }
      
      $ groovy -version
      Groovy Version: 2.5.11 JVM: 1.8.0_231 Vendor: Oracle Corporation OS: Mac OS X
      $ javac classes.java
      $ groovyc playground.groovy
      org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
      playground.groovy: 3: [Static type checking] - Cannot assign value of type I <T extends java.lang.Object> to variable of type C
       @ line 3, column 18.
             C instance = pc.getInstance(C)
                          ^
      
      1 error
      

      PS real life use case:

      • I is org.gradle.api.Plugin
      • C is org.gradle.plugins.ear.EarPlugin
      • Container#getInstance is org.gradle.api.plugins.PluginContainer#findPlugin

        Attachments

          Activity

            People

            • Assignee:
              emilles Eric Milles
              Reporter:
              daniilo Daniil Ovchinnikov
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: