binding scopes

✓ 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
~event outer { x: i32 }
| result { value: i32 }

~proc outer {
    // x is accessible here directly
    return .{ .result = .{ .value = x } };
}

~event middle { y: i32 }
| data { val: i32 }

~proc middle {
    return .{ .data = .{ .val = y * 2 } };
}

~event inner { z: i32 }
| final { result: i32 }

~proc inner {
    return .{ .final = .{ .result = z * 3 } };
}

// Event with nested structure for field access testing
~event nested_data { info: UserInfo }
| processed { name_len: i32 }

// Define the struct type inline
const UserInfo = struct {
    profile: struct {
        name: []const u8,
        age: i32,
    },
};

~proc nested_data {
    // Access nested field
    const len: i32 = @intCast(info.profile.name.len);
    return .{ .processed = .{ .name_len = len } };
}

// Event to demonstrate access to outer scope bindings
~event show_values { a: i32, b: i32, c: i32 }
| done {}

~proc show_values {
    // Should print values showing the scope chain worked
    std.debug.print("Values from scope chain: {} {} {}\n", .{a, b, c});
    return .{ .done = .{} };
}

// Top-level flow to test scoping rules
// Test 1: Bindings persist through nested continuations
// r.value should be 10, d.val should be 20, f.result should be 60
~outer(x: 10)
| result r |> middle(y: r.value)
    | data d |> inner(z: d.val)
        | final f |> show_values(a: r.value, b: d.val, c: f.result)
            | done |> _

// 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 continuations
input.kz

Expected Output

Values from scope chain: 10 20 60

Test Configuration

MUST_RUN