✓
Passing This code compiles and runs correctly.
Code
// PRIORITY: Combined test for all continuation codegen bugs
//
// This test exercises THREE bugs simultaneously:
// 1. Void event chaining (220_021) - switch on void
// 2. Nested branch shadowing (220_020) - |done| shadows |done|
// 3. Escape field name mismatch (330_052) - escape by name not value
//
// When all three are fixed, this test passes and Koru gets its signature syntax.
~import std/control
~import std/build
// Link libc for c_allocator
~std/build:requires { exe.linkLibC(); }
const std = @import("std");
const Resource = struct {
id: usize,
data: [64]u8,
};
const allocator = std.heap.c_allocator;
// ============================================================
// BUG #1: Void event chaining
// These are void events - no branches. Should chain with |>
// ============================================================
~event work-void { r: *Resource }
~proc work-void|zig {
r.data[0] +%= 1;
}
// ============================================================
// BUG #2: Nested branch shadowing
// Same branch name "done" at multiple nesting levels
// ============================================================
~event work-done { r: *Resource }
~proc work-done|zig {
r.data[0] +%= 1;
}
// ============================================================
// BUG #3: Escape field name mismatch
// Obligation escapes to differently-named field
// ============================================================
~event create { id: usize }
| created *Resource<active!>
~proc create|zig {
const r = allocator.create(Resource) catch unreachable;
r.* = Resource{ .id = id, .data = undefined };
return .{ .created = r };
}
~event destroy { r: *Resource<!active> }
~proc destroy|zig {
allocator.destroy(r);
}
// Factory with DIFFERENT field name than create
~event make-resource { id: usize }
| ready *Resource<active!> // "resource" not "r"
// BUG #3: f.r -> resource field name mismatch
~make-resource = create(id)
| created f => ready f
// ============================================================
// COMBINED TEST: Bugs #2 and #3 (void chaining is parser issue)
// ============================================================
const N: usize = 10;
~for(0..N)
! each i |> make-resource(id: i)
| ready r |> work-done(r) |> work-done(r) |> work-done(r) |> destroy(r)
pub fn main() void {
std.debug.print("All continuation bugs fixed!\n", .{});
}
Test Configuration
MUST_RUN