✓
Passing This code compiles and runs correctly.
Code
// ============================================================================
// REGRESSION TEST - Obligation escape when no disposal event exists
// ============================================================================
// Test: Cleanup obligation created but NO disposal event available
//
// BUG DISCOVERED: 2026-01-12
// Without a disposal event, auto-discharge cannot fix the leak.
// Should produce KORU031 error: no disposal event found.
//
// Expected: Should FAIL with "no disposal event found" error
// Actual: (after fix) Correctly fails
~import "$std/control"
~import "$std/build"
// Link libc for c_allocator
~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 {
const r = allocator.create(Resource) catch unreachable;
r.* = Resource{ .id = id };
return .{ .created = r };
}
// NOTE: NO destroy event exists - auto-discharge cannot fix this!
~event use { r: *Resource[active] }
~proc use {
std.debug.print("using {}\n", .{r.id});
}
// ERROR: Obligation [active!] has no disposal event [!active]
~for(0..10)
| each i |>
create(id: i)
| created r |>
use(r) // use it, but can't dispose - no destroy event exists!
| done |>
_
pub fn main() void {}
Error Verification
Actual Compiler Output
error[KORU030]: Resource '__type_ref' with phantom state [active!] was not disposed.
--> auto_discharge:46: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:9474:17: 0x10083e4af 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:9558:28: 0x10083f2b7 in main (backend)
const generated_code = try RuntimeEmitter.emit(compile_allocator, final_ast);
^Test Configuration
MUST_FAIL
Expected Behavior:
BACKEND_COMPILE_ERROR