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

STC: regression in private inner class type inference

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.4.20, 2.5.13
    • 2.4.22, 2.5.15
    • None
    • None

    Description

      Backport of GROOVY-7549 caused a regression in temp type inference of local variable assignment. Consider the following:

                  class Test {
                      @groovy.transform.ToString(excludes='children')
                      private static class TreeAttr {
                          String name
                          Integer val = 0
                          List<TreeAttr> children = []
                      }
      
                      void test(Integer count) {
                          TreeAttr root = new TreeAttr(name:'foo')
                          List<TreeAttr> collector = root.children
      
                          for (name in ['bar','baz']) { // tokens in a path
                              def item = collector.find { it.name == name }
                              if (!item) {
                                  item = new TreeAttr(name: name)
      // inferred type of "item" is Object after this point
                                  collector.add(item)
                              }
                              collector = item.children
                              if (count) item.val += count
                          }
                      }
                  }
      

      Note: This test case works fine for 3_0_X and master.

      Attachments

        Activity

          People

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

            Dates

              Created:
              Updated:
              Resolved: