Dominance in pattern matching for switch: Spec and Javac inconsistency

Ilyas Selimov ilyas.selimov at
Fri Sep 3 05:27:42 UTC 2021


The next code compiles correctly, but it seems to contradict the dominance

void test(Integer i) {
  switch (i) {
    case Integer in && in != null:
    case 1:
    case default:

> A switch label that has a pattern case label element p dominates another
switch label that has a constant case label element c if either of the
following is true:
> - the type of c is a primitive type and its wrapper class (5.1.7) is a
subtype of the erasure of the type of p.

Maybe the type of p should also be total for the type of selector
expression like in the rules for pattern-over-null dominance?

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the compiler-dev mailing list