-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
non-exhaustive enums #2524
Copy link
Copy link
Closed
Labels
acceptedThis proposal is planned.This proposal is planned.proposalThis issue suggests modifications. If it also has the "accepted" label then it is planned.This issue suggests modifications. If it also has the "accepted" label then it is planned.
Milestone
Metadata
Metadata
Assignees
Labels
acceptedThis proposal is planned.This proposal is planned.proposalThis issue suggests modifications. If it also has the "accepted" label then it is planned.This issue suggests modifications. If it also has the "accepted" label then it is planned.
A non-exhaustive enum is an enum that may have other unknown members.
This can help create APIs that may be extended in future. This sort of thing frequently comes up in data formats, network protocols, and even C APIs.
Possible syntax:
_as a trailing field.Semantics:
enum(u5) { X, Y, Z, _ }_when an enum is already "full" (e.g. if it'su2and you specify 4 values followed by a_), then there is a compiler error.switch-ed on, anelseclause is always required@intToEnumcan never fail withhas no tag matching integer valuebuiltin.Enumgains a new boolean fieldis_exhaustiveRelated