✓
Passing This code compiles and runs correctly.
Code
// Asymmetric manual/auto discharge across an `if` is VALID. `| else |> close(f)`
// discharges f manually; `| then |> _` discharges it automatically — `_` is an
// explicit "auto-discharge me", so the compiler inserts close(f) on the then arm.
// Whichever branch runs, f is closed: no leak. This is the else-manual / then-auto
// mirror of 330_024_if_hybrid_manual_auto (then-manual / else-auto).
~import std/control
~import app/fs
const condition = true;
~app/fs:open(path: "test.txt"): f |> if(condition)
| then |> _
| else |> app/fs:close(file: f)
Supporting Files
// JavaScript implementation facet. The Koru declarations live in the
// `fs.kz` companion (merged at import); this file holds the `|js`
// proc bodies mirroring its `|zig` ones.
//
// The Zig facet heap-allocates its `File` because Zig needs an address for a
// `*File`; the phantom `opened!` state is a compile-time obligation, not a
// runtime one. JS hands back the object itself and the same obligations are
// tracked by the same pass.
~proc open|js {
console.log(`Opening file: ${path}`);
return { handle: 42 };
}
~proc close|js {
console.log(`Closing file`);
}
// Library module: fs
// Defines filesystem operations with cleanup obligations
// Copied verbatim from 330_022_if_manual_both_branches/fs.kz
const std = @import("std");
// File type with phantom states
const File = struct {
handle: i32,
};
// Open a file - returns opened! state (requires cleanup)
~pub tor open { path: string } -> *File<opened!>
~proc open|zig {
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 f;
}
// Close a file - CONSUMES opened! state (disposes the resource)
~pub tor close { file: *File<!opened> }
~proc close|zig {
std.debug.print("Closing file\n", .{});
}
Actual
Opening file: test.txt
Closing file
Expected output
Opening file: test.txt
Closing file
Flows
flow ~open click a branch to expand · @labels scroll to their anchor
open (path: "test.txt")
Test Configuration
MUST_RUN