groovy
  1. groovy
  2. GROOVY-5384

Type checker doesn't infer generics properly

    Details

    • Type: Bug Bug
    • Status: Closed Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 2.0-beta-2
    • Fix Version/s: 2.0-beta-3
    • Component/s: None
    • Labels:
      None
    • Number of attachments :
      0

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

        Activity

        Show
        CÚdric Champeau added a comment - Fixed by commits: https://github.com/groovy/groovy-core/commit/25c2a19a36e927c268898bd181df0920b52ec970 https://github.com/groovy/groovy-core/commit/5d2cdfd86813217e5ca8d05f503e008fea059f66

          People

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

            Dates

            • Created:
              Updated:
              Resolved: