✓
Passing This code compiles and runs correctly.
Code
// Test: Auto-discharge cleans up undischarged handles at request end
// With auto-discharge: true, interpreter calls discharge events automatically
~import std/runtime
~import std/io
const std = @import("std");
~pub event open { path: []const u8 }
| opened []const u8<opened!>
~proc open|zig {
return .{ .opened = "file_1" };
}
~pub event close { handle: []const u8<!opened> }
~proc close|zig {
std.debug.print("close() was called by auto-discharge\n", .{});
}
~std/runtime:register(scope: "test") {
open(10)
close(1)
}
const TEST_SOURCE = "~open(path: \"test.txt\")\n| opened f |> result { status: \"done\" }";
// Open file but DON'T close - auto-discharge should clean up
~std/runtime:run(source: TEST_SOURCE, scope: "test", budget: 100, auto_discharge: true)
| result _ |> std/io:print.ln("PASS: auto-discharge ran")
| exhausted _ |> std/io:print.ln("FAIL: should not exhaust")
| parse-error _ |> std/io:print.ln("PARSE ERROR")
| validation-error _ |> std/io:print.ln("VALIDATION ERROR")
| shape-error _ |> std/io:print.ln("SHAPE ERROR")
| event-denied _ |> std/io:print.ln("EVENT DENIED")
| dispatch-error _ |> std/io:print.ln("DISPATCH ERROR")
| scope-not-found _ |> std/io:print.ln("SCOPE NOT FOUND")
Actual
close() was called by auto-discharge
[AUTO-DISCHARGE] Invoked 'close' for handle 'file_1' [main:opened]
PASS: auto-discharge ran
Expected output
close() was called by auto-discharge
[AUTO-DISCHARGE] Invoked 'close' for handle 'file_1' [main:opened]
PASS: auto-discharge ran
Test Configuration
MUST_RUN