[code-reflection] RFR: Update ReflectMethods.BodyScanner.coerce to handle null targetType
Maurizio Cimadamore
mcimadamore at openjdk.org
Mon Sep 1 17:30:55 UTC 2025
On Mon, 1 Sep 2025 15:15:35 GMT, Mourad Abbay <mabbay at openjdk.org> wrote:
>> src/jdk.incubator.code/share/classes/jdk/incubator/code/internal/ReflectMethods.java line 739:
>>
>>> 737:
>>> 738: Value coerce(Value sourceValue, Type sourceType, Type targetType) {
>>> 739: if (targetType == null || targetType.hasTag(TypeTag.VOID)) {
>>
>> Not sure about this -- as I'm not sure about `VOID`. E.g. this method should be called when we do have a target type. If there's no target type then there's nothing to coerce in the first place, and we shouldn't call this method. Can you describe more precisely why we end up with a `null` here?
>
> For case body of a switch statement and body has a return. Because `bodyTarget` will be set to `yieldType` which is null, `bodyTarget` will then be used when we scan the return, this cause null to be passed to `coerce`.
Since `coerce` already handles void, would it be possible to use `voidType` as a possible type for `yieldType` ? (although, if there's no target `noType` might be better).
-------------
PR Review Comment: https://git.openjdk.org/babylon/pull/536#discussion_r2314387416
More information about the babylon-dev
mailing list