[pattern-switch] Opting into totality

Remi Forax forax at univ-mlv.fr
Tue Sep 1 12:36:51 UTC 2020

> De: "Brian Goetz" <brian.goetz at oracle.com>
> À: "amber-spec-experts" <amber-spec-experts at openjdk.java.net>
> Envoyé: Lundi 31 Août 2020 15:25:13
> Objet: Re: [pattern-switch] Opting into totality

> I think this is the main open question at this point.

> We now have a deeper understanding of what this means, and the shape of the
> remainder. Totality means not only “spot check me that I’m right”, but also “I
> know there might be some remainder, please deal with it.” So totality is not
> merely about type checking, but about affirmative handling of the remainder.

> Expression switches automatically get this treatment, and opting _out_ of that
> makes no sense for expression switches (expressions must be total), but
> statement switches make sense both ways (just like unbalanced and balanced
> if-else.) Unfortunately the default has to be partial, so the main question is,
> how do we indicate the desire for totality in a way that is properly evocative
> for the user?

> We’ve talked about modifying switch (sealed switch), a hyphenated keyword
> (total-switch), a trailing modifier (switch case), and synthetic cases
> (“default: unreachable”). Of course at this point it’s “just syntax”, but I
> think our goal should be picking something that makes it obvious to users that
> what’s going on is not merely an assertion of totality, but also a desire to
> handle the remainder.

>> - How does a switch opt into totality, other than by being an expression switch?

With the current spec knowing if a switch is total or not depend the last item (it's not fully true) of the switch, if the last item is default, case var, etc 
so it seems weird to me to have to opt-in upfront instead of at the end of the switch. 

what about something like 
switch(foo) { 
case ... 
case ... 

obviously, there is perhaps a better keyword than check-that-this-swicth-is-optimistically-total-please, something like implicit-default (using default as a hyphen part is a subconscious message to the fact that using a default here is not expected) or sealed. 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.java.net/pipermail/amber-spec-experts/attachments/20200901/e6649537/attachment.htm>

More information about the amber-spec-experts mailing list