007 use after disposal

✓ 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 |> _
input.kz

Error Verification

Expected Error Pattern

Backend should fail - no disposal event available or multiple disposal options

Actual Compiler Output

error[KORU030]: Phantom state mismatch: argument 'file' has no tracked phantom state, but event requires '[!opened]' (consumption). Did you mean to pass a value with state 'app.fs:opened'?
  --> phantom_semantic_check:13:0

error[KORU030]: Phantom state mismatch: argument 'file' has no tracked phantom state, but event requires '[opened]'. The value must be in state 'app.fs:opened'.
  --> 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:9476:17: 0x10056e4af 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:9560:28: 0x10056f2b7 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[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 = 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 = .{} };
}
fs.kz

Test Configuration

MUST_FAIL