✓
Passing Passing: the compiler rejects this program as expected.
Code
// An obligation with several disposers that reaches a `! each` scope exit
// undisposed is refused at the scope arm (`! each ...`), not the flow head —
// "Discharge explicitly" tells the author the remedy and the caret says where.
import std/control
import app/fs2
for(0..3)
! each _ |> app/fs2:open(path: "x"): f |> app/fs2:lock(file: f): g
| done |> _
Supporting Files
// Library module: fs
// State transitions with multiple disposal options (mimics string library)
const std = @import("std");
const File = struct { handle: i32 };
// Open a file - returns opened! state
~pub tor open { path: string } -> *File<opened!>
~proc open|zig {
const f = std.heap.page_allocator.create(File) catch unreachable;
f.* = File{ .handle = 42 };
return f;
}
// Lock - transition opened! -> locked!
~pub tor lock { file: *File<!opened> } -> *File<locked!>
~proc lock|zig {
return file;
}
// Write - requires locked state (doesn't consume)
~pub tor write { file: *File<locked>, data: string }
| written
| err string
~proc write|zig {
std.debug.print("Writing: {s}\n", .{data});
return .{ .written = .{} };
}
// Unlock - consumes locked! (Option 1 for disposing locked!)
~pub tor unlock { file: *File<!locked> }
~proc unlock|zig {
std.debug.print("Unlocking\n", .{});
std.heap.page_allocator.destroy(file);
}
// Force close - also consumes locked! (Option 2 for disposing locked!)
~pub tor force-close { file: *File<!locked> }
~proc force-close|zig {
std.debug.print("Force closing\n", .{});
std.heap.page_allocator.destroy(file);
}
Actual compiler output
error[KORU030]: Resource 'g' <locked!> has multiple discharge options: force-close, unlock. Discharge explicitly.
--> tests/regression/300_ADVANCED_FEATURES/330_PHANTOM_TYPES/330_131_scope_exit_ambiguity_names_the_arm/input.k:7:0
❌ Compiler coordination error: Auto-discharge failed (multiple disposal options or no disposal event)
(set KORU_BACKEND_TRACE=1 for the backend return trace)Must contain:
has multiple discharge options: force-close, unlockFlows
flow ~for click a branch to expand · @labels scroll to their anchor
for (0..3)
Test Configuration
MUST_ERROR