006 cleanup consumed by disposal

✓ Passing This code compiles and runs correctly.

Code

// Test 515: Cleanup obligation consumed by disposal
// Tests that [!state] syntax properly consumes cleanup obligations
//
// Key points:
// - open() returns *File[opened!] (produces obligation)
// - close() accepts *File[!opened] (consumes obligation)
// - After disposal, obligation is satisfied
// - Terminator should not error

~import "$app/fs"

~app.fs:open(path: "test.txt")
| opened f |> app.fs:close(file: f.file)
    | closed |> _
input.kz

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] }  // [!opened] means CONSUMES obligation
| closed {}

~proc close {
    std.debug.print("Closing file\n", .{});
    return .{ .closed = .{} };
}
fs.kz