Skip to content

GROOVY-12232: Wrap AIC cast arguments only when the generated constru… - #2801

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

GROOVY-12232: Wrap AIC cast arguments only when the generated constru…#2801
paulk-asert wants to merge 1 commit into
apache:masterfrom
paulk-asert:groovy12232

Conversation

@paulk-asert

Copy link
Copy Markdown
Contributor

…ctor delegates to super dynamically

Since 5.0.0-alpha-4 (GROOVY-6285/GROOVY-9244), writeAICCall wraps every non-primitive cast argument in a PojoWrapper so the anonymous inner class's generated constructor can select among ambiguous super constructors by the declared cast type at runtime — the dynamic selectConstructorAndTransformArguments path unwraps it. But when the super constructor is arity-unique, the generated constructor binds it statically and consumes its Object parameter with a plain cast, which the wrapper reaches intact: new Test(['a'] as Set) {} failed with GroovyCastException 'Cannot cast PojoWrapper to Set' (reduced from Gradle's test suite).

writeAICCall now evaluates the same predicate the constructor's own compilation uses for its super call (arity-unique candidate, no spread arguments — mirroring makeDirectConstructorCall) against the generated constructor's super call, found by scanning its body (the this$0 assignment may precede it), and wraps only when delegation will be dynamic. Both consumers now see what they expect: the dynamic selector receives wrappers and keeps choosing by cast type; a statically bound super call receives the plain value.

…ctor delegates to super dynamically

Since 5.0.0-alpha-4 (GROOVY-6285/GROOVY-9244), writeAICCall wraps every
non-primitive cast argument in a PojoWrapper so the anonymous inner
class's generated constructor can select among ambiguous super
constructors by the declared cast type at runtime — the dynamic
selectConstructorAndTransformArguments path unwraps it. But when the
super constructor is arity-unique, the generated constructor binds it
statically and consumes its Object parameter with a plain cast, which
the wrapper reaches intact: new Test(['a'] as Set) {} failed with
GroovyCastException 'Cannot cast PojoWrapper to Set' (reduced from
Gradle's test suite).

writeAICCall now evaluates the same predicate the constructor's own
compilation uses for its super call (arity-unique candidate, no spread
arguments — mirroring makeDirectConstructorCall) against the generated
constructor's super call, found by scanning its body (the this$0
assignment may precede it), and wraps only when delegation will be
dynamic. Both consumers now see what they expect: the dynamic selector
receives wrappers and keeps choosing by cast type; a statically bound
super call receives the plain value.
@testlens-app

testlens-app Bot commented Aug 17, 2026

Copy link
Copy Markdown

✅ All tests passed ✅

⚠️ TestLens detected flakiness ⚠️

Test Summary

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

Test Runs Flakiness
AgentChangesTest > forAwaitOverChanges() ❌ ✅ 1% 🟡

🏷️ Commit: 257c7f5
▶️ Tests: 22068 executed
⚪️ Checks: 31/31 completed


Learn more about TestLens at testlens.app.

@codecov-commenter

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 62.50000% with 12 lines in your changes missing coverage. Please review.
✅ Project coverage is 70.1210%. Comparing base (9230bc8) to head (257c7f5).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
...codehaus/groovy/classgen/asm/InvocationWriter.java 62.5000% 2 Missing and 10 partials ⚠️
Additional details and impacted files

Impacted file tree graph

@@                Coverage Diff                 @@
##               master      #2801        +/-   ##
==================================================
+ Coverage     70.1192%   70.1210%   +0.0017%     
- Complexity      35808      35816         +8     
==================================================
  Files            1562       1562                
  Lines          132413     132444        +31     
  Branches        24355      24370        +15     
==================================================
+ Hits            92847      92871        +24     
+ Misses          31164      31163         -1     
- Partials         8402       8410         +8     
Files with missing lines Coverage Δ
...codehaus/groovy/classgen/asm/InvocationWriter.java 86.3636% <62.5000%> (-1.4258%) ⬇️

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

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