codeconsole opened a new pull request, #3176:
URL: https://github.com/apache/groovy/pull/3176
With closure packing (`@PackedClosures` or
`-Dgroovy.target.closure.pack=true`), the compile-time escape gate in
`ClosureWriter` treated every assignment target that is not a `FieldNode` or
`PropertyNode` as a local. A bare name bound to a `DynamicVariable` is not a
local. It is stored through the MOP into the script binding, or into a dynamic
property of the owner, where code outside the method reads it:
```groovy
@groovy.transform.PackedClosures
def install() { handler = { x -> x + 1 } }
install()
handler.delegate = 'd' // UnsupportedOperationException: Cannot set a
delegate on a @PackedClosures closure
```
The same thing happened when a method of an annotated class stores to an
undeclared name that `propertyMissing` takes, when a script method stores to an
`@Field` (outside `run()` still a `DynamicVariable`), and, with the flag, for a
binding store in a script's `run()` and in `@CompileStatic` code whose type
checking extension makes the variable dynamic. Seen in 6.0.0 too.
`ClosureWriter.isLocalTarget` now treats a `DynamicVariable` like a field or
property, so such a store is declined as an escape. Stores to parameters and
declared locals still pack. The `@PackedClosures` Javadoc lists binding
variables among the escapes.
The compound stores of #3172 (GROOVY-12651) go through `isLocalTarget`, so
they pick this up once both are merged.
## Tests
`PackedClosuresTransformTest.bindingAndDynamicPropertyStoresAreDeclinedAtCompileTime`
(script binding, `@Field` from a script method, a dynamic property of an
annotated class) and
`PackedClosuresTransformTest.flagPathDeclinesBindingStores` (script `run()`,
and `@CompileStatic` with a `makeDynamic` extension) fail without the change.
The closure-packing test classes, `org.codehaus.groovy.classgen.asm.sc.*` and
`groovy.transform.stc.*` (including `ClosuresSTCTest`) pass. The Checkstyle and
CodeNarc gates pass.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]