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/02/17 02:02:00 UTC

[jira] [Updated] (GROOVY-10499) Incomplete type variable substitution when using wildcard type and diamond operator

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

Thodoris Sotiropoulos updated GROOVY-10499:
-------------------------------------------
    Description: 
I have the following groovy program

{code:java}
class Foo<T> {
  Foo(T x) {}
}

class Bar<T> {
  Bar(Foo<? extends T> foo, T p) {

  }

  T m(T x) {
    return null;
  }
}

public class Test<T>  {
  void test() {
    T x = null;
    new Bar<>(new Foo<T>(x), x).m(x);
  }  
}
{code}

h3. Actual behaviour

groovyc rejects the program by raising

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

1 error
{code}

h3. Expected behaviour

Compile successfully.


The bug happens when:
* The constructor of `Bar` expects a parameterized type containing a wildcard type (i.e., `Foo<? extends T>`
* The constructor of `Bar` expects something of type `T` (i.e., `T p`).

Tested against master (commit: 85676f1855bbe751bac897ea3fdd900fbbe74ecb).

  was:
I have the following groovy program

{code:java}
class Foo<T> {
  Foo(T x) {}
}

class Bar<T> {
  Bar(Foo<? extends T> foo, T p) {

  }

  T m(T x) {
    return null;
  }
}

public class Test<T>  {
  void test() {
    T x = null;
    new Bar<>(new Foo<T>(x), x).m(x);
  }  
}
{code}

h3. Actual behaviour

groovyc rejects the program by raising

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

1 error
{code}

h3. Expected behaviour

Compile successfully.


Tested against master (commit: 85676f1855bbe751bac897ea3fdd900fbbe74ecb).


> Incomplete type variable substitution when using wildcard type and diamond operator
> -----------------------------------------------------------------------------------
>
>                 Key: GROOVY-10499
>                 URL: https://issues.apache.org/jira/browse/GROOVY-10499
>             Project: Groovy
>          Issue Type: Bug
>            Reporter: Thodoris Sotiropoulos
>            Priority: Major
>
> I have the following groovy program
> {code:java}
> class Foo<T> {
>   Foo(T x) {}
> }
> class Bar<T> {
>   Bar(Foo<? extends T> foo, T p) {
>   }
>   T m(T x) {
>     return null;
>   }
> }
> public class Test<T>  {
>   void test() {
>     T x = null;
>     new Bar<>(new Foo<T>(x), x).m(x);
>   }  
> }
> {code}
> h3. Actual behaviour
> groovyc rejects the program by raising
> {code}
> org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
> test.groovy: 20: [Static type checking] - Cannot find matching method Bar#m(T). Please check if the declared type is correct and if the method exists.
>  @ line 20, column 5.
>        new Bar<>(new Foo<T>(x), x).m(x);
>        ^
> 1 error
> {code}
> h3. Expected behaviour
> Compile successfully.
> The bug happens when:
> * The constructor of `Bar` expects a parameterized type containing a wildcard type (i.e., `Foo<? extends T>`
> * The constructor of `Bar` expects something of type `T` (i.e., `T p`).
> Tested against master (commit: 85676f1855bbe751bac897ea3fdd900fbbe74ecb).



--
This message was sent by Atlassian Jira
(v8.20.1#820001)