✓
Passing This code compiles and runs correctly.
Code
~import std/control
~import std/build
~std/build:requires { exe.linkLibC(); }
const std = @import("std");
const Resource = struct {
id: usize,
};
const allocator = std.heap.c_allocator;
~event create { id: usize }
| created *Resource<active!>
~proc create|zig {
const r = allocator.create(Resource) catch unreachable;
r.* = Resource{ .id = id };
return .{ .created = r };
}
~event use { r: *Resource<active> }
~proc use|zig {
std.debug.print("using {}\n", .{r.id});
}
~for(0..10)
! each i |> create(id: i)
| created r |> use(r) // use it, but can't dispose - no destroy event exists!
Backend must reject with:
CONTAINS error[KORU030]
CONTAINS was not dischargedError Verification
Actual Compiler Output
error[KORU030]: Resource 'r' with phantom state <active!> was not discharged. No event accepts <!active>.
--> auto_discharge:21:0
❌ Compiler coordination error: Auto-discharge failed (multiple disposal options or no disposal event)
error: CompilerCoordinationFailed
/Users/larsde/src/koru/tests/regression/300_ADVANCED_FEATURES/330_PHANTOM_TYPES/330_053_for_loop_obligation_escape/backend.zig:94:13: 0x104e3f4b3 in emit (backend)
return error.CompilerCoordinationFailed;
^
/Users/larsde/src/koru/tests/regression/300_ADVANCED_FEATURES/330_PHANTOM_TYPES/330_053_for_loop_obligation_escape/backend.zig:190:28: 0x104e4019f in main (backend)
const generated_code = try RuntimeEmitter.emit(compile_allocator, final_ast);
^Test Configuration
MUST_FAIL