Thanks Manoj. I’ve filed this as a bug [1] and we’ll fix it for JDK 15.
Cheers, Gavin [1] https://bugs.openjdk.java.net/browse/JDK-8245546 <https://bugs.openjdk.java.net/browse/JDK-8245546> > On 16 May 2020, at 10:10, Manoj Palat <manoj.pa...@in.ibm.com> wrote: > > Thanks Alex for the reply and clarifying that we are discussing Switch > Statements with Switch rules. > My bad for putting the title as Switch Expressions - don't want to correct > the title now which > will break the chain of the mail. > > Regards, > Manoj > > -----"amber-spec-experts" <amber-spec-experts-boun...@openjdk.java.net> > wrote: ----- > To: amber-spec-experts@openjdk.java.net > From: Alex Buckley > Sent by: "amber-spec-experts" > Date: 05/15/2020 11:34PM > Subject: [EXTERNAL] Re: Switch Expression - complete normally - spec omission? > > On 5/14/2020 7:22 PM, Manoj Palat wrote: >> 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. > > /* ----- > To demonstrate the point, the switch statement above uses a switch rule > block that completes abruptly, but could alternatively have used a > switch rule `throw` statement: > > switch (b) { > case 1 -> throw new Exception(); > } > > Also, to clarify for the many readers of this list, we are discussing > switch statements, which never require a `default` label. We are not > discussing switch expressions, which almost always require a `default` > label. > ----- */ > >> >> 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? > > I agree that without a `default` switch label, 14.11.3 may evaluate "If > no switch label matches, the entire switch statement completes > normally." Since we can see a way for the statement to complete > normally, 14.22 ought to say that the statement _can_ complete normally. > So, it looks right to add "– The switch block does not contain a default > label." > > Alex > >