ceylon/ceylon-spec — Issue #65: Restrict switch so that branches are disjoint
Author: gavinking
Created: 2011-11-23 06:54:25+00:00
State: open
Labels: type system discussion

Ross argues that `switch` statements should have disjoint `case`s, so that reordering the `case`s does not effect the execution of the statement.

I propose the following solution:

1. The `switch` expression type must be a class or interface type with enumerated cases (an `of` clause), or a union type containing disjoint classes (`X` and `Y` are disjoint if neither `X` is a subclass of `Y` nor `Y` is a subclass of `X`).
2. We keep the current rules for classes with enumerated subtypes (the subclasses are guaranteed to be disjoint).
3. We say that for interfaces with enumerated subtypes, that every concrete class that is a subtype of the interface type must also be a subtype of one and exactly one of the subtypes.

I think this satisfies the requirements.