Phase 5. Sum types and pattern matching
| Field | Value |
|---|---|
| MEP | MEP-46 §Phases · Phase 5 |
| Status | LANDED |
| Started | 2026-05-26 14:21 (GMT+7) |
| Landed | 2026-05-26 14:37 (GMT+7) |
| Tracking issue | — |
| Tracking PR | — |
Goal-alignment audit
This phase directly advances the correctness gate (byte-equal stdout vs vm3)
for programs that use sum types, which is one of the most common Mochi
patterns. Without this phase, any program using option<T>, Result<T,E>, or
user-defined tagged unions fails to compile to BEAM. Completing this phase
unlocks a large fraction of real Mochi programs.
Sub-phase 5.0: Variant constructors and basic match
Representation
Sum type type Shape = Circle(float) | Rectangle(float, float) | Point lowers
to tagged tuples and bare atoms depending on arity:
| Mochi variant | Core Erlang representation |
|---|---|
Point (unit) | c_atom("point") |
Circle(3.14) (single field) | c_tuple([c_atom("circle"), c_float(3.14)]) |
Rectangle(w, h) (multi-field) | c_tuple([c_atom("rectangle"), V_w, V_h]) |
The tag atom is always the lowercase variant name. The lowerer derives it with
strings.ToLower(variant.Name).