○
Planned This feature is planned but not yet implemented.
Auto-dispose for obligations in @loop branches not implemented
Code
// TEST: #loop/@loop scope behavior
// STATUS: PENDING IMPLEMENTATION
//
// When using #loop/@loop (label-based loops), the branch that leads to
// @loop creates a scope. Obligations created in that branch should be
// auto-discharged before the jump back.
//
// Here: The | next |> branch opens a file and jumps back.
// Each iteration should close the file before @loop.
//
// Expected: Compiles with open/close per iteration
~import "$app/fs"
const std = @import("std");
~event iterate { count: i32 }
| next { count: i32 }
| done {}
~proc iterate {
if (count < 3) {
return .{ .next = .{ .count = count + 1 } };
} else {
return .{ .done = .{} };
}
}
~#loop iterate(count: 0)
| next n |>
app.fs:open(path: "test.txt")
| opened f |> @loop(count: n.count) // Auto-close f before @loop
| done |> _
pub fn main() void {}
Expected Output
Opening file
Closing file
Opening file
Closing file
Opening file
Closing file
Imported Files
// Library module: fs
// Single disposal event
const std = @import("std");
const File = struct { handle: i32 };
// Open a file - returns opened! state (requires cleanup)
~pub event open { path: []const u8 }
| opened { file: *File[opened!] }
~proc open {
std.debug.print("Opening file\n", .{});
const f = std.heap.page_allocator.create(File) catch unreachable;
f.* = File{ .handle = 42 };
return .{ .opened = .{ .file = f } };
}
// Close - the ONLY consumer of [!opened]
~pub event close { file: *File[!opened] }
| closed {}
~proc close {
std.debug.print("Closing file\n", .{});
return .{ .closed = .{} };
}
Test Configuration
MUST_RUN