Break in non-fall through switch

Hunor Szegi hunor.szegi at gmail.com
Mon Jun 20 12:03:54 UTC 2022


Hi All,

I would like to ask you to consider banning the break statement at the
non-fall through switch.

First, this statement does nothing here. The return value is presented
using a different keyword (yield), so there's really no purpose left for
the break statement.

Additionally, it is confusing, as there's no control flow here that could
be interrupted.

If we want an empty case body, currently it is possible to provide an empty
block. (I would recommend allowing the completely empty case bodies,
similarly to the legacy switch.)

In a switch expression it isn't possible to use it, because we have to
yield a value, and can't break the flow before that. So this is already an
asymmetry, we won't make it worse allowing the break only at a fall through
switch statement, at the only case it makes sense.

It could be possible to use the break statement within the switch, but that
would be related only to the outer control flow, like a for loop. In this
way it would be possible to break the outer flow without using a label.

Thank you,

Regards,
Hunor
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/amber-dev/attachments/20220620/ac706ea3/attachment.htm>


More information about the amber-dev mailing list