Skip to content

GROOVY-11970: Provide support for compound assignment operator overlo…#2499

Merged
paulk-asert merged 1 commit into
apache:masterfrom
paulk-asert:groovy11970
May 2, 2026
Merged

GROOVY-11970: Provide support for compound assignment operator overlo…#2499
paulk-asert merged 1 commit into
apache:masterfrom
paulk-asert:groovy11970

Conversation

@paulk-asert
Copy link
Copy Markdown
Contributor

…ading (GEP-15)

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds GEP-15 support for dedicated compound-assignment operator overloads (e.g. plusAssign) across static type checking, bytecode generation, @OperatorRename, documentation, and tests.

Changes:

  • Introduces *Assign method resolution in the static type checker and propagates the resolved target to static codegen.
  • Adds dynamic-mode compound-assign dispatch via ScriptBytecodeAdapter.compoundAssign and updates bytecode generation to use it.
  • Documents the feature in the operator spec and adds a focused test suite for compound assignment behavior.

Reviewed changes

Copilot reviewed 13 out of 13 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
src/test/groovy/groovy/operator/CompoundAssignmentTest.groovy New tests covering static/dynamic *Assign selection, fallback behavior, final handling (static), setter skipping (static), and @OperatorRename scenarios.
src/spec/doc/core-operators.adoc Documents compound assignment operator overloading and method mapping table.
src/main/java/org/codehaus/groovy/transform/stc/StaticTypesMarker.java Adds metadata key to carry resolved *Assign target from STC into codegen.
src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java Resolves *Assign methods for compound-assign tokens and records the chosen target; skips setter-info when in-place mutation applies.
src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java Adds token→*Assign method-name mapping helper.
src/main/java/org/codehaus/groovy/transform/OperatorRenameASTTransformation.java Extends @OperatorRename to support *Assign renames with precedence over base operator renames.
src/main/java/org/codehaus/groovy/syntax/Types.java Treats REMAINDER_EQUAL as an assignment operator token.
src/main/java/org/codehaus/groovy/runtime/ScriptBytecodeAdapter.java Adds dynamic dispatcher helper for *Assign vs fallback operator call.
src/main/java/org/codehaus/groovy/classgen/asm/sc/StaticTypesBinaryExpressionMultiTypeDispatcher.java Emits in-place *Assign calls during static compilation when STC resolved a target; maintains legacy property-set fast-path.
src/main/java/org/codehaus/groovy/classgen/asm/BinaryExpressionMultiTypeDispatcher.java Overrides compound-assign emission to retain primitive/array fast paths.
src/main/java/org/codehaus/groovy/classgen/asm/BinaryExpressionHelper.java Routes compound-assign tokens through new evaluateCompoundAssign helper-based path.
src/main/java/org/codehaus/groovy/classgen/Verifier.java Skips final-variable reassignment checks for compound assigns marked as in-place via STC metadata.
src/main/java/groovy/transform/OperatorRename.java Adds annotation members for *Assign renames.

Comment thread src/spec/doc/core-operators.adoc Outdated
Comment thread src/test/groovy/groovy/operator/CompoundAssignmentTest.groovy
@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Apr 28, 2026

Codecov Report

❌ Patch coverage is 84.72222% with 22 lines in your changes missing coverage. Please review.
✅ Project coverage is 67.2449%. Comparing base (8dde1c8) to head (0c2bb71).
⚠️ Report is 6 commits behind head on master.

Files with missing lines Patch % Lines
...ovy/transform/OperatorRenameASTTransformation.java 63.1579% 12 Missing and 2 partials ⚠️
...taticTypesBinaryExpressionMultiTypeDispatcher.java 88.8889% 3 Missing ⚠️
...us/groovy/classgen/asm/BinaryExpressionHelper.java 92.8571% 1 Missing and 1 partial ⚠️
...roovy/transform/stc/StaticTypeCheckingVisitor.java 91.3044% 1 Missing and 1 partial ⚠️
...codehaus/groovy/runtime/ScriptBytecodeAdapter.java 83.3333% 0 Missing and 1 partial ⚠️
Additional details and impacted files

Impacted file tree graph

@@                Coverage Diff                 @@
##               master      #2499        +/-   ##
==================================================
+ Coverage     67.2264%   67.2449%   +0.0185%     
- Complexity      31984      32016        +32     
==================================================
  Files            1468       1468                
  Lines          123923     124054       +131     
  Branches        22251      22266        +15     
==================================================
+ Hits            83309      83420       +111     
- Misses          33433      33452        +19     
- Partials         7181       7182         +1     
Files with missing lines Coverage Δ
...in/java/org/codehaus/groovy/classgen/Verifier.java 90.0938% <100.0000%> (+0.0207%) ⬆️
...ssgen/asm/BinaryExpressionMultiTypeDispatcher.java 86.9347% <100.0000%> (-1.7833%) ⬇️
...rc/main/java/org/codehaus/groovy/syntax/Types.java 74.0458% <ø> (ø)
...roovy/transform/stc/StaticTypeCheckingSupport.java 82.0292% <100.0000%> (+0.2190%) ⬆️
...dehaus/groovy/transform/stc/StaticTypesMarker.java 100.0000% <100.0000%> (ø)
...codehaus/groovy/runtime/ScriptBytecodeAdapter.java 65.4762% <83.3333%> (+0.2588%) ⬆️
...us/groovy/classgen/asm/BinaryExpressionHelper.java 88.8179% <92.8571%> (-1.1985%) ⬇️
...roovy/transform/stc/StaticTypeCheckingVisitor.java 87.5000% <91.3044%> (+0.0230%) ⬆️
...taticTypesBinaryExpressionMultiTypeDispatcher.java 86.9565% <88.8889%> (+0.1918%) ⬆️
...ovy/transform/OperatorRenameASTTransformation.java 64.3564% <63.1579%> (+3.4189%) ⬆️

... and 6 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.

Comment thread src/main/java/org/codehaus/groovy/runtime/ScriptBytecodeAdapter.java Outdated
Comment thread src/main/java/org/codehaus/groovy/runtime/ScriptBytecodeAdapter.java Outdated
@paulk-asert paulk-asert merged commit 7b26481 into apache:master May 2, 2026
25 checks passed
@paulk-asert paulk-asert deleted the groovy11970 branch May 2, 2026 06:04
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.

4 participants