You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Paul King (Jira)" <ji...@apache.org> on 2022/02/03 22:35:01 UTC

[jira] [Closed] (GROOVY-8452) @CompileStatic, generic with 'extends' bug: Expected parameter of type ? but got A

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

Paul King closed GROOVY-8452.
-----------------------------

> @CompileStatic, generic with 'extends' bug:  Expected parameter of type ? but got A
> -----------------------------------------------------------------------------------
>
>                 Key: GROOVY-8452
>                 URL: https://issues.apache.org/jira/browse/GROOVY-8452
>             Project: Groovy
>          Issue Type: Bug
>          Components: Static compilation
>    Affects Versions: 2.4.13, 3.0.0-alpha-3, 2.5.2
>            Reporter: Xiaoguang Wang
>            Assignee: Eric Milles
>            Priority: Major
>             Fix For: 4.0.0-beta-1, 3.0.9
>
>
>  
> The inferred type of a generic List<? extends X> is wrong.
> The minimal reproduceable code is:
> {code:java}
> import groovy.transform.CompileStatic
> class A {}
> class B extends A {}
> @CompileStatic
> class TestClassSort {
>     void test() {
>         //List<? extends A> a  // without ` = null`, this compiles OK
>         List<? extends A> a = null
>         if(false) {
>             a = new ArrayList<A>()
>         } else {
>             a = new ArrayList<B>()
>         }
>         //BUG: Error: Groovyc: Expected parameter of type ? but got A
>         a.sort({ A v1, A v2 -> return 0 })
>     }
>     static void main(String []a) {
>         new TestClassSort().test()
>     }
> }
> {code}
>  



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