Summary
Rules for dominance between cases with patterns and cases with constant labels are relaxed so that unguarded cases do not dominate cases with constant labels.
Problem
The current dominance rules are relatively strict for cases with constant labels - any case with (unconditional) pattern dominates any case with a constant label. This is inconsistent with dominance between cases with patterns, where guarded cases don't dominate other cases with patterns.
Solution
The proposal is to make the rules for dominance more consistent, in particular, so that guarded cases with patterns don't dominate any other case labels, including cases with constant labels.
Specification
This existing normative text in the specification:
- A case label with a case constant c is dominated if one of the following holds:
- c is a constant expression of a primitive type S, and there is a preceding case label in the switch block with a case pattern p, where p is unconditional for the wrapper class of S.
- c is a constant expression of a reference type T, and there is a preceding case label in the switch block with a case pattern p, where p is unconditional for the type T.
- c is an enum constant of type T, and there is a preceding case label in the switch block with a case pattern p, where p is unconditional for the type T.
Is replaced with the following text:
A
case
label with acase
constant c is dominated if one of the following holds:c is a constant expression of a primitive type S, and there is a preceding
case
label in the switch block with an unguardedcase
pattern p, where p is unconditional for the wrapper class of S.c is a constant expression of a reference type T, and there is a preceding
case
label in the switch block with an unguardedcase
pattern p, where p is unconditional for the type T.c is an enum constant of type T, and there is a preceding
case
label in the switch block with an unguardedcase
pattern p, where p is unconditional for the type T.
- csr of
-
JDK-8309467 Pattern dominance should be adjusted
-
- Resolved
-