JEP325: Switch expressions spec

Alex Buckley alex.buckley at oracle.com
Fri Apr 27 21:55:29 UTC 2018


On 4/27/2018 8:03 AM, Gavin Bierman wrote:
> I have uploaded the latest draft of the spec for JEP 325 at http://cr.openjdk.java.net/~gbierman/switch-expressions.html

14.16 is right to say that:

   A break statement with value Expression ***attempts to cause the
   evaluation of the immediately enclosing switch expression***
   to complete normally ...

because the following is legal (x will become 200) :

   int x = switch (e) {
     case 1  -> {
       try { break 100; } finally { break 200; }
     }
     default -> 0;
   };

Therefore, in the discussion section, please say that:

   The preceding descriptions say "attempts to transfer control"
   ***and "attempts to cause evaluation to complete normally",***
   rather than just "transfers control" ***and "causes evaluation
   to complete normally",*** because if there are any try statements ...

   ... innermost to outermost, before control is transferred to the
   break target ***or evaluation of the break target completes***.

   [Notice we don't yet know if evaluation of the break target
    will complete normally or abruptly. If the finally clause above
    was to throw an exception instead of break-200, then the
    switch expression would complete abruptly by reason of the
    exception, rather than completing normally with the value 100.]

(Separately: Please flag the new text in 15.15's opening line.)

Alex


More information about the amber-spec-experts mailing list