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/30 15:26:00 UTC

[jira] [Assigned] (GROOVY-10330) STC instantiates type variable with a wrong type when calling an instance method of the same class

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

Eric Milles reassigned GROOVY-10330:
------------------------------------

    Assignee: Eric Milles

> STC instantiates type variable with a wrong type when calling an instance method of the same class
> --------------------------------------------------------------------------------------------------
>
>                 Key: GROOVY-10330
>                 URL: https://issues.apache.org/jira/browse/GROOVY-10330
>             Project: Groovy
>          Issue Type: Bug
>          Components: Static Type Checker
>            Reporter: Thodoris Sotiropoulos
>            Assignee: Eric Milles
>            Priority: Major
>
> I have the following program
> {code:java}
> import java.util.function.Function;
> class A<T> {
>   T y;
>   void foo(T x, Function<T, T> func) {
>     foo((true) ? x : y, func)
>   }
> }
> {code}
> h3. Actual behavior
> {code}
> org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
> test.groovy: 6: [Static type checking] - Cannot call A#foo(java.lang.Object, java.util.function.Function<java.lang.Object, java.lang.Object>) with arguments [java.lang.Object<T>, java.util.function.Function<T, T>]
>  @ line 6, column 5.
>        foo((true) ? x : y, func)
>        ^
> 1 error
> {code}
> h3. Expected behaviour
> Compile successfully
> *Note*: If replace `Function<T, T> func` with `Supplier<T> func`, the code compiles as expected.
> Tested against master.



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