GROOVY-12098: Pre/post increment on array element double-evaluates th…#2621
Conversation
There was a problem hiding this comment.
Pull request overview
Note
Copilot couldn't run its full agentic review because no GitHub Actions runner was available. Make sure your repository has a runner available to run Copilot's review, or add a copilot-setup-steps.yml file specifying one with the runs-on attribute. See the docs for more details.
Adds regression coverage and fixes bytecode generation so pre/post inc/dec on subscript expressions (a[i]++, ++a[i], etc.) evaluates the receiver and index exactly once and in left-to-right order.
Changes:
- Introduces a new regression test suite for GROOVY-12098 covering order, single-evaluation, and value semantics for arrays/lists (including
@CompileStaticcases). - Updates
BinaryExpressionHelperto cache both subscript receiver and index into temporaries and reuse them for the read (getAt) and write (putAt) paths.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| src/test/groovy/bugs/Groovy12098.groovy | Adds regression tests verifying evaluation order, single-evaluation, and correct values for array/list subscript inc/dec. |
| src/main/java/org/codehaus/groovy/classgen/asm/BinaryExpressionHelper.java | Caches subscript receiver+index into temporaries to prevent double-evaluation during read-modify-write operations. |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #2621 +/- ##
==================================================
+ Coverage 68.4541% 68.4796% +0.0255%
- Complexity 33505 33524 +19
==================================================
Files 1518 1518
Lines 127107 127124 +17
Branches 23065 23064 -1
==================================================
+ Hits 87010 87054 +44
+ Misses 32371 32333 -38
- Partials 7726 7737 +11
🚀 New features to boost your workflow:
|
✅ All tests passed ✅🏷️ Commit: 19149bb Learn more about TestLens at testlens.app. |
…e receiver