[ 
https://issues.apache.org/jira/browse/GROOVY-8394?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16266741#comment-16266741
 ] 

Jochen Theodorou commented on GROOVY-8394:
------------------------------------------

additional information: Setting no strategy in @DelegatesTo means OWNER_FIRST. 
As described, the owner of the child Closure is the parent Closure, which means 
the call should be resolved as if done from the owner Closure. This seems not 
to be the case

> @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
>
> {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
(v6.4.14#64029)

Reply via email to