Call for feedback -- switch expressions in JDK 12

Manoj Palat manoj.palat at in.ibm.com
Tue Apr 30 10:06:39 UTC 2019


Thanks Alex for the checking this issue and the heads up on spec changes!

Regards,
Manoj



From:	Alex Buckley <alex.buckley at oracle.com>
To:	jdk-dev at openjdk.java.net
Cc:	Stephan Herrmann <stephan.herrmann at berlin.de>
Date:	04/30/2019 02:17 AM
Subject:	Re: Call for feedback -- switch expressions in JDK 12
Sent by:	"jdk-dev" <jdk-dev-bounces at openjdk.java.net>



On 4/17/2019 4:50 PM, Manoj Palat wrote:
>     2) Thanks to Remi Forax raising a bug in ecj
>     [
https://urldefense.proofpoint.com/v2/url?u=https-3A__bugs.eclipse.org_bugs_show-5Fbug.cgi-3Fid-3D545716&d=DwIFaQ&c=jf_iaSHvJObTbx-siA1ZOg&r=A51zLdywEjS50U7u2UMWvsDIrUGEJ5IDXskL5MxIEjA&m=GAhhBGxI89L4ZPYfJmojbo9hfTvw3qEcwI1DV9VnGVg&s=rcyhedLZFsxKexCqbSltcCqXiLrw9IbcN5sndzlNAho&e=
] 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://urldefense.proofpoint.com/v2/url?u=https-3A__bugs.eclipse.org_bugs_show-5Fbug.cgi-3Fid-3D545716-23c16-5Fspecifically&d=DwIFaQ&c=jf_iaSHvJObTbx-siA1ZOg&r=A51zLdywEjS50U7u2UMWvsDIrUGEJ5IDXskL5MxIEjA&m=GAhhBGxI89L4ZPYfJmojbo9hfTvw3qEcwI1DV9VnGVg&s=MT4WBGp2qntLBcd4TMM91AvS-iFa-LeRwrJqbl1-PzE&e=

>     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
(
https://urldefense.proofpoint.com/v2/url?u=http-3A__cr.openjdk.java.net_-7Egbierman_switch-2Dexpressions.html-23jep325-2D16.2.9&d=DwIFaQ&c=jf_iaSHvJObTbx-siA1ZOg&r=A51zLdywEjS50U7u2UMWvsDIrUGEJ5IDXskL5MxIEjA&m=GAhhBGxI89L4ZPYfJmojbo9hfTvw3qEcwI1DV9VnGVg&s=bIajDf-jQmB-y2ER4sy41cLRN-b00CuaU_Muhcv9W9I&e=
).
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