Unreachable statements after exhaustive switch statement
Gavin Bierman
gavin.bierman at oracle.com
Tue Jul 11 13:24:07 UTC 2023
Hi Mikhail,
Thanks. Looks like there might be a case missing in the spec - I will investigate and get back to you.
Gavin
On 11 Jul 2023, at 14:07, Mikhail Pyltsin <pyltsinm at gmail.com> wrote:
Hi!
I am investigating a new version of jep440+441
(https://cr.openjdk.org/~gbierman/jep440%2B441/jep440+441-20230612/specs/patterns-switch-record-patterns-jls.html)
and notice the next fact:
```
class Test22 {
enum E {A, B}
int testAll(Integer i, E e) {
switch (e) {
case E d when d.hashCode()==1:
return 1;
case A:
return -1;
case B:
return -2;
}
return 1;
}
}
```
this code produces an error: `java: unreachable statement`. It is expected, but this draft doesn't mention any changes about reachability. 14.22 contains the statement, that
```
A switch statement whose switch block consists of switch labeled statement groups can complete normally if at least one of the following is true:
.... – The switch block does not contain a default label.
```
According to it, this `switch` can complete normally.
Perhaps, something is missing in this draft or I can't find some changes.
Could you help me why according to the jep this switch cannot complete normally?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/compiler-dev/attachments/20230711/1e848456/attachment.htm>
More information about the compiler-dev
mailing list