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 2021/04/05 19:49:00 UTC

[jira] [Created] (GROOVY-10011) Combining flow typing and type argument inference does not work as expected

Thodoris Sotiropoulos created GROOVY-10011:
----------------------------------------------

             Summary: Combining flow typing and type argument inference does not work as expected
                 Key: GROOVY-10011
                 URL: https://issues.apache.org/jira/browse/GROOVY-10011
             Project: Groovy
          Issue Type: Bug
          Components: Static Type Checker
            Reporter: Thodoris Sotiropoulos


I have the following program
{code:java}
class A<T> {
  T f;
  public A(T f) {
    this.f = f;
  }
}

class Foo {}
class Bar extends Foo {}

public class Main {
  public static void bar(Foo x) {
    if (x instanceof Bar) {
      A<Bar> a = new A<>(x)
    }
  }
}
{code}
h3. Actual Behavior
{code:java}
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
test.groovy: 15: [Static type checking] - Incompatible generic argument types. Cannot assign A <Foo> to: A <Bar>
 @ line 15, column 18.
         A<Bar> a = new A<>(x)
                    ^1 error

{code}
h3. Expected Behavior

Compile successfully

 

Tested against https://github.com/apache/groovy/commit/359be2b662be646d2d59db8b999412691891231d



--
This message was sent by Atlassian Jira
(v8.3.4#803005)