Swift Proposal: Non-Exhaustive Enums
Currently, adding a new case to an enum is a source-breaking change, which is very inconvenient for library authors. This proposal aims to distinguish between enums that are exhaustive (meaning they will never get any new cases) and those that are non-exhaustive, and to ensure that clients handle any future cases when dealing with the latter. This change only affects clients from outside the original module.
[…]
Public enums can be declared as
exhaustive
or asnonexhaustive
. In Swift 4 mode, the default behavior will beexhaustive
for source compatibility; in Swift 5 it will benonexhaustive
.When a client tries to switch over a
nonexhaustive
enum, they must include adefault
case unless the enum is declared in the same module as the switch. In Swift 4 mode, omitting this case will result in a warning; in Swift 5, it will be an error.Enums imported from C will be
nonexhaustive
by default, with a new C-side annotation to make themexhaustive
. These enums conservatively always have the “cross-module” behavior.
Update (2017-12-20): See SE-0192.