Scott Murphy Heiberg created GROOVY-12653:
---------------------------------------------

             Summary: Closure packing copies a local written after the literal 
by value in a constructor or instance initializer block
                 Key: GROOVY-12653
                 URL: https://issues.apache.org/jira/browse/GROOVY-12653
             Project: Groovy
          Issue Type: Bug
    Affects Versions: 7.0.0-alpha-1
            Reporter: Scott Murphy Heiberg


With closure packing enabled ({{-Dgroovy.target.closure.pack=true}} or 
{{@PackedClosures}}), a local captured by a closure literal in a constructor or 
an instance initializer block, and written after the literal, is copied into 
the packed closure by value instead of shared:
{code:groovy}
class R { def r; R() { def c; c = { x -> c == null ? 'stale' : 'set' }; r = 
c(1) }
          def m() { def c; c = { x -> c == null ? 'stale' : 'set' }; c(1) } }
class I { def r; { def c; c = { x -> c == null ? 'stale' : 'set' }; r = c(1) } }
[new R().r, new R().m(), new I().r]
{code}
*Actual* (dynamic and @CompileStatic, packing on): {{[stale, set, stale]}}.

*Expected:* {{[set, set, set]}}, as without packing and as in a method.

Cause: the lookup of names written after the literal 
({{ClosureWriter.holderCaptureNames}}) uses 
{{WriterController.getMethodNode()}}, which is null while a constructor is 
written, so no capture is threaded as a shared Reference.



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

Reply via email to