Call for feedback -- switch expressions in JDK 12

Alex Buckley alex.buckley at oracle.com
Mon Apr 29 20:46:41 UTC 2019


On 4/17/2019 4:50 PM, Manoj Palat wrote:
>     2) Thanks to Remi Forax raising a bug in ecj
>     [https://bugs.eclipse.org/bugs/show_bug.cgi?id=545716] and the
>     following discussions, we believe that there could be a bug [in
>     spec, javac as well as ecj] – see this comment from Stephan Herrmann
>     _https://bugs.eclipse.org/bugs/show_bug.cgi?id=545716#c16_specifically
>     for the findings.

Thanks for raising this. There is a flaw in how the new JLS 16.2.9 
analyzes -> rules in a switch statement 
(http://cr.openjdk.java.net/~gbierman/switch-expressions.html#jep325-16.2.9). 
The flaw is due to the fact that -> rules were initially introduced in 
switch expressions, which are complete by construction. (Either there is 
an explicit default, or there is an implicit default to catch novel enum 
constants.)

We will publish a new spec for JEP 354 soon, but in the meantime here is 
the corrected part of 16.2.9:

-----
The following rules apply only if the switch block of the switch 
statement consists of switch labeled rules:

* V is assigned after a switch statement iff either of the following are 
true:

     V is assigned after the selector expression, or

     There is a default labeled rule and for every switch labeled rule 
one of the following is true:

         It is a switch labeled expression e and V is assigned after e.

         It is a switch labeled block b and both V is assigned after b 
and V is assigned before every break statement contained in b that may 
exit the switch statement.

         It is a switch labeled throw statement.

* V is unassigned after a switch statement iff both of the following 
rules are true:

     V is unassigned after the selector expression, and

     For every switch labeled rule one of the following is true:

         It is a switch labeled expression e and V is unassigned after e.

         It is a switch labeled block b and both V is unassigned after b 
and V is unassigned before every break statement contained in b that may 
exit the switch statement.

         It is a switch labeled throw statement.

* V is [un]assigned before any switch labeled expression, switch labeled 
block, or switch labeled throw statement iff V is [un]assigned after the 
selector expression.
-----

Alex


More information about the jdk-dev mailing list