You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Daniil Ovchinnikov (Jira)" <ji...@apache.org> on 2020/05/15 17:09:00 UTC

[jira] [Created] (GROOVY-9555) Generic return type with raw upper bound is not inferred from argument properly

Daniil Ovchinnikov created GROOVY-9555:
------------------------------------------

             Summary: Generic return type with raw upper bound is not inferred from argument properly
                 Key: GROOVY-9555
                 URL: https://issues.apache.org/jira/browse/GROOVY-9555
             Project: Groovy
          Issue Type: Bug
          Components: Static Type Checker
    Affects Versions: 2.5.11
            Reporter: Daniil Ovchinnikov


{code:title=classes.java}
interface I<T> {}

class C implements I<Object> {}

interface Container {
    <T extends I> T getInstance(Class<T> c);
}
{code}

{code:title=playground.groovy}
@groovy.transform.CompileStatic
def usage(Container pc) {
    C instance = pc.getInstance(C)
    println(instance)
}
{code}

{noformat}
$ 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
{noformat}


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}}



--
This message was sent by Atlassian Jira
(v8.3.4#803005)