You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Non-exhaustive expression-position match on integers silently yields zero value #994
Spec violation with silent wrong-value runtime behavior (audit finding MATCH-001). Spec §9.x: 'Expression-position match (value is used/returned): must be exhaustive.'
Enum and bool subjects ARE checked (non-exhaustive match: missing variant 'Blue', non-exhaustive match on bool — both loud, both correct). But an integer-subject match in return position with no _ arm passes with check silently, and at runtime the fall-through produces the type's zero value (classify(2) returned '', printed empty, rc=0). Probes .audit/probes/readonly_pass_20260903/matchx{,2,3}_probe.w.
Two defects, one root
Check-time: exhaustiveness is implemented per finite domain (enum variants, bool) but infinite domains never demand _.
Runtime: the fall-through fabricates a zero value instead of failing (unreachable/panic). Even where checking lags, the codegen default must not invent a value.
Repair boundary
Demand _ (or compiler-proven full coverage) for expression-position matches over non-finite subjects — same diagnostic shape as the bool case; AND make unmatched fall-through a runtime panic rather than a zero value, so any future checking gap fails loud instead of fabricating data.
Review: reproduced, with one correction: the fabricated value is uninitialised memory, not a guaranteed zero
Verdict. Established on current main. An expression-position match over an integer with no _ arm passes with check, while the same shape over an enum or bool is rejected with the existing non-exhaustive match diagnostics. At runtime the unmatched case returns whatever the result temporary happens to hold: the report saw the type's zero value; on this host classify(2) returned "zero" (the first arm's value) and score(7) returned 20 (the second arm's). The MIR shows why: the fall-through edge jumps to the join block and moves out of a result local that was never assigned on that path. The ownership trace records the place as Maybe at that move, yet --validate-all, --validate-ownership, and with analyze audit:all all report ok, so the validators accept a move from a possibly-uninitialised place.
--trace-ownership classify:_3: bb1.stmt6 event=move before=_3=Maybe after=_3=Moved text="_0 = move _3;". The lowering has no unreachable/panic block for the exhausted chain; the last otherwise targets the join and the return reads _3 uninitialised. What the caller sees is therefore stack residue (here the previous call's arm value, in the reporter's run a zero), which is why the title's "zero value" is one observed outcome rather than the rule.
Sema: the exhaustiveness checks at src/SemaCheck.w:12692 (bool), :12721 (sealed trait), and :12755 (enum variants) are the only ones; there is no branch for integer, str, or other infinite-domain subjects, so no _ is demanded.
Spec
§9 "Pattern Matching" (spec lines 4310-4316): "Expression-position match (value is used/returned): must be exhaustive." The integer case violates this at check time, and the runtime behaviour violates the mission's safety bar (reading uninitialised memory from safe code). Statement position is correctly partial.
Tools that stayed silent
validate-ownership: ok on a body whose own trace marks the moved place Maybe. Per AGENTS.md this validator gap is part of the bug: a move from a Maybe-state place in a return should be rejected.
with analyze audit:all: violations=0 ok.
Related PRs
None merged or open touch integer-subject exhaustiveness or the match fall-through lowering.
Would I champion a fix? Yes, both halves.
Acceptance criteria:
Check time: an expression-position match whose subject type is not a finite domain (integers, str, floats, ...) and has no _/binding catch-all arm is rejected with a diagnostic of the same shape as the bool case (non-exhaustive match on i32: add a _ arm). Both probe programs above fail with check.
Lowering: the exhausted comparison chain's final otherwise targets an unreachable terminator (or a panic with the subject value), never the join block, so any future checking gap fails loudly instead of reading an uninitialised local.
Triage 2026-10-25, with v0.15.3.0 (main a261b65): does not reproduce. An integer match without _ is now refused; #1388 made exhaustiveness read whole patterns (05b674e).
$ cat main.w
fn classify(n: i32) -> str:
match n:
0 => "zero"
1 => "one"
fn main:
print(f"[{classify(2)}]")
$ with check main.w
error: non-exhaustive match on 'i32': `-1` is not covered
--> main.w:2:5
= help: add an arm that matches it, or a `_` arm
Activity
ehartford commentedon Sep 16, 2026
Review: reproduced, with one correction: the fabricated value is uninitialised memory, not a guaranteed zero
Verdict. Established on current
main. An expression-positionmatchover an integer with no_arm passeswith check, while the same shape over an enum orboolis rejected with the existingnon-exhaustive matchdiagnostics. At runtime the unmatched case returns whatever the result temporary happens to hold: the report saw the type's zero value; on this hostclassify(2)returned"zero"(the first arm's value) andscore(7)returned20(the second arm's). The MIR shows why: the fall-through edge jumps to the join block and moves out of a result local that was never assigned on that path. The ownership trace records the place asMaybeat that move, yet--validate-all,--validate-ownership, andwith analyze audit:allall report ok, so the validators accept a move from a possibly-uninitialised place.Tested revision and compiler
main@ 5809ac1 (2026-09-14)with buildof 5809ac1 in a detached worktree, self-reportswith v0.15.2.1Probe matrix
with checkwith runfn classify(n: i32) -> str: match n: 0 => "zero" | 1 => "one"; printclassify(0/1/2)[zero] [one] [zero](third should not compile)fn score(n: i32) -> i32: match n: 0 => 10 | 1 => 20;score(0/1/7)10 20 20Colormatch missingBlue, return positionnon-exhaustive match: missing variant 'Blue'boolmatch with onlytrue, return positionnon-exhaustive match on bool_afterRoot cause (observed in MIR)
--dump-mirforclassify:--trace-ownership classify:_3:bb1.stmt6 event=move before=_3=Maybe after=_3=Moved text="_0 = move _3;". The lowering has no unreachable/panic block for the exhausted chain; the lastotherwisetargets the join and the return reads_3uninitialised. What the caller sees is therefore stack residue (here the previous call's arm value, in the reporter's run a zero), which is why the title's "zero value" is one observed outcome rather than the rule.Sema: the exhaustiveness checks at
src/SemaCheck.w:12692(bool),:12721(sealed trait), and:12755(enum variants) are the only ones; there is no branch for integer,str, or other infinite-domain subjects, so no_is demanded.Spec
§9 "Pattern Matching" (spec lines 4310-4316): "Expression-position match (value is used/returned): must be exhaustive." The integer case violates this at check time, and the runtime behaviour violates the mission's safety bar (reading uninitialised memory from safe code). Statement position is correctly partial.
Tools that stayed silent
validate-ownership: okon a body whose own trace marks the moved placeMaybe. Per AGENTS.md this validator gap is part of the bug: a move from aMaybe-state place in a return should be rejected.with analyze audit:all:violations=0 ok.Related PRs
None merged or open touch integer-subject exhaustiveness or the match fall-through lowering.
Would I champion a fix? Yes, both halves.
Acceptance criteria:
matchwhose subject type is not a finite domain (integers,str, floats, ...) and has no_/binding catch-all arm is rejected with a diagnostic of the same shape as the bool case (non-exhaustive match on i32: add a_arm). Both probe programs above failwith check.otherwisetargets anunreachableterminator (or a panic with the subject value), never the join block, so any future checking gap fails loudly instead of reading an uninitialised local.validate_ownership_bodyrejects a move/copy from a place whose state isMaybeon a return path, andsrc/MirValidationTests.wgains a hostile body for it (ties into MIR validator negative coverage: validate_mir_body and use-after-kill have no malformed-MIR cases #989).test/compile_errorsfixture for the integer expression-position case.Untested
Floats and
strsubjects were not probed; they share the code path (no domain branch in Sema). Linux and Windows not executed.Patterns: a struct pattern tests its literal fields; exhaustiveness r…
Restore Vec.clone in drop-state storage; pin the cross-unit receiver …
Patterns: a struct pattern tests its literal fields; exhaustiveness r…
ehartford commentedon Oct 25, 2026
Triage 2026-10-25,
with v0.15.3.0(main a261b65): does not reproduce. An integer match without_is now refused; #1388 made exhaustiveness read whole patterns (05b674e).