[jdk17] RFR: 8268766: Desugaring of pattern matching enum switch should be improved [v2]
Jan Lahoda
jlahoda at openjdk.java.net
Fri Jun 18 09:11:26 UTC 2021
On Thu, 17 Jun 2021 21:56:21 GMT, Rémi Forax <forax at openjdk.org> wrote:
>> Jan Lahoda has updated the pull request incrementally with one additional commit since the last revision:
>>
>> Creating a new bootstrap method for (pattern matching) enum switches, as suggested.
>
> src/java.base/share/classes/java/lang/runtime/SwitchBootstraps.java line 222:
>
>> 220: String invocationName,
>> 221: MethodType invocationType,
>> 222: Object... labels) throws Throwable {
>
> Is it not better to take a Class and a String... as separated parameters instead of taking Object... and doing the conversion to a Class and an array of String later in Java
This is to represent cases like:
E sel = null;
switch (sel) {
case A -> {}
case E e && "B".equals(e.name()) -> {}
case C -> {}
case E e -> {}
}
The method needs to know which cases represent constants and which represent patterns (even though the primary type of all the patterns will be the enum type), so we cannot easily put the `Class` first (or elide it), and then a `String...`, unless we represent the patterns in the `String...` array somehow.
-------------
PR: https://git.openjdk.java.net/jdk17/pull/81
More information about the core-libs-dev
mailing list