contextual void construction

This commit is contained in:
2026-06-29 20:24:48 +02:00
parent c82f070d55
commit 98c303d22c
4 changed files with 185 additions and 8 deletions
+20 -4
View File
@@ -535,10 +535,26 @@
(`match get()`) is a pre-existing gap (assign to a variable first, as the spec examples do);
the rvalue pointer-capture guard is defensive for when that lands
22.6. (`// ponytail:` follow-ups): contextual void construction (`e Event = .quit`) needs
enum-literal→union coercion. Separately, a **call expression directly as a match subject**
(`match get()`) is a pre-existing gap (assign to a variable first, as the spec examples do);
the rvalue pointer-capture guard is defensive for when that lands
22.6. contextual void construction + call-as-match-subject (implemented; see below)
- **contextual void construction**: a bare enum literal in a tagged-union context constructs a
void-payload variant — `e Event = .quit` (and any expected-union position: `=`, return, call
argument) coerces `.quit` to the union, equivalent to `Event{ quit }`. Build-pass only: the
`.Enum_Literal` case, given a tagged-union `expected`, looks the variant up and emits the
tag-only union `.Struct` HIR for a void variant. A payload variant via a bare `.variant`
("needs a payload") and an unknown variant are diagnosed; the payload-carrying contextual form
`.variant{...}` stays deferred to milestone 23 (error channel)
- **call expression directly as a match subject**: `match get() { … }` now specializes the call.
Root cause was that the inference/spec-request walker `infer_statements` had no `.Match` case,
so a match's subject and arm bodies were never visited and their calls never got a
specialization (`find_spec` → "could not resolve specialization"). Added a `.Match` case that
infers the subject and recurses into arm bodies (with the capture local typed from the variant
payload, mirroring the `.For`/unwrap-`.If` handling). This also covers value-`match` and calls
inside arm bodies. As a side effect the rvalue pointer-capture guard from 22.5 is now reachable
(`match make_box() { .v |@p|: … }` correctly errors "requires an addressable subject")
- checker-only; no parser/AST/HIR/IR/lowering/codegen change
- deferred: payload-carrying contextual construction (`.variant{…}`, milestone 23); a
`yield call()` inside a value-block/value-match arm still misses its spec (`infer_statements`
has no `.Yield` case either — a separate pre-existing gap)
23. error types (see below)