GROOVY-12232: Wrap AIC cast arguments only when the generated constru… - #2801
Open
paulk-asert wants to merge 1 commit into
Open
GROOVY-12232: Wrap AIC cast arguments only when the generated constru…#2801paulk-asert wants to merge 1 commit into
paulk-asert wants to merge 1 commit into
Conversation
…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.
✅ All tests passed ✅Test SummaryBuild and test / lts (17, macos-latest) > :test
🏷️ Commit: 257c7f5 Learn more about TestLens at testlens.app. |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ 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
🚀 New features to boost your workflow:
|
blackdrag
approved these changes
Aug 17, 2026
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.
…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.