[pattern-switch] Opting into totality

Dan Smith daniel.smith at oracle.com
Tue Sep 1 17:27:10 UTC 2020


> On Sep 1, 2020, at 8:22 AM, Brian Goetz <brian.goetz at oracle.com> wrote:
> 
> But, there is a subtle difference between
> 
>     switch (x) {
>         case FOO: ...
>     }
> 
> and
> 
>     sealed switch (x) {
>         case FOO: ....
>         default: // nothing
>     }
> 
> which is, what happens on remainder.  In the former, it is just another ignored non-matching input; in the latter, we throw.

Confused here. Doesn't 'default' handle the remainder explicitly? Under what conditions does your sealed switch throw?

The way I'm modeling remainder handling in my head is that sealed switches without 'default' get an implicit 'default' clause that throws. (And, for that matter, regular switches without 'default' get an implicit 'default' that is a no-op.)


More information about the amber-spec-experts mailing list