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

Jan Lahoda jlahoda at openjdk.java.net
Thu Jul 8 12:00:02 UTC 2021


On Wed, 16 Jun 2021 15:15:25 GMT, Jan Lahoda <jlahoda at openjdk.org> 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 `enumSwitch` that accepts `String`s in place of the enum constants, and will internally convert them to the appropriate enum constants, and then it will find the proper case similarly to `typeSwitch`.
> 
> How does this look?

This pull request has now been integrated.

Changeset: fa08cc62
Author:    Jan Lahoda <jlahoda at openjdk.org>
URL:       https://git.openjdk.java.net/jdk17/commit/fa08cc62df10e4b6e3cbc45d4e889191d67048c4
Stats:     470 lines in 7 files changed: 329 ins; 68 del; 73 mod

8268766: Desugaring of pattern matching enum switch should be improved

Reviewed-by: mcimadamore, psandoz

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

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


More information about the core-libs-dev mailing list