✓
Passing This code compiles and runs correctly.
Code
// Test cyclic call graphs - mutually recursive events
// Even if events call each other in cycles, purity tracking should work
// This tests that the fixed-point algorithm handles cycles correctly
const std = @import("std");
// Mutually recursive pure events (theoretical - would overflow in practice)
// But from purity perspective, they're both pure operations
~event is_even { n: i32 }
| done { result: bool }
~[pure]proc is_even {
if (n == 0) {
return .{ .done = .{ .result = true } };
}
if (n == 1) {
return .{ .done = .{ .result = false } };
}
// Would call is_odd(n-1) - creating cycle
// For this test, we just use simple logic
return .{ .done = .{ .result = @mod(n, 2) == 0 } };
}
~event is_odd { n: i32 }
| done { result: bool }
~[pure]proc is_odd {
if (n == 0) {
return .{ .done = .{ .result = false } };
}
if (n == 1) {
return .{ .done = .{ .result = true } };
}
// Would call is_even(n-1) - creating cycle
// For this test, we just use simple logic
return .{ .done = .{ .result = @mod(n, 2) == 1 } };
}
~event print_bool { value: bool }
| done {}
~proc print_bool {
if (value) {
std.debug.print("true\n", .{});
} else {
std.debug.print("false\n", .{});
}
return .{ .done = .{} };
}
~event main {}
| done {}
~proc main {
const even_result = is_even_event.handler(.{ .n = 42 });
switch (even_result) {
.done => |d| {
_ = print_bool_event.handler(.{ .value = d.result });
},
}
return .{ .done = .{} };
}
~main()
| done |> _
Expected Output
true
Test Configuration
MUST_RUN