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

Type checker doesn't infer generics properly

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 2.0-beta-2
    • Fix Version/s: 2.0-beta-3
    • Component/s: None
    • Labels:
      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

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

              Dates

              • Created:
                Updated:
                Resolved: