✓
Passing This code compiles and runs correctly.
Code
// NEGATIVE: a label-fold consumes an OUTER-issued obligation each iteration with
// NO compensating reissue on the back-edge. `step` consumes the outer handle
// (<!owned>) but does NOT re-issue an <owned!>; the back-edge re-feeds the SAME
// outer binding `h0`, which was already discharged on the prior iteration. With
// no reissue, every back-edge is a use-after-discharge, and a 0-iteration run
// leaks the outer obligation. MUST be rejected.
// Grammar grounded against 330_017_scope_label_loop (@loop re-feeding an outer
// binding), 330_072_obligation_transfer_through_loop (<owned!>/<!owned> markers),
// and 210_123 (#loop / @loop fold form).
const std = @import("std");
const Handle = struct { n: i32 };
~event make {}
| made *Handle<owned!>
~proc make|zig {
const h = std.heap.page_allocator.create(Handle) catch unreachable;
h.* = .{ .n = 0 };
return .{ .made = h };
}
// Consumes <!owned> but re-issues nothing (branch payloads are plain i32).
~event step { h: *Handle<!owned> }
| again i32
| stop i32
~proc step|zig {
h.n += 1;
if (h.n < 3) {
return .{ .again = h.n };
}
return .{ .stop = h.n };
}
~event report { n: i32 }
~proc report|zig {
std.debug.print("n={}\n", .{n});
}
~event spin { h: *Handle<!owned> }
| finished i32
~spin = #loop step(h)
| again _ |> @loop(h) // re-feeds already-consumed h -> use-after-discharge, no reissue
| stop r => finished r
~make()
| made h0 |> spin(h: h0)
| finished f |> report(n: f)
Backend must reject with:
CONTAINS error[KORU030]
CONTAINS carries no obligation here
CONTAINS this event consumesError Verification
Actual Compiler Output
error[KORU030]: Phantom state mismatch: argument 'h' carries no obligation here, but this event consumes '<!owned>'. Pass a value that still holds its '<owned!>' obligation.
--> phantom_semantic_check:45:0
❌ Compiler coordination error: Phantom semantic validation failed
error: CompilerCoordinationFailed
/Users/larsde/src/koru/tests/regression/300_ADVANCED_FEATURES/330_PHANTOM_TYPES/330_080_reject_consume_outside_obligation_in_loop/backend.zig:94:13: 0x102e9720b in emit (backend)
return error.CompilerCoordinationFailed;
^
/Users/larsde/src/koru/tests/regression/300_ADVANCED_FEATURES/330_PHANTOM_TYPES/330_080_reject_consume_outside_obligation_in_loop/backend.zig:190:28: 0x102e97ef7 in main (backend)
const generated_code = try RuntimeEmitter.emit(compile_allocator, final_ast);
^Flows
subflow ~spin click a branch to expand · @labels scroll to their anchor
#loop step (h)
flow ~make click a branch to expand · @labels scroll to their anchor
make
Test Configuration
MUST_FAIL