> On Aug 31, 2020, at 7:35 AM, Brian Goetz <brian.go...@oracle.com> wrote:
> 
> Totality is a term that language designers like, but may not be all that 
> evocative to users.  So switch-total might not exactly turn on the light bulb 
> for them.  In this manner, “sealed” has a useful connotation that has nothing 
> to do with sealed types: non-leakiness: a sealed switch doesn’t leak any 
> unprocessed values! 
> 
> Test driving ...
> 
>     sealed switch (x) { … }
>     sealed-switch (x) { … }
>     switch-sealed (x) { … }
> 
> “A switch may be sealed with the sealed modifier; expression switches are 
> implicitly sealed.  The set of case patterns for a sealed switch must be 
> total with some remainder; synthetic throwing cases are inserted for the 
> remainder.”  

+1

I like this being up front. I find tricks embedded in the body like 'default: 
unreachable' do be too subtle and verbose. And I like the reuse of 'sealed'.

It's unclear whether your "some remainder" is allowed to be empty. (There was 
some discussion earlier about outlawing 'default' in the equivalent of a sealed 
switch.) I hope full totality is fine—an expression switch, implicitly 
'sealed', of course permits a 'default' clause.

And then note that, given the existence of 'sealed switch', the 'default Object 
o' feature is redundant. If you want to make sure you have a total case in your 
switch, just say 'sealed' at the top. All sealed switches (both statement and 
expression) guarantee either optimistic totality + NPE or that the last clause 
is total.

Reply via email to