JEP 455: Non-enhanced switch statements
Yuriy Maslyanko
yuriy.maslyanko at oracle.com
Tue Oct 24 19:57:39 UTC 2023
Hi Angelos,
Section 14.11.2 of https://cr.openjdk.org/~abimpoudis/instanceof/jep443-20231010/specs/instanceof-jls.html#jls-14.11.2 has this note:
For compatibility reasons, switch statements that are not enhanced switch statements are not required to be exhaustive.
Noticed that if the switch selector statement is float/double/boolean (in this case it's a non-enhanced switch statement), the code shown below fails with "error: the switch statement does not cover all possible input values":
static boolean check = false;
public static boolean testMethod() {
double v1 = 1d;
switch ( v1 ) {
case 1d:
check = true;
break;
}
return check;
}
However, it works for char, byte, short, int. Maybe this is a bug? Tried it with https://mach5.us.oracle.com/mdash/buildIds/2023-10-18-2214011.angelos.bimpoudis.dev, with same result. Could you please check?
Thanks,
Yuriy
From: Yuriy Maslyanko
Sent: Wednesday, October 18, 2023 2:39 PM
To: Angelos Bimpoudis <angelos.bimpoudis at oracle.com>
Cc: compiler-dev at openjdk.org
Subject: JEP 455: JLS change for switch expressions
Hi Angelos,
JCK team started working on JEP 455: Primitive types in Patterns, instanceof, and switch (Preview). Just noticed that in the draft spec, https://cr.openjdk.org/~abimpoudis/instanceof/jep443-20231010/specs/instanceof-jls.html, there is a change for the switch statement:
14.11 The switch Statement
The Expression is called the selector expression. The type of the selector expression must be char, byte, short, int, or a reference type, or a compile-time error occurs. (jls-14.11-200)
->
The Expression is called the selector expression. The type of the selector expression can be either a primitive or a reference type.
But the corresponding assertion for switch expressions is not changed:
15.28. switch Expressions
The Expression is called the selector expression. The type of the selector expression must be char, byte, short, int, or a reference type, or a compile-time error occurs. (jls-15.28-200)
Could you please take a look?
Thanks,
Yuriy
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/compiler-dev/attachments/20231024/c509e7f3/attachment.htm>
More information about the compiler-dev
mailing list