The v0.3 type checker treats generic types like Result<u64> as opaque heads. Codegen rejects them. This issue lands sum types end-to-end.
Scope
Three layers move in lockstep:
Grammar
enum Name { Variant1, Variant2(T), Variant3 { f: T, g: T } } declaration syntax
- Built-in
Result<T, E> and Option<T> shipped as stdlib enums once self-hosting allows
- Constructor expressions:
Ok(x), None, Some(x)
- Pattern matching with constructors:
match x { Ok(v) => ..., Err(e) => ... }
Type system
- Resolve enum declarations as new nominal types
- Constructor expressions have type of their enum head
- Pattern arms scope their bindings into the arm body
- Exhaustiveness check (basic; refined later)
Codegen
- Layout decision: tag-then-payload, 4-byte tag + payload aligned to widest variant
Ok(x) emits tag-write + payload-write to a freshly-allocated heap slot
match destructures via tag-test + payload-load
Hard prerequisite
Memory model RFC (#42) must land first. Sum types need an allocator, and the allocator design is gated on the memory model.
Acceptance
The v0.3 type checker treats generic types like
Result<u64>as opaque heads. Codegen rejects them. This issue lands sum types end-to-end.Scope
Three layers move in lockstep:
Grammar
enum Name { Variant1, Variant2(T), Variant3 { f: T, g: T } }declaration syntaxResult<T, E>andOption<T>shipped as stdlib enums once self-hosting allowsOk(x),None,Some(x)match x { Ok(v) => ..., Err(e) => ... }Type system
Codegen
Ok(x)emits tag-write + payload-write to a freshly-allocated heap slotmatchdestructures via tag-test + payload-loadHard prerequisite
Memory model RFC (#42) must land first. Sum types need an allocator, and the allocator design is gated on the memory model.
Acceptance
Result<u64>through a hostcallexamples/counter.cv(the aspirational version withResult<u64>) now actually compiles and runs