✗
Failing This test is currently failing.
Failed: backend-exec
Failure Output
Showing last 10 of 38 lines
^
/Users/larsde/src/koru/tests/regression/300_ADVANCED_FEATURES/330_PHANTOM_TYPES/330_018_auto_discharge_escaped_obligation/backend.zig:9549:51: 0x1021c3077 in main (backend)
const generated_code = try RuntimeEmitter.emit(compile_allocator, final_ast);
^
/opt/homebrew/Cellar/zig/0.15.2_1/lib/zig/std/start.zig:627:37: 0x1021ca64b in main (backend)
const result = root.main() catch |err| {
^
???:?:?: 0x19815dd53 in ??? (???)
???:?:?: 0x0 in ??? (???)
/Users/larsde/src/koru/scripts/regression_lib.sh: line 33: 82126 Abort trap: 6 ./backend output Code
// TEST: Auto-discharge with escaped obligation via subflow
//
// This tests the full obligation lifecycle:
// 1. get_file subflow internally calls open()
// 2. get_file returns via branch constructor - obligation ESCAPES
// 3. Main flow receives the obligation via binding 'f'
// 4. Main flow terminates with '_' - obligation unsatisfied
// 5. Auto-discharge should insert close(file: f.file) in MAIN flow
//
// Expected: Compiles successfully with auto-inserted disposal in main flow
const std = @import("std");
const File = struct { handle: i32 };
// Open a file - returns opened! state (requires cleanup)
~event open { path: []const u8 }
| opened *File[opened!]
~proc open {
std.debug.print("Opening file\n", .{});
const f = std.heap.page_allocator.create(File) catch unreachable;
f.* = File{ .handle = 42 };
return .{ .opened = f };
}
// Close - the ONLY consumer of [!opened]
~event close { file: *File[!opened] }
| closed
~proc close {
std.debug.print("Closing file (auto-discharged)\n", .{});
return .{ .closed = .{} };
}
// Wrapper event that opens and returns file (obligation escapes)
~event get_file { path: []const u8 }
| got_file *File[opened!]
// Subflow: opens file, returns via branch constructor (obligation escapes!)
~get_file = open(path: path)
| opened f |> got_file { file: f.file }
// Main flow: calls get_file, receives escaped obligation, terminates
// Auto-discharge should insert close() HERE
~get_file(path: "test.txt")
| got_file _ |> _
pub fn main() void {}
Expected
Opening file
Closing file (auto-discharged)
Test Configuration
MUST_RUN