✓
Passing This code compiles and runs correctly.
Code
// Test: Simple phantom obligations
//
// Tests that <allocated!> obligation can be discharged with <!allocated>
~import std/io
const std = @import("std");
pub const Resource = struct {
data: []const u8,
allocator: std.mem.Allocator,
};
~pub tor create-resource { name: string } -> *Resource<allocated!>
~proc create-resource|zig {
const alloc = std.heap.page_allocator;
const data = std.fmt.allocPrint(alloc, "Resource: {s}", .{name}) catch unreachable;
const res = alloc.create(Resource) catch unreachable;
res.* = .{ .data = data, .allocator = alloc };
return res;
}
~pub tor destroy-resource { res: *Resource<!allocated> }
~proc destroy-resource|zig {
res.allocator.free(res.data);
std.heap.page_allocator.destroy(res);
}
// Simple sequential test
~std/io:print.ln("Test start")
~create-resource(name: "Test"): r |> destroy-resource(res: r) |> std/io:print.ln("Test done")
Actual
Test start
Test done
Expected output
Test start
Test done
Flows
flow ~print.ln click a branch to expand · @labels scroll to their anchor
print.ln (expr: "Test start")
flow ~create-resource click a branch to expand · @labels scroll to their anchor
create-resource (name: "Test")
Test Configuration
MUST_RUN