[code-reflection] RFR: 8337156: Generate code model for switch expression that throws when no label applies [v4]
Paul Sandoz
psandoz at openjdk.org
Fri Aug 9 23:04:56 UTC 2024
On Sat, 3 Aug 2024 09:18:15 GMT, Mourad Abbay <mabbay at openjdk.org> wrote:
>> Update the code model generation of switch expression to throw if no label applies.
>
> Mourad Abbay has updated the pull request with a new target base due to a merge or a rebase. The incremental webrev excludes the unrelated changes brought in by the merge/rebase. The pull request contains four additional commits since the last revision:
>
> - Merge branch 'code-reflection' into 8337156
> - Add default label (if it's missing) during code model generation
> - Merge branch 'code-reflection' into 8337156
> - Update the lowering of switch expression to throw Match Exception if no label applies
src/java.base/share/classes/java/lang/reflect/code/op/ExtendedOp.java line 872:
> 870: case YieldOp yop -> {
> 871: if (isDefaultLabel) {
> 872: block.op(branch(expression.successor()));
Extra indentation.
src/jdk.compiler/share/classes/com/sun/tools/javac/comp/ReflectMethods.java line 1649:
> 1647: // statement
> 1648: pushBody(tree, actionType);
> 1649: Class<?> exClass = isEnum(tree.selector.type.tsym) ? IncompatibleClassChangeError.class : MatchException.class;
JEP 441 (https://openjdk.org/jeps/441) states:
"
To align with pattern switch semantics, switch expressions over enum classes now throw MatchException rather than IncompatibleClassChangeError when no switch label applies at run time. This is a minor incompatible change to the language. (An exhaustive switch over an enum fails to match only if the enum class is changed after the switch has been compiled, which is highly unusual.)
"
-------------
PR Review Comment: https://git.openjdk.org/babylon/pull/195#discussion_r1712328274
PR Review Comment: https://git.openjdk.org/babylon/pull/195#discussion_r1712335469
More information about the babylon-dev
mailing list