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
D43: a multi-statement arm ending in an assignment is typed Unit, so a mixed tail infers instead of 'cannot infer' #1337
Spec: §9.1 "Inferred returns through a branching tail" (rule 3) and "A single-statement body and a block body ending in the same tail are the same case"; D43 ("Both spellings, one rule"); Eric's ruling on D43 (2026-09-22, #1332 closed): an assignment that is a written arm of a tail if/match keeps its value type; only a function/closure's own body tail or a statement discards it. test/compile_errors/err_d43_cannot_infer_match.w stands.
Repro (release compiler built from ae609cdd):
var seen: i32
fn f(p: bool):
if p:
let n = 1
seen = n
else:
assert(not p)
fn main: f(true)
Expected:error: cannot infer return type: if arms have types i32 and Unit; add -> i32or-> Unit`` — the then arm's value is the assignment, exactly as in the one-statement spellings below.
Actual:with check says ok; f is inferred Unit.
The same arm spelled with one statement is rejected, as D43 requires:
then arm
verdict
if p: ⏎ seen = 1 (indented, one statement)
cannot infer (correct)
if p: { seen = 1 }
cannot infer (correct)
if p: ⏎ let n = 1 ⏎ seen = n (block ending in the assignment)
ok, inferred Unit
So whether an arm keeps its assignment's type depends on how many statements precede it — the body-form dependence D43 rules out. Likely site: #1319's tail discard applies to a multi-statement block's tail even when that block is an arm of an enclosing tail if/match, while a one-statement arm goes through the arm path.
Where it shows:examples/ecs/src/storage.wDenseStorage.insert (then arm: let idx = ... then self.dense_data[idx] = component; else arm: pushes). It keeps -> Unit, which D43 requires; the compiler currently accepts it without the annotation, which it must not.
Workaround used: none (the example carries the D43-required annotation).
Activity
examples: restore the spec spellings #1308 parked behind now-fixed co…
Sema/MirLower: only a body's own tail discards an assignment; an arm …
Sema/MirLower: only a body's own tail discards an assignment; an arm …