You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Eric Milles (Jira)" <ji...@apache.org> on 2021/10/12 15:32:00 UTC

[jira] [Resolved] (GROOVY-10222) Unable to infer the type parameter of a parameterized function

     [ https://issues.apache.org/jira/browse/GROOVY-10222?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Eric Milles resolved GROOVY-10222.
----------------------------------
    Fix Version/s: 4.0.0-beta-2
       Resolution: Fixed

> Unable to infer the type parameter of a parameterized function
> --------------------------------------------------------------
>
>                 Key: GROOVY-10222
>                 URL: https://issues.apache.org/jira/browse/GROOVY-10222
>             Project: Groovy
>          Issue Type: Bug
>          Components: Static Type Checker
>            Reporter: Thodoris Sotiropoulos
>            Assignee: Eric Milles
>            Priority: Major
>             Fix For: 4.0.0-beta-2
>
>
> I have the following program
> {code:java}
> class A {
>     static <T> T foo() {
>         return null;
>     }
> }
> class Test<T> {
>     void bar() {
>         T x = A.foo();
>     }
> }
> {code}
> h3. Actual Behaviour
> {code:java}
> org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
> groovy11.groovy: 9: [Static type checking] - Cannot assign value of type #T to variable of type T
>  @ line 9, column 15.
>            T x = A.foo();
>                  ^1 error
> {code}
> h3. Expected Behaviour
> Compile successfully
>  
> I don't know however, if this is a limitation of the inference engine of groovyc or a bug. Note that the Java compiler compiles the above program successfully. Also note that if I replace "T x = A.foo()" with "String x = A.foo()", groovyc compiles the updated program.
>  



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