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/18 19:55:00 UTC

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

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

Eric Milles updated GROOVY-10342:
---------------------------------
    Description: 
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.

  was:
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.


> 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
>            Assignee: Eric Milles
>            Priority: Major
>
> 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.20.7#820007)