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
An if without else as the last statement of a with ... as mut body is rejected, though §7.2 discards the body's value #1298
Found rewriting `examples/service` under #1150 ruling 4 (`describe_changes` and the postgres `update` SET-clause builder).
§7.2: `with expr as mut x:` "always returns `x` (the builder), regardless of the type of the body's last expression". The checker still types the body's last statement as the block value, so a trailing `if` without `else` — the natural last line of a conditional builder — is an error:
```
fn describe(x: i32) -> str:
let changes = with Vec.new() as mut c:
if x > 1:
c.push("gt1")
if x > 2:
c.push("gt2")
changes.join(", ")
```
```
error: if expression requires an else branch unless the then branch diverges
--> p8.w:5:9
```
Single-line `if x > 2: c.push("gt2")` is rejected the same way. `src/MirLower.w:6196` already special-cases "a statement-if reached in value mode (`with … as mut c:` bodies)", so the lowering knows the body is a statement; Sema's join does not. Expected: the body of a Form 2 block is checked as statements, the block's type is the builder's. Installed `with v0.15.2.1-g478b26481`.
The example uses the `var` desugaring (§7.2:2906) for those two builders until this lands.
Activity
examples: rewritten to the current spec (D55 ruling 4) + examples-tes…
Sema: assignment tails are discarded (#1296) and `with … as mut` bodi…
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 …
ehartford commentedon Sep 26, 2026
Verified fixed on main 55739d4 (release binary): trailing if without else in a
with … as mutbody compiles.