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

ASF GitHub Bot commented on GROOVY-12651:
-----------------------------------------

testlens-app[bot] commented on PR #3172:
URL: https://github.com/apache/groovy/pull/3172#issuecomment-6618170730

   ## ✅ All tests passed ✅
   
   🏷️ Commit: be980534e061edb88ebcb5ae5d9972b2752c1700
   ▶️ Tests:  110891 executed
   ⚪️ Checks: 26/26 completed
   
   ---
   _Learn more about TestLens at 
[testlens.app/docs](https://testlens.app/docs/features/pr-comment/)._
   




> 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
>            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)

Reply via email to