Unreachable statements after exhaustive switch statement

Mikhail Pyltsin pyltsinm at gmail.com
Tue Jul 11 13:07:26 UTC 2023


  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/711423ba/attachment-0001.htm>


More information about the compiler-dev mailing list