✓
Passing This code compiles and runs correctly.
Code
// PIN: outer resource discharged inside the ! each body.
// Even with a single-iteration loop (0..1), the body is a repeating scope
// boundary — discharging there violates the @scope rule.
// Austral rule: "a linear value defined outside a loop cannot appear in the loop body."
//
// Grounding:
// Legal form (discharge in | done): 330_044_for_manual_done_ok/input.kz:3-6
// Illegal form (discharge in ! each): 330_045_for_manual_each_error/input.kz:3-6
// (330_045 uses 0..3; this test uses 0..1 to isolate the scope issue from count)
// for + each + done structure: 330_032_nested_for_scopes/input.kz:4-9
// KORU032 message: "Cannot discharge outer-scope resource inside @scope boundary"
~import std/control
~import app/fs
~app/fs:open(path: "outer.txt")
| opened outer_f |> std/control:for(0..1)
! each _ |> app/fs:close(file: outer_f) // ERROR: outer_f is in @scope, body runs once but COULD run N times
| done |> _
Must contain:
KORU032Error Verification
Actual Compiler Output
error[KORU032]: Cannot discharge outer-scope resource 'outer_f' inside @scope boundary. Handle outside the scope or escape via branch constructor.
--> auto_discharge:15:0
❌ Compiler coordination error: Auto-discharge failed (multiple disposal options or no disposal event)
error: CompilerCoordinationFailed
/Users/larsde/src/koru/tests/regression/300_ADVANCED_FEATURES/335_OBLIGATION_STRESS/335_004_loop_body_discharges_outer/backend.zig:94:13: 0x10115e3b3 in emit (backend)
return error.CompilerCoordinationFailed;
^
/Users/larsde/src/koru/tests/regression/300_ADVANCED_FEATURES/335_OBLIGATION_STRESS/335_004_loop_body_discharges_outer/backend.zig:190:28: 0x10115f09f 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<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 .{ .opened = f };
}
// Close a file - CONSUMES opened! state (disposes the resource)
~pub event close { file: *File<!opened> }
~proc close|zig {
std.debug.print("Closing file\n", .{});
}
Test Configuration
MUST_FAIL