codeconsole opened a new pull request, #3368:
URL: https://github.com/apache/groovy/pull/3368

   The packability analysis (`ClosureWriter#isPackable`) keeps a closure as a 
class when its body names one of the Closure pseudo-properties (`owner`, 
`delegate`, `thisObject`, `directive`, `resolveStrategy`, `metaClass`). It 
tested the name of every `VariableExpression` alone, so it also declined a 
closure that only reads a method parameter or local variable of that name:
   
   ```groovy
   @CompileStatic @PackedClosures
   class OwnerName {
       static String greet(String owner, List<String> pets) {
           Closure<String> c = { String pet -> owner + ' owns ' + pet }   // 
stayed OwnerName$_greet_closure1
           pets.collect(c).join(', ')
       }
   }
   ```
   
   Such a variable hides the Closure property in a closure class too, so the 
body does not use the property. With `@PackedClosures(mode = STRICT)` this was 
a compile error whose message says the closure uses owner/delegate/thisObject 
although it uses none of them.
   
   ### The change
   
   `visitVariableExpression` in `ClosureWriter#isPackable` now declines for one 
of those names only when the accessed variable is not a `Parameter` or a 
declared local variable. A name bound to a field or property of the enclosing 
class, or to nothing, still reads the Closure property in a closure class and 
keeps declining.
   
   ### Tests
   
   Two tests added to `ClosurePackCapabilityTest`: a parameter and a local of 
those names are packed and give the same result (fails without the change), and 
a field named `owner` still declines. Run with JDK 21: 
`ClosurePackCapabilityTest` 24 and `PackedClosuresTransformTest` 59, 0 failures.
   
   The defect is in 6.0.0 and 6.0.1 as well; please consider the change for 
`GROOVY_6_0_X`.
   
   https://issues.apache.org/jira/browse/GROOVY-12840
   


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

Reply via email to