✓
Passing This code compiles and runs correctly.
Code
// Test 522: State variable with wildcard (_)
// Tests that M'_ accepts any state and preserves it through event
//
// Key points:
// - data:process has d: *Data[M'_]
// - M'_ is a wildcard - accepts ANY state
// - The same M is used in output, preserving the state
// - Should work with [owned], [borrowed], or any other state
~import "$app/data"
// Test 1: Wildcard accepts [owned]
~app.data:alloc()
| allocated a |> app.data:process(d: a.data) // M'_ accepts [owned], M = owned
| done _ |> _ // d.d: *Data[owned] - preserved!
Imported Files
const std = @import("std");
const Data = struct { value: i32 };
~pub event alloc {}
| allocated { data: *Data[owned] }
~proc alloc {
const allocator = std.heap.page_allocator;
const d = allocator.create(Data) catch unreachable;
d.* = Data{ .value = 42 };
return .{ .allocated = .{ .data = d } };
}
~pub event borrow { other: *Data[owned] }
| borrowed { data: *Data[borrowed] }
~proc borrow {
return .{ .borrowed = .{ .data = other } };
}
// Generic processor that accepts data in ANY state and preserves it
~pub event process { d: *Data[M'_] }
| done { d: *Data[M'_] } // Wildcard: accepts any state, preserves it
~proc process {
// Process the data without changing its state
return .{ .done = .{ .d = d } };
}
// Generic processor that accepts data in ANY state and preserves it
const Data = struct { value: i32 };
~pub event process { d: *Data[M'_] }
| done { d: *Data[M'_] } // Wildcard: accepts any state, preserves it
~proc process {
// Process the data without changing its state
return .{ .done = .{ .d = d } };
}