PM design question: Scopes

Mark Raynsford mark at
Sat Nov 4 20:46:55 UTC 2017

On 2017-11-03T10:44:51 +0000
Gavin Bierman <gavin.bierman at> wrote:
> switch (o) {
>     case int i : ... // in scope and DA
>                  ... // in scope and DA
>     case T i :       // int i not in scope, so can re-use
> }
> ... // i not in scope
> +ve Simple syntactic rule
> +ve Allows reuse of pattern variable in the same switch statement.
> -ve Doesn’t make sense for fallthrough
> NOTE This final point is important - supporting fallthrough impacts on what solution we might choose for scoping of pattern variables. (We could not support fallthrough and instead support OR patterns - a further design dimension.)

I'm strongly in favour of this one. In my experience and opinion,
fallthrough was a mistake in C and it was a mistake to copy it in Java.
In some 15 years and close to a million lines of code, I have never once
felt the need to fall through a switch case. If fallthrough didn't
exist, I'm not sure that there'd even be a question that this was the
"right" choice... It essentially makes each branch of the switch
appear to match the scoping rules for lambdas.

From a pedagogical standpoint, all of the other languages I know of
that have implemented pattern matching never had any kind of
fallthrough in the first place, so it'd likely benefit Java to match
them (no pun intended!). I'm thinking of people who learned pattern
matching via something like ML being able to write Java
switches/matches without having to make the mental gear change of
inserting these annoying "break" statements everywhere.

Is there actually a significant amount of code out there that uses
switch case fallthrough? I mean, I know you have to assume that there
is in the interest of preserving backwards compatibility, but I'm
curious if there are actually any metrics on this. I've never even seen
fallthrough in any code in the wild... I was under the impression that
modern IDEs warn against fallthroughs by default.

Mark Raynsford |

More information about the amber-spec-experts mailing list