028 ambiguous without default

✓ Passing This code compiles and runs correctly.

Code

// TEST: Multiple disposal options without [!] should error
//
// When multiple events can discharge an obligation and NONE have [!],
// the compiler must error - it can't guess which one to use.

~import "$std/io"

const std = @import("std");

const File = struct { handle: i32 };

~event open { path: []const u8 }
| opened { file: *File[opened!] }

~proc open {
    const f = std.heap.page_allocator.create(File) catch unreachable;
    f.* = File{ .handle = 42 };
    return .{ .opened = .{ .file = f } };
}

// Two discharge options - NEITHER has [!] = ambiguous!
~event close { file: *File[!opened] }

~proc close {
    std.heap.page_allocator.destroy(file);
}

~event flush_close { file: *File[!opened] }

~proc flush_close {
    std.heap.page_allocator.destroy(file);
}

// This should FAIL - auto-discharge can't choose
~open(path: "test.txt")
| opened _ |> _
input.kz

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 (31 items)
[PHASE 2.6] Rescanning transformed AST (31 items)
[PHASE 2.6] Rescan complete: 27 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.io:print.ln
  [6] std.io:print.blk
  [7] std.testing:test
  [8] std.testing:validate_mocks
  [9] std.testing:test.with_harness
  [10] std.testing:test.harness
  [11] std.testing:assert
  [12] std.testing:test.property.equivalent
  [13] std.deps:deps
  [14] std.deps:requires.system
  [15] std.deps:requires.zig
  [16] std.control:if
  [17] std.control:for
  [18] std.control:capture
  [19] std.control:const
  [20] std.build:requires
  [21] std.build:variants
  [22] std.build:config
  [23] std.build:command.sh
  [24] std.build:command.zig
  [25] std.build:step
  [26] std.template:define
error[KORU030]: Multiple disposal options for resource '_auto_0.file': input:close, input:flush_close. Discharge explicitly in your code.
  --> auto_discharge:36: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_028_ambiguous_without_default/backend.zig:10916:17: 0x102796433 in emit (backend)
                return error.CompilerCoordinationFailed;
                ^
/Users/larsde/src/koru/tests/regression/300_ADVANCED_FEATURES/330_PHANTOM_TYPES/330_028_ambiguous_without_default/backend.zig:11000:28: 0x1027971bf in main (backend)
    const generated_code = try RuntimeEmitter.emit(compile_allocator, final_ast);
                           ^

Test Configuration

MUST_FAIL