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

Daniel Sun resolved GROOVY-12651.
---------------------------------
    Fix Version/s: 7.0.0-alpha-1
                   6.0.1
         Assignee: Daniel Sun
       Resolution: Fixed

Fixed on master in dfc788bc4ed0b103a594466416562be06c445b0d 
(https://github.com/apache/groovy/commit/dfc788bc4ed0b103a594466416562be06c445b0d,
 #3172) and on the GROOVY_6_0_X branch in 
f220446cb0d8e2bc5d2f8660ad39b98acc932729 
(https://github.com/apache/groovy/commit/f220446cb0d8e2bc5d2f8660ad39b98acc932729).

> Closure packing packs a closure literal stored or composed into a field, 
> property or index by ?=, ??=, <<=, >>= or +=
> ---------------------------------------------------------------------------------------------------------------------
>
>                 Key: GROOVY-12651
>                 URL: https://issues.apache.org/jira/browse/GROOVY-12651
>             Project: Groovy
>          Issue Type: Bug
>    Affects Versions: 6.0.0
>            Reporter: Scott Murphy Heiberg
>            Assignee: Daniel Sun
>            Priority: Major
>             Fix For: 7.0.0-alpha-1, 6.0.1
>
>
> {code:groovy}
> @groovy.transform.PackedClosures
> class C {
>     void install(Holder h) { h.handler ?= { x -> x * 2 } }
> }
> class Holder { Closure handler }
> def h = new Holder()
> new C().install(h)
> h.handler.delegate = 'some delegate'
> println h.handler(21)
> {code}
> *Actual:* the literal is packed ({{PackedClosure$Fixed1}}), and setting the 
> delegate throws {{UnsupportedOperationException: Cannot set a delegate on a 
> @PackedClosures closure (hoisted method '$packed$closure$0') ...}}
> *Expected:* the closure escapes its method, so the escape gate declines it 
> and keeps its closure class. The script then prints 42, as it does without 
> packing.
> The same happens for {{??=}}, for {{<<=}} and {{>>=}} on a Closure slot (the 
> stored ComposedClosure keeps a packed clone of the literal and passes 
> setDelegate on to it), and for {{<<=}} and {{+=}} on a collection slot. It 
> happens in dynamic code, under {{@TypeChecked}} and under {{@CompileStatic}}, 
> and with {{-Dgroovy.target.closure.pack=true}}. 
> {{ClosureWriter.collectEscapingClosures}} counted only {{=}} on a non-local 
> target and {{<<}} as escapes.



--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

Reply via email to