[jdk17] RFR: 8268766: Desugaring of pattern matching enum switch should be improved [v2]

Rémi Forax forax at openjdk.java.net
Fri Jun 18 09:50:28 UTC 2021

On Fri, 18 Jun 2021 09:08:04 GMT, Jan Lahoda <jlahoda at openjdk.org> wrote:

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

Ok got it,
At some point, we will have to represent patterns either as String and parse them or as Condy of condy if we want a more structured recursive way.


PR: https://git.openjdk.java.net/jdk17/pull/81

More information about the compiler-dev mailing list