Dominance in pattern matching for switch: Spec and Javac inconsistency

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


Hello!

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

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

> 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?

Thanks,
Ilyas
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.java.net/pipermail/compiler-dev/attachments/20210903/b90cd2f3/attachment.htm>


More information about the compiler-dev mailing list