✓
Passing This code compiles and runs correctly.
Code
import app/handle
app/handle:open(): h1 |> app/handle:finalize(h: h1)
app/handle:open(): h1 |> app/handle:start-close(h: h1): h2 |> app/handle:finalize(h: h2)
Actual
Opening handle
Finalizing handle: 42
Opening handle
Starting close: 42
Finalizing handle: 42
Expected output
Opening handle
Finalizing handle: 42
Opening handle
Starting close: 42
Finalizing handle: 42
Flows
flow ~open click a branch to expand · @labels scroll to their anchor
open
flow ~open click a branch to expand · @labels scroll to their anchor
open
Imported Files
// Library module: handle
// Demonstrates phantom state unions - events that accept multiple states
const std = @import("std");
// Handle type with phantom states
const Handle = struct {
id: i32,
};
// Open a handle - produces obligation (must be finalized)
~pub tor open {} -> *Handle<opened!>
~proc open|zig {
std.debug.print("Opening handle\n", .{});
const allocator = std.heap.page_allocator;
const h = allocator.create(Handle) catch unreachable;
h.* = Handle{ .id = 42 };
return h;
}
// Start closing - explicitly discharges opened! and produces closing! obligation
~pub tor start-close { h: *Handle<!opened> } -> *Handle<closing!>
~proc start-close|zig {
std.debug.print("Starting close: {d}\n", .{h.id});
return h;
}
// Finalize - accepts EITHER opened OR closing, discharging whichever obligation exists
~pub tor finalize { h: *Handle<!opened|closing> }
~proc finalize|zig {
std.debug.print("Finalizing handle: {d}\n", .{h.id});
// Clean up the handle
}
Test Configuration
MUST_RUN