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/11/03 15:29:00 UTC

[jira] [Created] (GROOVY-10342) STC is unable to infer type parameter of parameterized method call

Thodoris Sotiropoulos created GROOVY-10342:
----------------------------------------------

             Summary: STC is unable to infer type parameter of parameterized method call
                 Key: GROOVY-10342
                 URL: https://issues.apache.org/jira/browse/GROOVY-10342
             Project: Groovy
          Issue Type: Bug
          Components: Static Type Checker
            Reporter: Thodoris Sotiropoulos


This bug may be related to GROOVY-10222.

I have the following program
{code:java}
class A<T> {
  T f;
}

class Test {
  static <T> T m() { return null; }

  static <T extends Number> void test() {
    String x = m(); // works

    A<String> y = new A<>();
    y.f = m(); // works

    A<T> z = new A<T>();
    z.f = m(); // does not work
  }

}
{code}

h3. Actual behaviour

{code}
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
test.groovy: 15: [Static type checking] - Cannot assign value of type #T to variable of type T
 @ line 15, column 11.
       z.f = m();
             ^

1 error
{code}

h3. Expected behavior

Compile successfully

*NOTE*: Replacing `T extends Number` with `T` compiles code successfully.

Tested against master.



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