✓
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 { msg: []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
[PHASE 2.4] Calling run_pass for transforms\n[PHASE 2.5] Executing comptime_main() - running comptime flows
[PHASE 2.5] Comptime flows complete (39 items)
[PHASE 2.6] Rescanning transformed AST (39 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
error[KORU030]: No disposal event found for resource '_auto_0' with state 'input:open!'. Library must define an event with [!input:open!] parameter.
--> 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:9392:17: 0x100ae2433 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:9476:28: 0x100ae31bf 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