✓
Passing This code compiles and runs correctly.
Code
// PINS: union phantom-state INPUTS — `resume` accepts *Connection<paused|active>
// and `close` accepts *Connection<active|paused>, so each state transition below
// typechecks and every line of the runtime trace prints.
//
// HISTORY: written 2026-07-12 with tagged continuations (`| resumed c3 |> ...`)
// on bare-returning tors; KORU021 (2026-08-18) refused that spelling, masking
// the pin. Re-spelled 2026-08-25 to chained bare bindings grounded on
// 330_027_db_transaction_pattern. Measured TRUE: all four flows compile and
// the output is byte-identical to expected.txt. The call side is also pinned
// by 330_051 (green); this pin adds the full four-path trace.
~import app/connection
~app/connection:create(): c1 |> app/connection:connect(conn: c1): c2 |> app/connection:resume(conn: c2): c3 |> app/connection:close(conn: c3)
~app/connection:create(): c1 |> app/connection:connect(conn: c1): c2 |> app/connection:pause(conn: c2): c3 |> app/connection:resume(conn: c3): c4 |> app/connection:close(conn: c4)
~app/connection:create(): c1 |> app/connection:connect(conn: c1): c2 |> app/connection:close(conn: c2)
~app/connection:create(): c1 |> app/connection:connect(conn: c1): c2 |> app/connection:pause(conn: c2): c3 |> app/connection:close(conn: c3)
Supporting Files
// Library module: connection
// Demonstrates phantom state unions - events that accept multiple states
const std = @import("std");
// Connection type with phantom states
const Connection = struct {
id: i32,
};
// Create a new connection - starts in 'idle' state
~pub tor create {} -> *Connection<idle>
~proc create|zig {
std.debug.print("Creating connection\n", .{});
const allocator = std.heap.page_allocator;
const c = allocator.create(Connection) catch unreachable;
c.* = Connection{ .id = 1 };
return c;
}
// Connect - transitions from idle to active
~pub tor connect { conn: *Connection<idle> } -> *Connection<active>
~proc connect|zig {
std.debug.print("Connecting: {d}\n", .{conn.id});
return conn;
}
// Pause - transitions from active to paused
~pub tor pause { conn: *Connection<active> } -> *Connection<paused>
~proc pause|zig {
std.debug.print("Pausing: {d}\n", .{conn.id});
return conn;
}
// Resume - accepts EITHER paused OR active (union!) - always returns active
// This demonstrates the core union feature: flexible input acceptance
~pub tor resume { conn: *Connection<paused|active> } -> *Connection<active>
~proc resume|zig {
std.debug.print("Resuming/continuing: {d}\n", .{conn.id});
return conn;
}
// Close - accepts active OR paused (union!) - cleans up connection
~pub tor close { conn: *Connection<active|paused> }
~proc close|zig {
std.debug.print("Closing: {d}\n", .{conn.id});
}
Actual
Creating connection
Connecting: 1
Resuming/continuing: 1
Closing: 1
Creating connection
Connecting: 1
Pausing: 1
Resuming/continuing: 1
Closing: 1
Creating connection
Connecting: 1
Closing: 1
Creating connection
Connecting: 1
Pausing: 1
Closing: 1
Expected output
Creating connection
Connecting: 1
Resuming/continuing: 1
Closing: 1
Creating connection
Connecting: 1
Pausing: 1
Resuming/continuing: 1
Closing: 1
Creating connection
Connecting: 1
Closing: 1
Creating connection
Connecting: 1
Pausing: 1
Closing: 1
Flows
flow ~create click a branch to expand · @labels scroll to their anchor
create
flow ~create click a branch to expand · @labels scroll to their anchor
create
flow ~create click a branch to expand · @labels scroll to their anchor
create
flow ~create click a branch to expand · @labels scroll to their anchor
create
Test Configuration
MUST_RUN