✓
Passing This code compiles and runs correctly.
Code
// TEST: Undisposed nested obligation MUST error
//
// BUG: When an inner event returns an obligation, and the outer flow
// terminates without disposing it, the phantom checker should error.
// Currently it says "No uncleaned resources" incorrectly.
//
// MUST_FAIL: KORU030
~import "$app/fs"
// open returns file with [opened!]
// read returns content with [data!]
// We dispose file but NOT content - MUST error with KORU030!
~app.fs:open(path: "test.txt")
| opened f |> app.fs:read(f.file)
| data d |> app.fs:close(d.file)
| closed |> _ // BUG: d.content has [data!] not disposed - should error!
Imported Files
// Library module: fs with nested obligations
// Tests that nested obligations are tracked correctly
const std = @import("std");
const File = struct { handle: i32 };
const Data = struct { content: []const u8 };
// Open a file - returns opened! state
~pub event open { path: []const u8 }
| opened { file: *File[opened!] }
~proc open {
const f = std.heap.page_allocator.create(File) catch unreachable;
f.* = File{ .handle = 42 };
return .{ .opened = .{ .file = f } };
}
// Read - returns data! state (nested obligation)
~pub event read { file: *File[opened!] }
| data { file: *File[opened!], content: *Data[data!] }
~proc read {
const d = std.heap.page_allocator.create(Data) catch unreachable;
d.* = Data{ .content = "test content" };
return .{ .data = .{ .file = file, .content = d } };
}
// Close file - consumes opened!
~pub event close { file: *File[!opened] }
| closed {}
~proc close {
std.heap.page_allocator.destroy(file);
return .{ .closed = .{} };
}
// Free data - consumes data!
~pub event free { content: *Data[!data] }
~proc free {
std.heap.page_allocator.destroy(content);
}
Test Configuration
MUST_FAIL