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

STC: lowed bound wildcard inference produces false positives

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • None
    • 4.0.0-rc-1
    • None
    • None

    Description

      Follow up from GROOVY-10339 and possibly related to GROOVY-10047, GROOVY-9998 and GROOVY-9803. Consider the following:

      class Pogo {
        String x
      }
      class Sorter implements Comparator<Pogo>, Serializable {
        int compare(Pogo p1, Pogo p2) { p1.x <=> p2.x }
      }
      @groovy.transform.TypeChecked
      void test(Pogo[] pogos) {
        List<String> strings = pogos.sort(true, new Sorter()).collect { Pogo pogo ->
          pogo.x
        }
        print strings
      }
      test(new Pogo(x:'foo'),new Pogo(x:'bar'))
      

      Current STC has difficulty with multiple type witnesses for the "sort" call, which supplies Pogo[] for T[] and Sorter for Comparator<? super T>.

      STC errors:

      Incompatible generic argument types. Cannot assign java.util.List<java.lang.Object> to: java.util.List<java.lang.String>
      Expected parameter of type java.lang.Object but got Pogo
      No such property: x for class: java.lang.Object
      

      Attachments

        Issue Links

          Activity

            People

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

              Dates

                Created:
                Updated:
                Resolved: