✓
Passing Passing: the compiler rejects this program as expected.
Code
// TEST: Phantom obligation tracking across label jumps
// STATUS: MUST_ERROR (fixed)
//
// BUG: When a label jump (@loop) occurs, phantom obligations from the
// current scope are not being checked. This allows resource leaks.
//
// EXPECTED: Compiler error - obligation not satisfied before @loop
// ACTUAL: Compiler error (KORU030) once obligations are enforced
//
// This test documents the gap discovered while building Orisha HTTP server.
// The `| failed |> @accept_loop(server: s)` branch leaks the connection.
// It also pins the `~#label` anchor itself: the label-declaring line's
// inline `|>` chain must reach the checkers (the tail was once dropped at
// parse, so this program compiled to mangled Zig instead of being refused).
const std = @import("std");
const Resource = struct { id: i32 };
~tor create {} -> *Resource<open!>
~proc create|zig {
const r = std.heap.page_allocator.create(Resource) catch unreachable;
r.* = .{ .id = 42 };
return r;
}
~tor use { res: *Resource<open> }
| ok *Resource<open>
| failed *Resource<open>
~proc use|zig {
// Simulate sometimes failing
if (res.id == 42) {
return .{ .ok = res };
}
return .{ .failed = res };
}
~tor close { res: *Resource<!open> }
~proc close|zig {
std.heap.page_allocator.destroy(res);
}
// THE BUG: This flow should NOT compile!
// `use` only borrows `c` — `o` in the ok arm carries `<open>` with no
// obligation, so `close(res: o)` tries to settle a debt the value never
// incurred (a phantom-state refusal), and `c`'s own <open!> obligation is
// still live at every @loop back-edge regardless.
~#loop create(): c |> use(res: c)
| ok o |> close(res: o) |> @loop()
| failed _ |> @loop()
pub fn main() void {
std.debug.print("Test compiled - BUG: should have been rejected!\n", .{});
}
Actual compiler output
error[KORU030]: Phantom state mismatch: 'o' (parameter 'res') holds state 'input:open' with no obligation attached — '<!open>' settles a debt, and this value never incurred one.
--> tests/regression/300_ADVANCED_FEATURES/370_PHANTOM_TYPES/370_020_label_jump_obligation/input.kz:52:4
❌ Compiler coordination error: Phantom semantic validation failed
(set KORU_BACKEND_TRACE=1 for the backend return trace)Must contain:
Phantom state mismatchFlows
flow ~create click a branch to expand · @labels scroll to their anchor
#loop create
Test Configuration
MUST_ERROR