Repository navigation
Conversation
…arded (#1319's gap; fixes behav_distinct_compat) #1319 discarded an assignment in tail position (§9.1) for a block tail, a single-statement fn body and a closure body, but not for a bare `if`/`match` arm. `fn check(ok): if ok: n = n + 1 else: { eprint(..); m = m + 1 }` joined the then arm's place type i32 with the else block's Unit and was rejected ("if arms have types i32 and Unit"), turning main red on test/behavior/behav_distinct_compat.w. check_if and the match arm loop now type an assignment arm Unit through the same predicate (Sema.expr_is_assignment), and lower_if / lower_match lower a value-position arm through lower_tail_expr so MIR agrees at the same site. err_d43_cannot_infer_match used `true => seen = 1` beside `assert(p)` as its mixed-arm shape; under §9.1 that arm is Unit, so the program is valid (it now runs, as `true => { seen = 1 }` already did). The test keeps its D43 purpose with a real value arm (`true => 1`); the assignment-arm shape moved to behav_1319_assignment_arm_discarded.w, which covers then-bare/else-block, the reverse, both match orders, both-bare, #1180's assert shape and an annotated `-> i32` body.
|
More evidence: |
|
Held for a ruling: this PR rewrites |
|
Closed per Eric's ruling (2026-09-22): the spec, D43 as blessed including its pinned test, decides — an assignment is discarded only as the function/closure's own tail or a statement; as a written arm of a tail if/match it keeps its value type. This PR bent D43's test to keep another test green, which is the wrong motivation. The fix instead narrows #1319's arm-block discard back (new PR). |
#1319 made Sema discard an assignment in tail position (§9.1: "in statement or tail position its value is discarded") for a block tail, a single-statement fn body and a closure body. It missed a bare
if/matcharm, and main is red ontest/behavior/behav_distinct_compat.w:failed with
cannot infer return type: if arms have types i32 and Unit. The else block's tail was discarded (Unit), but the then arm kept its place type (i32).Fix
check_if(both arms) and the match arm loop type an assignment arm as Unit, using the same predicate as the other tail sites (Sema.expr_is_assignment).lower_ifandlower_matchlower a value-position arm throughlower_tail_expr, so MIR discards it at the same site.Test changes
test/behavior/behav_1319_assignment_arm_discarded.wcovers: bare then arm with block else, the reverse, both match orders, both arms bare, Unannotated block tail: value dropped while the caller formats it (garbage), invalid MIR on mixed match arms, validator silent #1180's assignment-beside-assertshape, and an annotated-> i32body.err_d43_cannot_infer_match.w: its mixed-arm example wastrue => seen = 1besideassert(p). Under §9.1 that arm is Unit, so the program is valid. On this branch it now runs, the same astrue => { seen = 1 }already did after Sema: assignment tails are discarded (#1296) andwith … as mutbodies are statements (#1298) #1319. The test still checks the D43 cannot-infer error, now using a real value arm (true => 1).Evidence (bootstrap stage1,
:devon this commit)err_d43_*produce their expected diagnostics.with test.run --debug-allocon the new test is clean.--validate-allcould not run: bootstrap stage1 hangs on it even for a hello-world, on main as well (bootstrap stage1check --validate-alltakes 15+ min at 7 GB RSS on a 20-line file (release binary: 0.07 s) #1315, check --validate-all on a bootstrap stage1 parks at 7 GB in the drop-state driver; the release binary answers in 0.1 s #1282).Draft until the seed-driven battery is green and posted (D56).