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/04/28 10:56:00 UTC

[jira] [Created] (GROOVY-10601) Incompatible generic argument type when combining conditionals and bounded type parameters

Thodoris Sotiropoulos created GROOVY-10601:
----------------------------------------------

             Summary: Incompatible generic argument type when combining conditionals and bounded type parameters
                 Key: GROOVY-10601
                 URL: https://issues.apache.org/jira/browse/GROOVY-10601
             Project: Groovy
          Issue Type: Bug
          Components: Static Type Checker
            Reporter: Thodoris Sotiropoulos


I have the following program

{code}
class Foo<X> {}

class Test {

  public static <T extends Foo<Number>> T test() {
    T x = (T) null;
    T y = (true) ? x : (T) null;
    y
  }
}
{code}

h3. Actual behaviour

The compiler rejects the program with

{code}
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
test.groovy: 8: [Static type checking] - Incompatible generic argument types. Cannot assign Foo<java.lang.Object> to: T
 @ line 8, column 5.
       y
       ^

1 error
{code}

h3. Expected behaviour

Compile successfully

**NOTE:** This bug occurs only when `test` and `Foo` have type parameters with different names.

Tested against master (commit: 5c468cd352f37fb5c599a3f51534ffcc55b339ed).



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