Integrated: 8309336: Incorrect switch in enum not reported properly

Jan Lahoda jlahoda at openjdk.org
Mon Jun 5 06:28:18 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.

This pull request has now been integrated.

Changeset: 05fb6c66
Author:    Jan Lahoda <jlahoda at openjdk.org>
URL:       https://git.openjdk.org/jdk/commit/05fb6c6648bc759853c5a9c5b932706592d87ba9
Stats:     121 lines in 7 files changed: 112 ins; 1 del; 8 mod

8309336: Incorrect switch in enum not reported properly

Reviewed-by: vromero

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

PR: https://git.openjdk.org/jdk/pull/14284


More information about the compiler-dev mailing list