JEP325: Switch expressions spec

Alex Buckley alex.buckley at oracle.com
Thu May 10 18:15:04 UTC 2018


On 5/10/2018 10:36 AM, Dan Smith wrote:
>> On May 10, 2018, at 6:28 AM, Gavin Bierman
>> <gavin.bierman at oracle.com> wrote:
>>> 15.29 "the switch expression completes normally": More
>>> conventionally, "the value of the switch expression is …"
>>
>> That phrase occurs in several places, so you’ll have to tell me
>> which one you don’t like.
>
> "If execution of the Statement completes abruptly for the reason of a
> break with a value, then the switch expression completes normally
> with that value."
>
> I'd suggest changing to "for the reason of a break with a value _V_,
> then the value of the switch expression is _V_."
>
> For comparison, in all of Chapter 15, I only find four usages of the
> phrase "complete[s] normally". Lots of usages of "complete[s]
> abruptly", though. Switch _bodies_ are special, because they contain
> statements, so it makes sense to say "completes normally" here. But
> once we've left the body and we're talking about the switch
> expression as a whole, it's better to use the expression-oriented
> terminology.

I agree that expressions completing normally has rarely been spelled out 
in Ch.15, and that the value resulting from evaluation of the expression 
is usually more interesting.

However, JEP 325 is the first time that the JLS will explicitly pend an 
expression's evalation on a statement's completion. Usually it's the 
other way round, per 14.1: "If a statement evaluates an expression, 
abrupt completion of the expression always causes ...". And lambda 
expressions, with bodies containing statements, didn't need to do it 
explicitly in 15.27.2 or 15.27.4.

So, since a value-break statement is a common way out of a switch 
expression, I would like the JLS to put the completes-abruptly side by 
side with a completes-normally. The abrupt completion of `break e;` is 
"swallowed" by the normal completion of the enclosing switch expression. 
(This appeals to the disrupted completion that `catch` and `finally` 
clauses arrange.)

AND, the JLS should specify the value of the switch expression, based on 
evaluating the argument of the value-break statement, as you have proposed.

Alex


More information about the amber-spec-experts mailing list