You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Eric Milles (Jira)" <ji...@apache.org> on 2020/12/04 17:46:00 UTC

[jira] [Updated] (GROOVY-9847) STC: regression in private inner class type inference

     [ https://issues.apache.org/jira/browse/GROOVY-9847?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Eric Milles updated GROOVY-9847:
--------------------------------
    Description: 
Backport of GROOVY-7549 caused a regression in temp type inference of local variable assignment.  Consider the following:
{code:groovy}
            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
                    }
                }
            }
{code}

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

  was:
Backport of GROOVY-7549 caused a regression in temp type inference of local variable assignment.  Consider the following:
{code:groovy}
            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
                    }
                }
            }
{code}


> STC: regression in private inner class type inference
> -----------------------------------------------------
>
>                 Key: GROOVY-9847
>                 URL: https://issues.apache.org/jira/browse/GROOVY-9847
>             Project: Groovy
>          Issue Type: Bug
>    Affects Versions: 2.4.20, 2.5.13
>            Reporter: Eric Milles
>            Assignee: Eric Milles
>            Priority: Major
>
> Backport of GROOVY-7549 caused a regression in temp type inference of local variable assignment.  Consider the following:
> {code:groovy}
>             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
>                     }
>                 }
>             }
> {code}
> *Note*: This test case works fine for {{3_0_X}} and {{master}}.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)