Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-8452

@CompileStatic, generic with 'extends' bug: Expected parameter of type ? but got A

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.4.13, 3.0.0-alpha-3, 2.5.2
    • 4.0.0-beta-1, 3.0.9
    • Static compilation
    • None

    Description

       

      The inferred type of a generic List<? extends X> is wrong.

      The minimal reproduceable code is:

      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()
          }
      }
      
      

       

      Attachments

        Activity

          People

            emilles Eric Milles
            wxiaoguang Xiaoguang Wang
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: