switch: using an expicit type as total is dangerous

Brian Goetz brian.goetz at oracle.com
Tue Sep 1 14:13:00 UTC 2020


> Anyway, what I think you're really after is a way for the programmer to assert that silently falling out of this switch is unexpected. And 'sealed switch' (however expressed syntactically) is the tool you need to do that. (Let's not dive into aspects of that feature here, though, there's another thread.)

Yes, this is the key thing that is missing.  The rest is mostly a 
distraction.

> Another thing you may appreciate is a warning or error if a non-sealed switch has a total case, because if the switch is total, it's very likely expected to be total forever. We could do this with optimistically-total enum switches, too. I don't think I'd want to do it with 'default' switches, which can be thought of as the "legacy" version of 'sealed switch'.

I'd leave this to IDEs to suggest.  It's a fine suggestion -- "I notice 
you are coding a total switch, let's buy some insurance on it staying 
that way."




More information about the amber-spec-experts mailing list