Thodoris Sotiropoulos created GROOVY-10330:
----------------------------------------------

             Summary: 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


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)

Reply via email to