You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Daniel Sun (Jira)" <ji...@apache.org> on 2020/08/01 11:36:00 UTC

[jira] [Resolved] (GROOVY-7232) Delegation inconsistent between methods and properties in nested closures

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

Daniel Sun resolved GROOVY-7232.
--------------------------------
    Fix Version/s: 4.0.0-alpha-1
       Resolution: Fixed

> Delegation inconsistent between methods and properties in nested closures
> -------------------------------------------------------------------------
>
>                 Key: GROOVY-7232
>                 URL: https://issues.apache.org/jira/browse/GROOVY-7232
>             Project: Groovy
>          Issue Type: Bug
>          Components: groovy-runtime
>    Affects Versions: 2.3.2, 2.3.7, 2.4.0-rc-1
>            Reporter: Matthew Farrell
>            Assignee: Eric Milles
>            Priority: Major
>              Labels: breaking
>             Fix For: 4.0.0-alpha-1
>
>         Attachments: DelegateTest.groovy
>
>          Time Spent: 20m
>  Remaining Estimate: 0h
>
> When a closure's resolveStrategy is set to DELEGATE_ONLY or DELEGATE_FIRST, resolution is different in nested closures between methods and properties of the delegate. For example, in the following, {{x}} resolves to {{f}}'s delegate (what I expect), but {{keySet()}} resolves to {{g}}'s delegate.
> {code}
> def g = {->
>     def f = {
>         {-> [x, keySet()]}()
>     }
>     f.resolveStrategy = Closure.DELEGATE_ONLY
>     f.delegate = [x: 1, f: 0]
>     f()
> }      
> g.delegate = [x: 0, g: 0]
> g()
> {code}
> Result: {code}[1, ['x', 'g']]{code}
> Whereas without the nested closure
> {code}
> def g = {->
>     def f = {
>         [x, keySet()]
>     }
>     f.resolveStrategy = Closure.DELEGATE_ONLY
>     f.delegate = [x: 1, f: 0]
>     f()
> }      
> g.delegate = [x: 0, g: 0]
> g()
> {code}
> Result: {{[1, ['x', 'f']]}}



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