multiple resources partial cleanup

✓ Passing This code compiles and runs correctly.

Code

// Test 521: Multiple resources - partial cleanup (MUST FAIL)
// Tests that the compiler catches when only ONE of TWO resources is cleaned
//
// Key points:
// - open_two() returns TWO files, each with [opened!]
// - We only close ONE file (file1)
// - ERROR: file2 still has cleanup obligation
// - This verifies each obligation is tracked independently

~import "$app/fs"

~app.fs:open_two(path1: "test1.txt", path2: "test2.txt")
| opened f |> app.fs:close(file: f.file1)  // Close first file only
    | closed |> _  // ERROR: f.file2 still uncleaned!
input.kz

Imported Files

const std = @import("std");
const File = struct { handle: i32 };

~pub event open_two { path1: []const u8, path2: []const u8 }
| opened { file1: *File[opened!], file2: *File[opened!] }  // TWO obligations!

~proc open_two {
    std.debug.print("Opening two files: {s}, {s}\n", .{path1, path2});
    const allocator = std.heap.page_allocator;
    const f1 = allocator.create(File) catch unreachable;
    const f2 = allocator.create(File) catch unreachable;
    f1.* = File{ .handle = 42 };
    f2.* = File{ .handle = 43 };
    return .{ .opened = .{ .file1 = f1, .file2 = f2 } };
}

~pub event close { file: *File[!opened] }  // Consumes one obligation
| closed {}

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

Test Configuration

MUST_FAIL