✓
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")
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