✓
Passing This code compiles and runs correctly.
Code
// ============================================================================
// VERIFIED REGRESSION TEST - DO NOT MODIFY WITHOUT DISCUSSION
// ============================================================================
// Test 513: Cleanup obligation escape
// Tests that semantic phantom checker detects cleanup obligations not met
// Demonstrates: ! marker for states requiring cleanup before disposal
// Expected: Should FAIL with "cleanup obligation not met" error
~import "$std/io"
~import "$app/fs"
// Open a file with opened! state
// The ! marker means this state requires cleanup (calling app.fs:close)
// before the flow terminates
~app.fs:open(path: "test.txt")
| opened |> _ // ERROR: Flow ends with *File[opened!] not cleaned up!
// This SHOULD fail because:
// 1. app.fs:open returns *File[opened!]
// 2. The flow terminates (_) without calling app.fs:close
// 3. The cleanup obligation is not met
// To fix, should do:
// ~app.fs:open(path: "test.txt")
// | opened f |> app.fs:close(file: f.file)
// | closed |> std.io:println(text: "File closed properly")
Error Verification
Expected Error Pattern
Backend should fail - no disposal event available or multiple disposal optionsActual Compiler Output
[PHASE 2.4] Calling run_pass for transforms\n[PHASE 2.5] Executing comptime_main() - running comptime flows
[PHASE 2.5] Comptime flows complete (36 items)
[PHASE 2.6] Rescanning transformed AST (36 items)
[PHASE 2.6] Rescan complete: 27 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.io:print.ln
[6] std.io:print.blk
[7] std.testing:test
[8] std.testing:validate_mocks
[9] std.testing:test.with_harness
[10] std.testing:test.harness
[11] std.testing:assert
[12] std.testing:test.property.equivalent
[13] std.deps:deps
[14] std.deps:requires.system
[15] std.deps:requires.zig
[16] std.control:if
[17] std.control:for
[18] std.control:capture
[19] std.control:const
[20] std.build:requires
[21] std.build:variants
[22] std.build:config
[23] std.build:command.sh
[24] std.build:command.zig
[25] std.build:step
[26] std.template:define
error[KORU030]: branch 'opened' has payload but no binding
--> structural_check:16:0
❌ Compiler coordination error: Incomplete branch coverage
error: CompilerCoordinationFailed
/Users/larsde/src/koru/tests/regression/300_ADVANCED_FEATURES/330_PHANTOM_TYPES/330_004_cleanup_obligation_escape/backend.zig:10917:17: 0x10071e433 in emit (backend)
return error.CompilerCoordinationFailed;
^
/Users/larsde/src/koru/tests/regression/300_ADVANCED_FEATURES/330_PHANTOM_TYPES/330_004_cleanup_obligation_escape/backend.zig:11001:28: 0x10071f1bf in main (backend)
const generated_code = try RuntimeEmitter.emit(compile_allocator, final_ast);
^Imported Files
// Library module: fs
// Defines filesystem operations with cleanup obligations
const std = @import("std");
// File type with phantom states
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: {s}\n", .{path});
const allocator = std.heap.page_allocator;
const f = allocator.create(File) catch unreachable;
f.* = File{ .handle = 42 };
return .{ .opened = .{ .file = f } };
}
// Close a file - accepts opened state, returns closed state
~pub event close { file: *File[!opened] }
| closed {}
~proc close {
std.debug.print("Closing file\n", .{});
return .{ .closed = .{} };
}
Test Configuration
MUST_FAIL