paulk-asert opened a new pull request, #2801:
URL: https://github.com/apache/groovy/pull/2801
…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.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]