[pattern-switch] Totality
Guy Steele
guy.steele at oracle.com
Sat Aug 22 18:26:19 UTC 2020
> On Aug 22, 2020, at 2:06 PM, Brian Goetz <brian.goetz at oracle.com> wrote:
> . . .
>>
>> Option 1: If the type of the switch expression is an enum or a sealed type, then it is a static error if the patterns are not at least optimistically total. **This would be an incompatible change with respect to existing switches on enum types.**
>
> Actually, as stated, this is not inconsistent -- for switch *expressions*. We added switch expressions in Java 12 and required that they be total, and, when the target is an enum, we nodded to optimistic totality, by not requiring a `default` when the cases were optimistically total. Where we don't have an equivalent story is for switch *statements*, which have always been partial -- and for which partiality is reasonable (just as an `if` without an `else` is reasonable.) And the story for optimistic totality does not scale quite as well as we'd hoped to sealed types, for a few reasons:
Yes, this was an error on my part; I meant to write "Option 1: If the type of the switch statement is . . .”
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.java.net/pipermail/amber-spec-experts/attachments/20200822/590ea69d/attachment.htm>
More information about the amber-spec-experts
mailing list