RFR: 8309336: Incorrect switch in enum not reported properly

Vicente Romero vromero at openjdk.org
Fri Jun 2 17:08:05 UTC 2023


On Fri, 2 Jun 2023 12:47:08 GMT, Jan Lahoda <jlahoda at openjdk.org> wrote:

> As of JDK 21, enum constants may be qualified in switches. But there's a bug in the way these "constants" are attributed. Having code like:
> 
> class EnumLabelMustBeEnumConstant {
>     enum E { A };
> 
>     void m(E e) {
>         switch (e) {
>             case EA -> {}
>             default -> {}
>         }
>     }
> 
>     static final E EA;
> }
> 
> 
> javac will attribute `EA`, which will turn out to exist, and have the correct type (`E`), so that it will be accepted (and may crash javac later in the backend).
> 
> The proposed fix is simply to check that the given expression is an enum constant.

lgtm

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

Marked as reviewed by vromero (Reviewer).

PR Review: https://git.openjdk.org/jdk/pull/14284#pullrequestreview-1458056913


More information about the compiler-dev mailing list