✓
Passing This code compiles and runs correctly.
Code
// 330_145 — `!`-arm custody of a binding the firing call consumed
//
// `pump(w)` takes `*Win<!opened|!active>` — w's obligations move into the
// loop's custody for the call's duration. Inside `! tick` the loop
// still holds w: the binding reads as live `*Win<opened|active>` (the
// consumed phantom minus the `!` markers), which is exactly what `read`'s
// signature borrows. On the `| done` path the loop hands `active!` back and
// `close` settles it.
//
// What this pins: an ambient use of the consumed binding inside its own
// `!` arm is legal — custody, not capture shape. The companion refusal
// (a binding discharged by an EARLIER call stays dead inside the arm) is
// 330_146. Post-call use after `| done` remains use-after-discharge.
import app/win
import std/io
app/win:open()
| win w |> app/win:pump(w)
! tick _ |> app/win:read(w)
| done w2 |> app/win:close(w: w2) |> std/io:print.ln("closed")
| err e |> std/io:print.ln(e)
Supporting Files
// 330_145 companion module — the window/frames analog as minimal tors.
const std = @import("std");
pub const Win = struct { n: i32 };
// Producer: issues the opened! obligation on | win.
~pub tor open {} | win *Win<opened!> | err string
~proc open|zig {
const w = std.heap.page_allocator.create(Win) catch unreachable;
w.* = .{ .n = 1 };
return .{ .win = w };
}
// A read needing the live states — the window.size(win: w) analog.
~pub tor read { w: *Win<opened|active> }
~proc read|zig { _ = w.n; }
// Settles the active! obligation that | done hands back.
~pub tor close { w: *Win<!active> }
~proc close|zig { std.heap.page_allocator.destroy(w); }
// Event-loop discharger — the frames analog: takes custody of w for the
// loop's duration, fires ! tick per iteration, hands active! back on done.
~pub tor pump { w: *Win<!opened|!active> }
! tick i64
| done *Win<active!>
~proc pump|zig {
tick(0);
return .{ .done = w };
}
Actual
closed
Expected output
closed
Flows
flow ~open click a branch to expand · @labels scroll to their anchor
open
Test Configuration
MUST_RUN