Pattern matching for switch: Spec and Javac inconsistency regarding enhanced switch statements
Ilyas Selimov
ilyas.selimov at jetbrains.com
Wed Jul 7 07:17:41 UTC 2021
Hello!
I found a difference between completeness rules for enhanced switch
statements in spec draft (
http://cr.openjdk.java.net/~gbierman/jep406/jep406-20210527/specs/patterns-switch-jls.html#jls-14.11.2
)
and its javac implementation (OpenJDK 17 build 17-ea+29-2576).
> An enhanced switch statement is one where either (i) the type of the
selector expression is not char, byte, short, int, Character, Byte, Short,
Integer, String, or an enum type,
or (ii) at least one of the switch labels has a pattern case label element
or a null case label element.
According to the statement, the next switch statement is enhanced:
void test(String s) {
switch (s) {
case null:
break;
}
}
> If the switch statement is an enhanced switch statement, then the switch
block must be complete for the selector expression.
As one contains neither total pattern, nor default label, it's incomplete,
but javac compiles it correctly.
Maybe I missed PR that fixed the issue.
Thanks,
Ilyas
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.java.net/pipermail/compiler-dev/attachments/20210707/03d053bd/attachment.htm>
More information about the compiler-dev
mailing list