✓
Passing This code compiles and runs correctly.
Code
// TEST: Auto-synthesized proc for phantom state transitions
//
// The core use case: state transitions where only the phantom type changes.
// The proc just passes through the pointer - zero runtime cost.
const std = @import("std");
const Resource = struct { value: i32 };
// Create resource - has a proc (does real work)
~pub tor create { value: i32 } -> *Resource<state_a!>
~proc create|zig {
const r = std.heap.page_allocator.create(Resource) catch unreachable;
r.* = Resource{ .value = value };
return r;
}
// Transition from state_a to state_b - NO PROC NEEDED
// Input and output have same shape (r: *Resource), just different phantom
// Compiler should synthesize: return r;
~pub tor transition { r: *Resource<!state_a> } -> *Resource<state_b!>
// Cleanup state_b - has a proc (does real work)
~pub tor cleanup { r: *Resource<!state_b> }
~proc cleanup|zig {
std.debug.print("cleaned up resource with value {d}\n", .{r.value});
std.heap.page_allocator.destroy(r);
}
// Test it
~create(value: 99): c |> transition(r: c): t |> cleanup(r: t)
Output must match:
cleaned up resource with value 99Flows
flow ~create click a branch to expand · @labels scroll to their anchor
create (value: 99)