✓
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!
Error Verification
Expected Error Pattern
KORU030Actual Compiler Output ✓ Pattern matched
error[KORU033]: Cannot issue obligation '[opened!]' on input parameter (event: read). Use '[!opened]' to consume an existing obligation, or remove the '!' suffix.
--> phantom_semantic_check:22:0
error[KORU030]: Phantom state mismatch: argument 'file' has no tracked phantom state, but event requires '[opened!]'. The value must be in state 'app.fs:opened!'.
--> phantom_semantic_check:16:0
❌ Compiler coordination error: Phantom semantic validation failed
error: CompilerCoordinationFailed
/Users/larsde/src/koru/tests/regression/300_ADVANCED_FEATURES/330_PHANTOM_TYPES/330_040_undisposed_nested_obligation/backend.zig:9517:17: 0x102dfa4af in emit (backend)
return error.CompilerCoordinationFailed;
^
/Users/larsde/src/koru/tests/regression/300_ADVANCED_FEATURES/330_PHANTOM_TYPES/330_040_undisposed_nested_obligation/backend.zig:9601:28: 0x102dfb2b7 in main (backend)
const generated_code = try RuntimeEmitter.emit(compile_allocator, final_ast);
^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[opened!]
~proc open {
const f = std.heap.page_allocator.create(File) catch unreachable;
f.* = File{ .handle = 42 };
return .{ .opened = 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