✓
Passing This code compiles and runs correctly.
Code
// Test 517: Obligation escapes via interface
// Tests that obligations can escape through return signatures
//
// Key points:
// - my_subflow internally opens a file (via subflow composition)
// - my_subflow returns *File[opened!] in its signature
// - This documents that the obligation escapes
// - The CALLER receives the obligation and must handle it
// - Caller closes the file, satisfying the obligation
~import "$app/fs"
~app.fs:my_subflow()
| file_opened f |> app.fs:close(file: f.file)
| closed |> _
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] }
| closed {}
~proc close {
std.debug.print("Closing file\n", .{});
return .{ .closed = .{} };
}
// Subflow that opens a file and returns it with obligation
// The obligation escapes via the return signature - caller must handle it
~pub event my_subflow {}
| file_opened { file: *File[opened!] }
// SUBFLOW: Delegates to open, maps opened → file_opened
// The [opened!] obligation passes through to the caller
~my_subflow = open(path: "data.txt")
| opened f |> file_opened { file: f.file }