8318144: Match on enum constants with body compiles but fails with MatchException

Reviewed-by: liach, vromero
This commit is contained in:
Jan Lahoda 2023-11-07 12:05:58 +00:00
parent 42f43c520c
commit 541ff7149f
3 changed files with 122 additions and 2 deletions

View file

@ -394,9 +394,13 @@ public class SwitchBootstraps {
Object resolved;
try {
if (!(value instanceof Enum<?> enumValue)) {
return false;
}
Class<?> clazz = label.constantType().resolveConstantDesc(lookup);
if (value.getClass() != clazz) {
if (enumValue.getDeclaringClass() != clazz) {
return false;
}