✓
Passing This code compiles and runs correctly.
Code
~import std/io
// Counter-pin to 400_222: when the each-body's leading step reads the item,
// nothing hoists — `make(d: i)` must run per iteration. Depths 1..4 build
// 3+7+15+31 = 56 nodes and check to 56; if the pass wrongly lifted the call
// the item would be unbound (refusal) or the mints count would collapse to a
// single tree — either way this output changes.
const std = @import("std");
const Node = struct { left: ?*Node, right: ?*Node };
var total_mints: u64 = 0;
fn freeNode(t: ?*Node) void {
if (t) |n| {
freeNode(n.left);
freeNode(n.right);
std.heap.c_allocator.destroy(n);
}
}
~tor mint-node { left: ?*Node<!owned>, right: ?*Node<!owned> } -> *Node<owned!>
~proc mint-node|zig {
total_mints += 1;
const n = std.heap.c_allocator.create(Node) catch unreachable;
n.* = .{ .left = left, .right = right };
return n;
}
~tor free-tree { t: ?*Node<!owned> }
~proc free-tree|zig {
freeNode(t);
}
~tor mints { } -> i64
~proc mints|zig {
return @intCast(total_mints);
}
~pub tor make { d: i64 } -> *Node<owned!>
~make = if(d > 0)
| then |> make(d: d - 1): l |> make(d: d - 1): r |> mint-node(left: l, right: r): n -> n
| else |> mint-node(left: null, right: null): n -> n
~pub tor check { t: ?*Node<*> } -> i64
~check = if(t != null)
| then |> check(t: t.?.left): l |> check(t: t.?.right): r -> 1 + l + r
| else -> 0
~capture { acc: 0[i64] }
! as g |> for(1..5)
! each i |> make(d: @as(i64, @intCast(i))): t |> check(t): c |> free-tree(t): _ |> captured { acc: g.acc + c }
| captured res |> mints(): m |> std/io:print.ln("{{ res.acc:d }} mints={{ m:d }}")
Actual
56 mints=56
Expected output
56 mints=56
Flows
subflow ~make click a branch to expand · @labels scroll to their anchor
if (d > 0)
subflow ~check click a branch to expand · @labels scroll to their anchor
if (t != null)
flow ~capture click a branch to expand · @labels scroll to their anchor
capture (source: acc: 0[i64])
Test Configuration
MUST_RUN