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

Paul King updated GROOVY-7232:
------------------------------
    Description: 
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']]}}

  was:
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: {code}[1, ['x', 'f']]{code}


> 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
>         Attachments: DelegateTest.groovy
>
>          Time Spent: 10m
>  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)

Reply via email to