Skip to content
Beskid Platform specification

Beskid

Jump to a Beskid service

Beskid

Jump to a Beskid service

Enums and match

Platform spec node

Enums and match

Spec standingStandard

Owner
Piotr Mikstacki
Submitter
Piotr Mikstacki

Defines enum declarations, constructors, match expressions, and patterns. Type rules integrate with Types and Control flow.

  • 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).
  • 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 scrutinee { arms } evaluates the scrutinee once, then selects the first arm whose pattern matches.
  • Each arm pattern => expression must produce the same type; mismatches must error (E1305).
  • when guard on an arm must be bool (E1308).
  • Patterns may be wildcard _, literals, identifiers (bind), or Enum.Variant(subpatterns).
  • Exhaustiveness: For enum scrutinees, arms must cover all variants or include _; non-exhaustive matches must error (E1304).
  • 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).

Enum/match band E1301–E1308. See Diagnostic code registry.

L2 implementations must agree with reference tests on arity, exhaustiveness, and arm typing.

  • D-LM-ENUM-001 — Expression-oriented match: match is 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 match on enums must be rejected unless _ is present.
  • D-LM-ENUM-004 — Option is not special syntax: Optional values use the corelib Option<T> enum, not a language optional keyword.

Algebraic enums and exhaustive match tie data representation to control flow. Lowering must preserve discriminant layout described in Execution where relevant.