RFR: 8318144: Match on enum constants with body compiles but fails with MatchException [v2]
Jan Lahoda
jlahoda at openjdk.org
Mon Nov 6 18:54:51 UTC 2023
On Mon, 6 Nov 2023 18:12:10 GMT, Vicente Romero <vromero at openjdk.org> wrote:
>> Jan Lahoda has updated the pull request incrementally with one additional commit since the last revision:
>>
>> Re-ordering tests as suggested.
>
> src/java.base/share/classes/java/lang/runtime/SwitchBootstraps.java line 397:
>
>> 395:
>> 396: try {
>> 397: if (!(value instanceof Enum<?> enumValue)) {
>
> this code seems to be here with the only purpose of casting `value` to `Enum<?>`, if this is the case shouldn't this intention be more explicit?
This method is also used in the `typeSwitch` (i.e. ordinary pattern matching switch, which may contain qualified enum constants intermixed with patterns), and so the `value` may be any object. If it is not an Enum, we can avoid the potential costly resolution.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/16499#discussion_r1383814245
More information about the compiler-dev
mailing list