040 undisposed nested obligation

✓ 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!
input.kz

Error Verification

Expected Error Pattern

KORU030

Actual Compiler Output ✓ Pattern matched

[PHASE 2.4] Calling run_pass for transforms\n[PHASE 2.5] Executing comptime_main() - running comptime flows
[PHASE 2.5] Comptime flows complete (27 items)
[PHASE 2.6] Rescanning transformed AST (27 items)
[PHASE 2.6] Rescan complete: 25 comptime events found
  [0] std.compiler:requires
  [1] std.compiler:flag.declare
  [2] std.compiler:command.declare
  [3] std.compiler:coordinate
  [4] std.compiler:context_create
  [5] std.testing:test
  [6] std.testing:validate_mocks
  [7] std.testing:test.with_harness
  [8] std.testing:test.harness
  [9] std.testing:assert
  [10] std.testing:test.property.equivalent
  [11] std.deps:deps
  [12] std.deps:requires.system
  [13] std.deps:requires.zig
  [14] std.control:if
  [15] std.control:for
  [16] std.control:capture
  [17] std.control:const
  [18] std.build:requires
  [19] std.build:variants
  [20] std.build:config
  [21] std.build:command.sh
  [22] std.build:command.zig
  [23] std.build:step
  [24] std.template:define

[PHANTOM-KORU] Starting phantom check proc...
error[KORU030]: Resource 'd.content' with cleanup obligation 'app.fs:data!' was not disposed. Call the disposal event explicitly.
  --> 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:9511:17: 0x104afa433 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:9595:28: 0x104afb1bf 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: *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);
}
fs.kz

Test Configuration

MUST_FAIL