On Thu, 17 Jun 2021 21:03:58 GMT, Maurizio Cimadamore <mcimadam...@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 173:
> 
>> 171: 
>> 172:     /**
>> 173:      * Bootstrap method for linking an {@code invokedynamic} call site 
>> that
> 
> This should be made clearer - e.g. the first argument is of type `Class` and 
> represents the enum we want to switch on. The remaining constants should be 
> of type `String`, the names of the various constants.

That is not quite what the labels represent. The target Enum type is inferred 
from the bootstrap method's invocation MethodType. (Alternatively, we can add a 
new Class parameter to the bootstrap method.)

For the labels, please consider this switch:

         E sel = null;
         switch (sel) {
             case A -> {}
             case E e && "B".equals(e.name()) -> {}
             case C -> {}
             case E e -> {}
         }


The patterns and the constants are mixed, and the order needs to be represented 
somehow in the labels array, so that the switch will classify the input 
correctly. The method in this proposal will use `{"A", E.class, "C", E.class}` 
as the labels array (which is mostly consistent with the `typeSwitch` method), 
but we could use different encodings if needed.

-------------

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

Reply via email to