You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Stefanos Chaliasos (Jira)" <ji...@apache.org> on 2021/03/22 08:37:00 UTC

[jira] [Created] (GROOVY-9996) Cannot infer correct type argument when using subtyping

Stefanos Chaliasos created GROOVY-9996:
------------------------------------------

             Summary: Cannot infer correct type argument when using subtyping
                 Key: GROOVY-9996
                 URL: https://issues.apache.org/jira/browse/GROOVY-9996
             Project: Groovy
          Issue Type: Bug
            Reporter: Stefanos Chaliasos


I have the following Groovy program.
{code:groovy}
@groovy.transform.CompileStatic
public class Main {
  public static void main(String[] args) {
    Foo foo = new Bar()
    def x = new A<>(foo)
    bar(x)
  }

  public static void bar(A<Foo> f) {}
}

class A<T> {
  T f;
  public A(T f) {
    this.f = f;
  }
}

class Foo {}
class Bar extends Foo {}
{code}
h2. Actual Behavior

The program does not compile, and I get the following error.
{code:java}
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
Main.groovy: 6: [Static type checking] - Cannot call Main#bar(A <Foo>) with arguments [A <Bar>]
 @ line 6, column 5.
       bar(x)
       ^

1 error

{code}
h2. Expected Behavior

Compile successfully.
h2. Affected Version

This should be a regression. The program compiles with 3.0.7 and 4.0.0-alpha-2, but fails with the compiler from Master (commit: e69c874e1a6a3cdeb236bad6a6faa061a30c88ca).



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