You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Xiaoguang Wang (JIRA)" <ji...@apache.org> on 2018/01/18 17:33:00 UTC

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

Xiaoguang Wang created GROOVY-8452:
--------------------------------------

             Summary: @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: Compiler
    Affects Versions: 2.4.13
            Reporter: Xiaoguang Wang


 

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
(v7.6.3#76005)