Enums and match
Platform spec node
Enums and match
Spec standingStandard
No architecture decision records under adr/ for this feature yet. Standard features must
publish at least one ADR or keep a ## Decisions summary on the hub.
- Enums and match Algebraic enums and exhaustive `match` tie data representation to control flow. Lowering must preserve discriminant layout described in Execution where relevant.
- Method dispatch Virtual dispatch, overload resolution, and receiver rules decide which code runs. Interop and codegen consume the same dispatch table model.
- Type inference Local type inference reduces annotation burden while keeping programs predictable. The inference algorithm is specified here; diagnostics reference these rules.
- Types The type grammar (nominal types, generics, ref T, Option T) is the backbone of static checking. All analysis phases share these definitions.
0 revisions (git unavailable at build; counts may be empty)
No commits recorded for this path.
| Section id | Required | Found |
|---|---|---|
scope | yes | yes |
features | yes | yes |
Full tree: run pnpm verify:platform-spec-layout (writes src/generated/platform-spec-layout-report.json).
Normative specification
Section titled “Normative specification”Defines enum declarations, constructors, match expressions, and patterns. Type rules integrate with Types and Control flow.
Enum declarations
Section titled “Enum declarations”enum Name<G…> { variants }introduces a nominal sum type.- Variants may be nullary (
Ok) or carry fields (Err(message: string)). - Duplicate variant names must error (E1002).
Constructors and use
Section titled “Constructors and use”- Qualified construction
Enum.Variant(args)is required when the enum type is not inferred from context (E1303 if unqualified where ambiguous). - Constructor arity must match the variant field list (E1302, E1307).
- Enum types in expressions must resolve to a known enum (E1301).
match expressions
Section titled “match expressions”match scrutinee { arms }evaluates the scrutinee once, then selects the first arm whose pattern matches.- Each arm
pattern => expressionmust produce the same type; mismatches must error (E1305). when guardon an arm must bebool(E1308).- Patterns may be wildcard
_, literals, identifiers (bind), orEnum.Variant(subpatterns). - Exhaustiveness: For enum scrutinees, arms must cover all variants or include
_; non-exhaustive matches must error (E1304).
Dynamic semantics
Section titled “Dynamic semantics”- Matching must bind pattern variables in the arm expression scope only.
- No fall-through between arms; order is significant for overlapping patterns (overlap should be rejected when detectable).
Diagnostics
Section titled “Diagnostics”Enum/match band E1301–E1308. See Diagnostic code registry.
Conformance
Section titled “Conformance”L2 implementations must agree with reference tests on arity, exhaustiveness, and arm typing.
Decisions
Section titled “Decisions”- D-LM-ENUM-001 — Expression-oriented match:
matchis an expression, not a statement; statement contexts wrap it in expression statements. - D-LM-ENUM-002 — Qualified constructors: Unqualified enum constructors are allowed only when type inference fixes the enum type.
- D-LM-ENUM-003 — Exhaustiveness is mandatory: Partial
matchon enums must be rejected unless_is present. - D-LM-ENUM-004 —
Optionis not special syntax: Optional values use the corelibOption<T>enum, not a languageoptionalkeyword.
Platform view
Section titled “Platform view”Algebraic enums and exhaustive match tie data representation to control flow. Lowering must preserve discriminant layout described in Execution where relevant.