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 2022/05/16 15:48:00 UTC

[jira] [Updated] (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 updated GROOVY-10330:
---------------------------------
    Fix Version/s: 3.0.11

> 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
>             Fix For: 4.0.0-beta-2, 3.0.11
>
>
> 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.20.7#820007)