jdaugherty commented on PR #3085:
URL: https://github.com/apache/groovy/pull/3085#issuecomment-6511288732

   Confirmed: a cast site never selects `asType` through the metaclass, before 
or after this change. The `CastSelector` chain is `asBoolean` (through the 
metaclass, still guarded), then the null, instance-of, collection and SAM 
checks, then `DefaultTypeTransformation.castToType`, which is decided by the 
value's class; classic call sites reach the same method via 
`ScriptBytecodeAdapter.castToType`. So a custom `asType` was never honoured by 
`Target t = value` or `(Target) value`, with or without indy.
   
   The `as` operator is a different site: `InvokeDynamicWriter.coerce` emits an 
ordinary indy method call named `asType`, linked by `MethodSelector`, whose 
`guardsReceiverMetaClass()` is unchanged. An ExpandoMetaClass, per-instance or 
category `asType` is selected and guarded there exactly as before.
   
   I checked with a script against master before the change (5b077f9dcf) and 
with it (1c5c941f4d); the output is identical. `value as Target` honours a 
class-level EMC `asType`, two per-instance `asType` closures alternating 
through the same site (it relinks on the receiver metaclass guard), and a 
category `asType` inside `use`, then falls back to the EMC one after the 
category exits. `Target t = value` and `(Target) value` throw 
`GroovyCastException` in every case on both builds. With 
`-Dgroovy.indy.logging=true` the `asType` site logs "added meta class equality 
check" and the cast site logs only the class switch point and same-class 
argument guards. The 6.0.x and 5.1.x `CastSelector`s have the same chain ending 
in `DTT_CAST_TO_TYPE`, so this holds for the backports.
   
   Noted on GROOVY-12557 as well.
   


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

Reply via email to