021 field punning shorthand

✓ Passing This code compiles and runs correctly.

Code

// Test 210_021: Struct Field Punning Shorthand
// When field value is an expression like `p.x`, infer field name from last segment
//
// Syntax: { p.x, p.y } should expand to { x: p.x, y: p.y }

~import "$std/io"

pub const Point = struct { x: i32, y: i32 };

~event make_point { x: i32, y: i32 }
| point { p: Point }

~proc make_point {
    return .{ .point = .{ .p = Point{ .x = x, .y = y } } };
}

~event use_point { p: Point }
| result { x: i32, y: i32 }

// Shorthand: { p.x, p.y } should become { x: p.x, y: p.y }
~use_point = result { p.x, p.y }

// Test it
~make_point(x: 10, y: 20)
| point pt |> use_point(p: pt.p)
    | result r |> std.io:print.ln("punning works: x={{ r.x }}, y={{ r.y }}")
input.kz

Expected Output

punning works: x=10, y=20

Test Configuration

MUST_RUN