RFR: 8309336: Incorrect switch in enum not reported properly
Jan Lahoda
jlahoda at openjdk.org
Fri Jun 2 12:54:24 UTC 2023
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.
-------------
Commit messages:
- Improving error messages.
- Fixing tests.
- Improving error messages for non-enum switch
- 8309336: Incorrect switch in enum not reported properly
Changes: https://git.openjdk.org/jdk/pull/14284/files
Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=14284&range=00
Issue: https://bugs.openjdk.org/browse/JDK-8309336
Stats: 121 lines in 7 files changed: 112 ins; 1 del; 8 mod
Patch: https://git.openjdk.org/jdk/pull/14284.diff
Fetch: git fetch https://git.openjdk.org/jdk.git pull/14284/head:pull/14284
PR: https://git.openjdk.org/jdk/pull/14284
More information about the compiler-dev
mailing list