[
https://issues.apache.org/jira/browse/GROOVY-12651?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Scott Murphy Heiberg updated GROOVY-12651:
------------------------------------------
Affects Version/s: 6.0.0
> 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: 7.0.0-alpha-1, 6.0.0
> Reporter: Scott Murphy Heiberg
> Priority: Major
>
> {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)