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

Type checker doesn't infer generics properly

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.0-beta-2
    • 2.0-beta-3
    • None
    • None

    Description

      In the following code, the computed lowest upper bound of the list doesn't have the correct type.

      class Test {
          static test2() {
              if (new Random().nextBoolean()) {
                  def a = new ArrayList<String>()
                  a << "a" << "b" << "c"
                  return a
              } else {
                  def b = new LinkedList<Number>()
                  b << 1 << 2 << 3
                  return b
              }
          }
      
          static test() {
              def result = test2()
              result[0].toInteger()
              //result[0].toString()
          }
      }
      new Test()
      

      Attachments

        Activity

          People

            melix Cédric Champeau
            melix Cédric Champeau
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: