✓
Passing This code compiles and runs correctly.
Code
// TEST: Auto-discharge with no consumer - MUST FAIL
// STATUS: PENDING IMPLEMENTATION
// MUST_FAIL: No disposal event found
//
// When no event consumes the obligation [!state], the compiler
// cannot auto-discharge and should error clearly.
//
// Here: open() returns *File[opened!] but NO event has [!opened]
// Compiler should error: "No disposal event found for [opened!]"
//
// This indicates a library bug - the library author forgot to
// provide a disposal event for the resource.
~import "$app/fs"
// This should FAIL - no way to dispose!
~app.fs:open(path: "test.txt")
| opened _ |> _
pub fn main() void {}
Error Verification
Expected Error Pattern
MUST_FAILActual 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: 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.file' with state 'app.fs:opened!'. Library must define an event with [!app.fs:opened!] parameter.
--> auto_discharge:18: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_012_auto_discharge_none/backend.zig:9349:17: 0x101096433 in emit (backend)
return error.CompilerCoordinationFailed;
^
/Users/larsde/src/koru/tests/regression/300_ADVANCED_FEATURES/330_PHANTOM_TYPES/330_012_auto_discharge_none/backend.zig:9433:28: 0x1010971bf in main (backend)
const generated_code = try RuntimeEmitter.emit(compile_allocator, final_ast);
^Imported Files
// Library module: fs
// NO disposal event defined - should error
const std = @import("std");
const File = struct { handle: i32 };
// Open a file - returns opened! state (requires cleanup)
~pub 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 } };
}
// Oops! No close() or any event with [!opened] defined!
// This is a library bug - no way to satisfy the obligation
Test Configuration
MUST_FAIL
Expected Error:
No disposal event found