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/06/20 09:37:00 UTC

[jira] [Created] (GROOVY-10662) Fail to substitute type variable when encountering conflicting type parameter with a bound

Thodoris Sotiropoulos created GROOVY-10662:
----------------------------------------------

             Summary: Fail to substitute type variable when encountering conflicting type parameter with a bound
                 Key: GROOVY-10662
                 URL: https://issues.apache.org/jira/browse/GROOVY-10662
             Project: Groovy
          Issue Type: Bug
          Components: Static Type Checker
            Reporter: Thodoris Sotiropoulos


This might be related to GROOVY-10367.

I have the following program:

{code}
class A<X, T> {
  A(T p1, X p2) {}

  void foo(X x) {}
}

class B<T extends Number> {
  void test() {
    T x = (T) null;
    Character y = (Character) 'd';
    new A<>(y, x).foo((T) null);
  }
}
{code}

h3. Actual behaviour

{code}
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
test.groovy: 12: [Static type checking] - Cannot find matching method A#foo(T). Please check if the declared type is correct and if the method exists.
 @ line 12, column 5.
       new A<>(y, x).foo((T) null);
       ^

1 error
{code}

h3. Expected behaviour

Compile successfully

**Notes:** To trigger this bug, the following conditions should be met:
  1. The second type parameter of class A must have the same name with the type parameter of class B.
  2. We must use the diamond operator for constructing the receiver object at line 12.

Tested against master (commit: fface1c9fe7f20a1d4c50b4cb00ead62bfaa31cb)



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