✓
Passing This code compiles and runs correctly.
Code
// TEST: Phantom obligation tracking across label jumps
// STATUS: MUST_FAIL (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.
const std = @import("std");
const Resource = struct { id: i32 };
~event create {}
| created *Resource[open!]
~proc create {
const r = std.heap.page_allocator.create(Resource) catch unreachable;
r.* = .{ .id = 42 };
return .{ .created = r };
}
~event use { res: *Resource[open] }
| ok *Resource[open]
| failed *Resource[open]
~proc use {
// Simulate sometimes failing
if (res.id == 42) {
return .{ .ok = res };
}
return .{ .failed = res };
}
~event close { res: *Resource[!open] }
| closed
~proc close {
std.heap.page_allocator.destroy(res);
return .{ .closed = .{} };
}
// THE BUG: This flow should NOT compile!
// The `| failed |> @loop` branch has an open obligation that is never discharged.
~#loop create()
| created c |> use(res: c.res)
| ok o |> close(res: o.res)
| closed |> _
| failed _f |> @loop() // BUG! c.res has [open!] obligation, not discharged!
pub fn main() void {
std.debug.print("Test compiled - BUG: should have been rejected!\n", .{});
}
Error Verification
Actual Compiler Output
error[KORU030]: Phantom state mismatch: argument 'res' has no tracked phantom state, but event requires '[open]'. The value must be in state 'input:open'.
--> phantom_semantic_check:54:0
error[KORU030]: Phantom state mismatch: argument 'res' has no tracked phantom state, but event requires '[!open]' (consumption). Did you mean to pass a value with state 'input:open'?
--> phantom_semantic_check:54:0
error[KORU030]: Label jump '@loop' drops cleanup obligation for 'c' - pass it as an argument or discharge it before jumping
--> phantom_semantic_check:54:0
❌ Compiler coordination error: Phantom semantic validation failed
error: CompilerCoordinationFailed
/Users/larsde/src/koru/tests/regression/300_ADVANCED_FEATURES/370_PHANTOM_TYPES/370_020_label_jump_obligation/backend.zig:9506:17: 0x1022b24af in emit (backend)
return error.CompilerCoordinationFailed;
^
/Users/larsde/src/koru/tests/regression/300_ADVANCED_FEATURES/370_PHANTOM_TYPES/370_020_label_jump_obligation/backend.zig:9590:28: 0x1022b32b7 in main (backend)
const generated_code = try RuntimeEmitter.emit(compile_allocator, final_ast);
^Test Configuration
MUST_FAIL