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

[jira] [Created] (GROOVY-10317) Type variable substitution does not work properly on parameterized function's return type

Thodoris Sotiropoulos created GROOVY-10317:
----------------------------------------------

             Summary: Type variable substitution does not work properly on parameterized function's return type
                 Key: GROOVY-10317
                 URL: https://issues.apache.org/jira/browse/GROOVY-10317
             Project: Groovy
          Issue Type: Bug
          Components: Static Type Checker
            Reporter: Thodoris Sotiropoulos


I have the following program

{code:java}
class A<T1, T2> {
  void m1(T1 x) {}

  void test() {
    var x = new B();
    T2 y = null;
    (new A<T2, T2>()).m1(x.m2(y));
  }
  
}

class B {
  <X, Y> X m2(Y x) { return null; }
}
{code}

h3. Actual behaviour

{code}
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
test.groovy: 8: [Static type checking] - Cannot call A#m1(T2) with arguments [#X]
 @ line 8, column 5.
       (new A<T2, T2>()).m1(x.m2(y));
       ^

1 error
{code}

h3. Expected behaviour

Compile successfully.

**Note**: If I change the expected type of parameter `x` in method `m1(T1 x)` to `m1(T2 x`), the program compiles as expected.

Tested against master



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