✓
Passing This code compiles and runs correctly.
Code
import app/fs
app/fs:open(path: "test.txt"): f |> app/fs:read(f.file): d |> app/fs:close(d.file)
Must contain:
Phantom state mismatchFlows
flow ~open click a branch to expand · @labels scroll to their anchor
open (path: "test.txt")
Imported Files
// Library module: fs with nested obligations
// Tests that nested obligations are tracked correctly
const std = @import("std");
const File = struct { handle: i32 };
const Data = struct { content: []const u8 };
// Open a file - returns opened! state
~pub tor open { path: string } -> *File<opened!>
~proc open|zig {
const f = std.heap.page_allocator.create(File) catch unreachable;
f.* = File{ .handle = 42 };
return f;
}
// Read - requires an opened file, returns data! state (nested obligation).
// Input is a STATE REQUIREMENT (<opened>), never an issue: `<opened!>` on an
// input parameter is illegal polarity (KORU033, pinned by 330_110) — only
// outputs issue obligations.
~pub tor read { file: *File<opened> } -> { file: *File<opened!>, content: *Data<data!> }
~proc read|zig {
const d = std.heap.page_allocator.create(Data) catch unreachable;
d.* = Data{ .content = "test content" };
return .{ .file = file, .content = d };
}
// Close file - consumes opened!
~pub tor close { file: *File<!opened> }
~proc close|zig {
std.heap.page_allocator.destroy(file);
}
// Free data - consumes data!
~pub tor free { content: *Data<!data> }
~proc free|zig {
std.heap.page_allocator.destroy(content);
}