✓
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 event create-resource { name: []const u8 }
| created *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 .{ .created = res };
}
~pub event 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")
| created r |> destroy-resource(res: r) |> std/io:print.ln("Test done")
Actual
Test start
Test done
Expected output
Test start
Test done
Test Configuration
MUST_RUN