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
with expr as mut x: (§7.2 builder) drops the builder before returning it: every Vec pushed inside comes back empty #1290
Found rewriting `examples/ecs`, `examples/nebula` and `examples/service` under #1150 ruling 4; the spec's own §7.2 example is the repro.
```
fn main:
let v = with Vec.new() as mut v:
v.push(1)
v.push(2)
print(f"{v.len()}") // expected 2; prints 0
let s = with "" as mut acc:
acc = acc ++ "ab"
print(s) // expected ab; prints nothing
```
A struct builder (`with Cfg {} as mut c: c.timeout = 30`) happens to work because the field stores land in the same storage; anything with an owned buffer or a reassignment is lost. The `var out = Vec.new(); out.push(1); out` desugaring (§7.2:2906) works.
Root cause (exact lines, MIR evidence). `src/MirLower.w` `lower_with_binding`: line 12496 schedules `schedule_drop(local, DK_VALUE)` for the builder local, and the Form 2 return at line 12505 hands back `OK_COPY` of that local. The scope-exit drop therefore runs before the copy:
(`with check w.w --dump-mir` on the `with`-form function). The `var` form lowers to `_0 = move _1; _1 = const zst` with no drop. The fix is to move the builder out (`OK_MOVE`, with the scheduled value drop cancelled / reset-on-move), which is exactly the spec's desugaring. Branch `with-builder-move` carries it; it is a drop-scheduling change and runs its own battery (isolation rule).
Installed `with v0.15.2.1-g478b26481` and the main-HEAD stage1s in `printd`/`exdefects` all reproduce.
Activity
examples: rewritten to the current spec (D55 ruling 4) + examples-tes…
MirLower: `with expr as mut x:` moves the builder out instead of drop…
MirLower: `with expr as mut x:` moves the builder out instead of drop…