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

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

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

Eric Milles resolved GROOVY-9996.
---------------------------------
    Fix Version/s: 4.0.0-alpha-3
       Resolution: Fixed

> 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
>            Assignee: Eric Milles
>            Priority: Major
>             Fix For: 4.0.0-alpha-3
>
>          Time Spent: 0.5h
>  Remaining Estimate: 0h
>
> 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)