Skip to content

GROOVY-12099: Elvis-assignment on array element evaluates receiver an…#2622

Open
paulk-asert wants to merge 1 commit into
apache:masterfrom
paulk-asert:groovy12099
Open

GROOVY-12099: Elvis-assignment on array element evaluates receiver an…#2622
paulk-asert wants to merge 1 commit into
apache:masterfrom
paulk-asert:groovy12099

Conversation

@paulk-asert

Copy link
Copy Markdown
Contributor

…d index twice

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 @CompileStatic cases for arrays and lists, including receiver/index side-effect ordering.
  • Update BinaryExpressionHelper.evaluateElvisEqual to 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.

@testlens-app

testlens-app Bot commented Jun 23, 2026

Copy link
Copy Markdown

✅ All tests passed ✅

⚠️ TestLens detected flakiness ⚠️

Test Summary

Build and test / lts (17, windows-latest, 1) > :test

Test Runs
GenericsSTCTest > testReturnTypeInferenceWithMethodGenerics18() ❌ ✅
GenericsSTCTest > testReturnTypeInferenceWithMethodGenerics18a() ❌ ✅
GenericsStaticCompileTest > testReturnTypeInferenceWithMethodGenerics18() ❌ ✅
GenericsStaticCompileTest > testReturnTypeInferenceWithMethodGenerics18a() ❌ ✅

Build and test / lts (25, ubuntu-latest) > :test

Test Runs
StreamClassloaderInScriptTest > testSerializationToFileWithinScript ❌ ✅

🏷️ Commit: 0f55195
▶️ Tests: 40609 executed
⚪️ Checks: 30/30 completed


Learn more about TestLens at testlens.app.

@codecov-commenter

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 87.50000% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 68.4541%. Comparing base (40c6203) to head (0f55195).
⚠️ Report is 5 commits behind head on master.

Files with missing lines Patch % Lines
...us/groovy/classgen/asm/BinaryExpressionHelper.java 87.5000% 1 Missing and 2 partials ⚠️
Additional details and impacted files

Impacted file tree graph

@@                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     
Files with missing lines Coverage Δ
...us/groovy/classgen/asm/BinaryExpressionHelper.java 88.7346% <87.5000%> (-0.0833%) ⬇️

... and 9 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants