On this page

0025: option and result as seeded unions with ?

Date: 2026-10-30 Status: Accepted Name reservation superseded by ADR-0034. Plan: M4.5

Context

Fallible calls need explicit values and concise propagation on both backends. The M4 implementation plan reserves ADR-0025 for this decision; this record uses that reserved number and the format of ADR-0018 rather than allocating the next number with new-adr.sh (which would allocate 0032).

Decision

Seed ordinary generic unions in the type checker without a prelude file: option<T> { some(T), none } and result<T, E> { ok(T), err(E) }. Their synthetic declaration location is the empty span at byte zero, as for builtins; TypeDecl itself carries no declaration span. Constructors are bare and use local expected-type inference. Locals retain their separate namespace.

Postfix ? extracts success or returns failure from the enclosing function. Option requires an option return; result requires a result return with exactly the same error type. Success types may differ. Lower to Core IR Switch, Payload and Variant, constructing failure in the enclosing return layout. Generic return layouts are substituted per instance. No backend-specific operation or new trap is required. Main returns unit and cannot use ?.

Alternatives considered

Consequences

Both backends share propagation semantics, evaluation order and existing IR. Missing constructor context is E0602; invalid propagation is E0520–E0523. The seeded type names and constructor function names become reserved in their namespaces, but remain ordinary identifier tokens and legal local names.