paulk-asert opened a new pull request, #3315: URL: https://github.com/apache/groovy/pull/3315
https://issues.apache.org/jira/browse/GROOVY-12790 When a script has an instance `main` or a `run()` method and no statements other than declarations, `ModuleNode.createStatementsClass()` turns its declarations into fields. The multiple-assignment handling had two problems: - A right-hand side that was not a list literal hit a bare `break`, so that declaration and every later one were silently dropped: ```groovy def (a, b) = "xy".toList() def c = 3 void main() { println "a=$a c=$c" } // MissingPropertyException: No such property: a ``` - With a list literal, targets were paired with elements one by one, which is wrong for the newer forms: `def (h, *t) = [1, 2, 3]` gave `t == 2`. Each target is still a field, but the multiple assignment is now kept as a `(a, b) = rhs` assignment in the class's instance initializer, with the targets' rest-binding and map-key metadata. So a rest binding, map style, typed or `val` targets and any right-hand side behave as they do elsewhere. Field initializers run before the instance initializer, so declarations after the first multiple assignment are assigned there too, to keep their order. Declarations before it, and scripts without one, compile as before. `Groovy12790` covers the instance-`main` and `run()` paths, a later declaration that uses the tuple's values, rest binding, map style, typed and final targets, and a `@CompileStatic` `main`. All 8 tests fail on master and pass with the fix. `bugs.*`, `gls.*`, the parser tests, `ScriptsAndClassesSpecTest` (4143 tests) and `:checkstyleGate :codenarcGate :rat` pass locally on JDK 17. The same loop is on GROOVY_5_0_X, GROOVY_5_1_X and GROOVY_6_0_X, from GROOVY-11118. #3314 (`@NoScript`) touches the same method and will be rebased on this. -- 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]
