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 2022/05/13 13:18:00 UTC

[jira] [Created] (GROOVY-10622) Wrong type is inferred when involving a bounded type parameter in a parameterized method call

Thodoris Sotiropoulos created GROOVY-10622:
----------------------------------------------

             Summary: Wrong type is inferred when involving a bounded type parameter in a parameterized method call
                 Key: GROOVY-10622
                 URL: https://issues.apache.org/jira/browse/GROOVY-10622
             Project: Groovy
          Issue Type: Bug
          Components: Static Type Checker
            Reporter: Thodoris Sotiropoulos


I have the following program

{code}
class A<T> {
  T m() {
    return null;
  }
}

class B {
  B(byte x) {}
}

class C<T> {
  T x;

  C(T x) {
    this.x = x;
  }
}

class Test {
  <T extends A<Byte>> void test() {
    C<T> a = new C<T>(null);
    T x = a.x;
    new B(x.m()); // should type check
  }
}
{code}

h3. Actual behavior

{code}
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
test.groovy: 23: [Static type checking] - Cannot find matching method B#<init>(java.lang.Object). Please check if the declared type is correct and if the method exists.
 @ line 23, column 5.
       new B(x.m());
       ^

1 error
{code}

h3. Expected behavior

Compile successfully

Tested against master (commit: ee12bb52381e8f0583c61fc25d43de1f55b80a87)



--
This message was sent by Atlassian Jira
(v8.20.7#820007)