You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Paul King (Jira)" <ji...@apache.org> on 2020/11/11 02:02:05 UTC
[jira] [Closed] (GROOVY-8394) @CompileStatic doesn't respect
resolve strategy on closures
[ https://issues.apache.org/jira/browse/GROOVY-8394?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Paul King closed GROOVY-8394.
-----------------------------
> @CompileStatic doesn't respect resolve strategy on closures
> -----------------------------------------------------------
>
> Key: GROOVY-8394
> URL: https://issues.apache.org/jira/browse/GROOVY-8394
> Project: Groovy
> Issue Type: Bug
> Components: Static compilation, Static Type Checker
> Affects Versions: 2.4.13
> Reporter: Daniil Ovchinnikov
> Priority: Major
> Fix For: 2.5.8
>
>
> {code}
> class Root {
> Parent parent = new Parent()
> def parent(@DelegatesTo(Parent) Closure cl) {
> cl.delegate = parent
> cl()
> }
> }
> class Parent {
> Child child = new Child()
> def child(@DelegatesTo(Child) Closure cl) {
> cl.delegate = child
> cl()
> }
> def foo() { "parent" }
> }
> class Child {
> def foo() { "child" }
> }
> @groovy.transform.CompileStatic
> def usage() {
> new Root().parent {
> child {
> foo()
> }
> }
> }
> println usage()
> {code}
> Expected result: {{parent}}
> Actual result: {{child}}
> Closure inside {{child {}}} call has default resolve strategy, i.e. owner first. Its owner is a closure passed to {{parent {}}}, which is delegated to {{Parent}}, which in turn has the method {{foo}}.
> Works properly without {{@CompileStatic}}.
--
This message was sent by Atlassian Jira
(v8.3.4#803005)