✓
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 { res: *Resource[open!] }
~proc create {
const r = std.heap.page_allocator.create(Resource) catch unreachable;
r.* = .{ .id = 42 };
return .{ .created = .{ .res = r } };
}
~event use { res: *Resource[open] }
| ok { res: *Resource[open] }
| failed { res: *Resource[open] }
~proc use {
// Simulate sometimes failing
if (res.id == 42) {
return .{ .ok = .{ .res = res } };
}
return .{ .failed = .{ .res = 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
[PHASE 2.4] Calling run_pass for transforms\n[PHASE 2.5] Executing comptime_main() - running comptime flows
[PHASE 2.5] Comptime flows complete (40 items)
[PHASE 2.6] Rescanning transformed AST (40 items)
[PHASE 2.6] Rescan complete: 25 comptime events found
[0] std.compiler:requires
[1] std.compiler:flag.declare
[2] std.compiler:command.declare
[3] std.compiler:coordinate
[4] std.compiler:context_create
[5] std.testing:test
[6] std.testing:validate_mocks
[7] std.testing:test.with_harness
[8] std.testing:test.harness
[9] std.testing:assert
[10] std.testing:test.property.equivalent
[11] std.deps:deps
[12] std.deps:requires.system
[13] std.deps:requires.zig
[14] std.control:if
[15] std.control:for
[16] std.control:capture
[17] std.control:const
[18] std.build:requires
[19] std.build:variants
[20] std.build:config
[21] std.build:command.sh
[22] std.build:command.zig
[23] std.build:step
[24] std.template:define
[PHANTOM-KORU] Starting phantom check proc...
error[KORU030]: Label jump '@loop' drops cleanup obligation for 'c.res' - 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:9500:17: 0x100d52433 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:9584:28: 0x100d531bf in main (backend)
const generated_code = try RuntimeEmitter.emit(compile_allocator, final_ast);
^Test Configuration
MUST_FAIL