✓
Passing This code compiles and runs correctly.
Code
// TEST: Auto-discharge with MULTIPLE nested resources
//
// Open TWO files in nested continuations.
// User closes SECOND file explicitly, but leaves FIRST for auto-discharge.
//
// Expected: Second is closed explicitly, first is auto-closed
~import "$app/fs"
const std = @import("std");
// Open first file (use _ for auto-discharge)
// Then open second, close it explicitly
// The outer file should be auto-closed at the terminal
~app.fs:open(path: "first.txt")
| opened _ |>
app.fs:open(path: "second.txt")
| opened f2 |>
app.fs:close(file: f2.file)
| closed |> _
pub fn main() void {}
Expected Output
Opening: first.txt
Opening: second.txt
Closing file
Closing file
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: {s}\n", .{path});
const f = std.heap.page_allocator.create(File) catch unreachable;
f.* = File{ .handle = 42 };
return .{ .opened = .{ .file = f } };
}
~pub event close { file: *File[!opened] }
| closed {}
~proc close {
std.debug.print("Closing file\n", .{});
return .{ .closed = .{} };
}
Test Configuration
MUST_RUN