Skip to content

non-exhaustive enums #2524

Description

@daurnimator

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:

  • a non-exhaustive enum is created by including _ as a trailing field.

Semantics:

  • A non-exhaustive enum must have the size specified: enum(u5) { X, Y, Z, _ }
  • If you specify _ when an enum is already "full" (e.g. if it's u2 and you specify 4 values followed by a _), then there is a compiler error.
  • When switch-ed on, an else clause is always required
  • @intToEnum can never fail with has no tag matching integer value
  • builtin.Enum gains a new boolean field is_exhaustive

Related

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    acceptedThis proposal is planned.proposalThis issue suggests language modifications. If it also has the "accepted" label then it is planned.

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions