Switch Expression - complete normally - spec omission?

Manoj Palat manoj.palat at in.ibm.com
Fri May 15 02:22:19 UTC 2020


Hi,
I think there is a spec omission regarding "complete normally for switch statements whose switch block consists of switch rules

Ref JLS 14 Sec 14.22
...
A switch statement whose switch block consists of switch rules can complete
normally iff at least one of the following is true:
– One of the switch rules introduces a switch rule expression (which is
necessarily a statement expression).
– One of the switch rules introduces a switch rule block that can complete
normally.
– One of the switch rules introduces a switch rule block that contains a reachable
break statement which exits the switch statement.
...
Now consider:

switch (b) {
case 1 -> {
throw new Exception();
}
}

As per the above definition, this switch statement cannot complete normally;
but consider "b" having a value other than 1 and then it completes normally.

Also consider, 14.11.3. which says:
"If no switch label matches, the entire switch statement completes normally."

which looks inconsistent. One hand says: "completes normally" the other:
"iff at least one of the following ..." not mentioning default.

Hence, shouldn't the item,
-> – The switch block does not contain a default label.

also be added in the list in 14.22?

Regards,
Manoj.



More information about the amber-spec-observers mailing list