Skip to content

D43: a partial match tail with equal written-arm types infers a value and reads an unwritten result #1889

Closed

Description

@ehartford

D43 (§9.1) says a missing arm makes an unannotated function's tail Unit. A partial match whose written arms all have the same non-Unit type instead keeps that type and reads an unwritten result on its no-match path.

with reduce minimized the failing D43 corpus case to:

enum Event { Click | Key | Scroll }
global var seen: i32
fn partial(e: Event):
    match e:
        Key => seen = 5

On fix-globals stage1 (d7b800f0 plus the in-progress Never-call repair):

with-stage1 check repro.w --validate-all --no-prelude
error: validate-all failed: ownership MIR: fn sym7 stmt5 span=116: read of _2 reaches a path that never initialized it (Maybe)

The live compiler matrix records partial's Sema return type as 3 (i32), with MIR result locals of that same type. LLDB stops at Sema.check_match_expr, src/SemaCheck.w:16163:

else if stmt_arms_mixed:
    result_type = self.ty_void

(bool) stmt_arms_mixed = false
(int) result_type = 3
0x10029182c: tbz w8, #0x0, 0x100291838

The earlier missing-arm check has already classified this inferred tail as statement position, but only mixed written-arm types cause the final result to become Unit. With a single arm or same-typed arms, Sema retains i32; MIR consequently allocates a result and reads it even when no arm ran. This is a Sema decision and must be corrected there, not by adding a default result in MIR.

New behavior regression behav_d43_partial_match_tail_is_unit.w demands Unit from both single-statement and block-body spellings; all four bindings fail before the fix. test/phase/validate_partial_match_tail.w independently pins the validator verdict. Repair is in progress on fix-globals; no green gate or battery claimed yet.

Found during the #1883 validator sweep, part of the #1709 modeled-C close-out. Local evidence: out/handoff-partial-reduce.log, out/handoff-partial-lldb.log, out/handoff-partial-before.log, and out/handoff-partial-validator-before.log in that worktree.

Activity

  1. added a commit that references this issue on Sep 29, 2026
    617a51e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions