✓
Passing This code compiles and runs correctly.
Code
// Test 202: Binding scopes and persistence
// Tests the scoping rules from SPEC.md:
// - Bindings persist through ALL nested continuations
// - Parent bindings remain accessible at any depth
// - Duplicate binding names are forbidden (enforced by parser)
const std = @import("std");
// Events for testing scoping
~tor outer { x: i32 } -> i32
~proc outer|zig {
// x is accessible here directly
return x;
}
~tor middle { y: i32 } -> i32
~proc middle|zig {
return y * 2;
}
~tor inner { z: i32 } -> i32
~proc inner|zig {
return z * 3;
}
// Event with nested structure for field access testing
~tor nested-data { info: UserInfo } -> i32
// Define the struct type inline
const UserInfo = struct {
profile: struct {
name: []const u8,
age: i32,
},
};
~proc nested-data|zig {
// Access nested field
const len: i32 = @intCast(info.profile.name.len);
return len;
}
// Event to demonstrate access to outer scope bindings
~tor show-values { a: i32, b: i32, c: i32 }
~proc show-values|zig {
// Should print values showing the scope chain worked
std.debug.print("Values from scope chain: {} {} {}\n", .{a, b, c});
}
// Top-level flow to test scoping rules
// Test 1: Bindings persist through nested continuations
// r should be 10, d should be 20, f should be 60
~outer(x: 10): r |> middle(y: r): d |> inner(z: d): f |> show-values(a: r, b: d, c: f)
// The binding 'r' from outer should be accessible in all nested continuations
// The binding 'd' from middle should be accessible in inner's continuation
// Each binding creates a new scope that persists through its continuationsActual
Values from scope chain: 10 20 60
Expected output
Values from scope chain: 10 20 60Flows
flow ~outer click a branch to expand · @labels scroll to their anchor
outer (x: 10)
Test Configuration
MUST_RUN