Treatment of nested 'break'

Dan Smith daniel.smith at
Wed May 9 20:27:26 UTC 2018

> On May 9, 2018, at 12:37 PM, Brian Goetz <brian.goetz at> wrote:
> Right, now I see what you mean, and now I recall the motivation. The idea was that there are "breaky" and "nonbreaky" contexts, and for each breaky context, it supports either break-e or break-{l,nothing}.

Okay, yep.

I'm saying that I think this is a bad idea, because it makes value breaks much less useful than returns, though both serve a similar purpose and would be used in similar ways.

The key readability question is: can I readily find this value break's target? I think the answer will usually be "yes", even when nested in other constructs. If not, I worry that that's a fatal problem with 'break', and we should be looking at a different keyword.

>> A simplified model which the spec suggests: there are certain constructs that introduce control flow barriers: method, constructor, initializer, lambda body, switch expression body. It's an error if a break/continue/return reaches one of those and cannot be handled. Nested within one of those, all constructs may choose to handle a break/continue/return, or (by default) propagate it outward.
> Right, that's where I was going with this approach.  Certain constructs consume certain abrupt completions, and others are barriers to certain abrupt completions.  I left out try-catch but it would fit into this approach too, with a little more work.

You've got a general framework, and I'm saying we can reduce some degrees of freedom by saying that if a construct is a "barrier", it's got to be a barrier for all abrupt completions. That limitation contains all the X's to certain rows, and distributes them uniformly across columns.

Here's my proposed table, if it helps (also has some bug fixes):

            break-e   break   break-l   continue   return

switch-s      P         L       P         P          P
for           P         L       P         L          P
while         P         L       P         L          P
block         P         P       P         P          P
labeled       P         P      L*        P          P
[simple rule: if you can handle it, great; if not, pass it on]

lambda        X         X       X         X      L
method        X         X      X         X          L
switch-e      L         X       X         X          X
[simple rule: if you can handle it, great; if not, error]

More information about the amber-spec-experts mailing list