GROOVY-12099: Elvis-assignment on array element evaluates receiver an…#2622
Open
paulk-asert wants to merge 1 commit into
Open
GROOVY-12099: Elvis-assignment on array element evaluates receiver an…#2622paulk-asert wants to merge 1 commit into
paulk-asert wants to merge 1 commit into
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes GROOVY-12099 by ensuring Elvis-assignment with a subscript LHS (e.g. a[i] ?= b) evaluates the receiver and index exactly once (left-to-right), reusing them for both the getAt read and putAt write during bytecode generation.
Changes:
- Add regression tests covering dynamic and
@CompileStaticcases for arrays and lists, including receiver/index side-effect ordering. - Update
BinaryExpressionHelper.evaluateElvisEqualto cache subscript receiver/index into temporaries for non-safe subscripts and reuse them for read/write. - Introduce a small helper to evaluate-and-store an expression in a temporary slot while preserving type information for subsequent resolution.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/test/groovy/bugs/Groovy12099.groovy | Adds focused regression coverage for single-evaluation and correct semantics across falsy/truthy, side effects, arrays/lists, and @CompileStatic. |
| src/main/java/org/codehaus/groovy/classgen/asm/BinaryExpressionHelper.java | Adjusts Elvis-assignment bytecode rewrite for subscript LHS to avoid duplicate receiver/index evaluation by storing them into temporaries and reusing loaders. |
✅ All tests passed ✅Test SummaryBuild and test / lts (17, windows-latest, 1) > :test
Build and test / lts (25, ubuntu-latest) > :test
🏷️ Commit: 0f55195 Learn more about TestLens at testlens.app. |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #2622 +/- ##
==================================================
- Coverage 68.4541% 68.4541% -0.0001%
- Complexity 33505 33512 +7
==================================================
Files 1518 1518
Lines 127107 127129 +22
Branches 23065 23067 +2
==================================================
+ Hits 87010 87025 +15
- Misses 32371 32377 +6
- Partials 7726 7727 +1
🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
…d index twice