✓
Passing This code compiles and runs correctly.
Code
// Test 516: Use-after-disposal error
// Tests that using a resource after disposal is caught
//
// Key points:
// - open() returns *File[opened!]
// - close() accepts *File[!opened] and marks it as disposed
// - use_file() expects *File[opened]
// - ERROR: Cannot use f.file after it was disposed by close()
~import "$app/fs"
~app.fs:open(path: "test.txt")
| opened f |> app.fs:close(file: f.file)
| closed |> app.fs:use_file(file: f.file) // ERROR: f.file was disposed!
| used |> _
Error Verification
Expected Error Pattern
Backend should fail - no disposal event available or multiple disposal optionsActual 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 (25 items)
[PHASE 2.6] Rescanning transformed AST (25 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
[PHANTOM-KORU] Starting phantom check proc...
error[KORU030]: Use-after-disposal: binding 'f.file' was already disposed and cannot be used
--> phantom_semantic_check:13:0
❌ Compiler coordination error: Phantom semantic validation failed
error: CompilerCoordinationFailed
/Users/larsde/src/koru/tests/regression/300_ADVANCED_FEATURES/330_PHANTOM_TYPES/330_007_use_after_disposal/backend.zig:9470:17: 0x10240e433 in emit (backend)
return error.CompilerCoordinationFailed;
^
/Users/larsde/src/koru/tests/regression/300_ADVANCED_FEATURES/330_PHANTOM_TYPES/330_007_use_after_disposal/backend.zig:9554:28: 0x10240f1bf in main (backend)
const generated_code = try RuntimeEmitter.emit(compile_allocator, final_ast);
^Imported Files
const std = @import("std");
const File = struct { handle: i32 };
~pub event open { path: []const u8 }
| opened { file: *File[opened!] }
~proc open {
std.debug.print("Opening file: {s}\n", .{path});
const allocator = std.heap.page_allocator;
const f = allocator.create(File) catch unreachable;
f.* = File{ .handle = 42 };
return .{ .opened = .{ .file = f } };
}
~pub event close { file: *File[!opened] } // Consumes obligation
| closed {}
~proc close {
std.debug.print("Closing file\n", .{});
return .{ .closed = .{} };
}
~pub event use_file { file: *File[opened] } // Expects opened file
| used {}
~proc use_file {
std.debug.print("Using file\n", .{});
return .{ .used = .{} };
}
Test Configuration
MUST_FAIL