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

Brian Goetz brian.goetz at oracle.com
Wed Jun 16 16:54:16 UTC 2021


Bootstrap methods are cheap. If you have one that is semantically 
different, better to write a separate bootstrap than to try and cram two 
sets of functionality into one.  So +1 for "make a new bootstrap for enums."

On 6/16/2021 11:25 AM, Jan Lahoda wrote:
> Currently, an enum switch with patterns is desugared in a very non-standard, and potentially slow, way. It would be better to use the standard `typeSwitch` bootstrap to classify the enum constants. The bootstrap needs to accept enum constants as labels in order to allow this. A complication is that if an enum constant is missing, that is not an incompatible change for the switch, and the switch should simply work as if the case for the missing constant didn't exist. So, the proposed solution is to have a new bootstrap `enumConstant` that converts the enum constant name to the enum constant, returning `null`, if the constant does not exist. It delegates to `ConstantBootstraps.enumConstant` to do the actual conversion. And `typeSwitch` accepts `null`s as padding.
>
> How does this look?
>
> -------------
>
> Commit messages:
>   - Adding and fixing test.
>   - Merging master.
>   - 8268766: Desugaring of pattern matching enum switch should be improved
>
> Changes: https://git.openjdk.java.net/jdk17/pull/81/files
>   Webrev: https://webrevs.openjdk.java.net/?repo=jdk17&pr=81&range=00
>    Issue: https://bugs.openjdk.java.net/browse/JDK-8268766
>    Stats: 313 lines in 6 files changed: 165 ins; 76 del; 72 mod
>    Patch: https://git.openjdk.java.net/jdk17/pull/81.diff
>    Fetch: git fetch https://git.openjdk.java.net/jdk17 pull/81/head:pull/81
>
> PR: https://git.openjdk.java.net/jdk17/pull/81



More information about the core-libs-dev mailing list