✓
Passing This code compiles and runs correctly.
Code
// TEST: Auto-discharge skips multi-branch events - no valid candidate
//
// MUST_FAIL
//
// When the ONLY disposal event has multiple branches,
// auto-discharge cannot use it (multiple branches require manual handling).
// This should result in an error: obligation not satisfied.
//
// Expected: Compile error about unsatisfied obligation
// Resource with obligation
pub const Handle = struct {
id: i32,
};
// Event that creates obligation
~event open {}
| ok *Handle[open!]
~proc open {
const h = std.heap.page_allocator.create(Handle) catch unreachable;
h.* = .{ .id = 42 };
return .{ .ok = h };
}
// ONLY disposal event has branches - cannot be auto-discharged
~event close { h: *Handle[!open] }
| closed
| error []const u8
~proc close {
std.heap.page_allocator.destroy(h);
return .{ .closed = .{} };
}
const std = @import("std");
// Flow: open, then terminator
// No void disposal exists, so auto-discharge has no candidate
// This should ERROR - obligation not satisfied
~open()
| ok _ |> _
Error Verification
Actual Compiler Output
error[KORU030]: Resource '__type_ref' [open!] was not disposed. Call: close
--> auto_discharge:42: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_036_autodischarge_no_void_candidate/backend.zig:9398:17: 0x1024ce4af in emit (backend)
return error.CompilerCoordinationFailed;
^
/Users/larsde/src/koru/tests/regression/300_ADVANCED_FEATURES/330_PHANTOM_TYPES/330_036_autodischarge_no_void_candidate/backend.zig:9482:28: 0x1024cf2b7 in main (backend)
const generated_code = try RuntimeEmitter.emit(compile_allocator, final_ast);
^Test Configuration
MUST_FAIL
Expected Behavior:
MUST_FAIL
# Should error because no void disposal candidate exists
# Error occurs at backend-exec when auto-discharge finds no valid candidate
CONTAINS Auto-discharge failed