✓
Passing This code compiles and runs correctly.
Code
// Test 525: State variable chaining through multiple events
// Tests that M stays consistent across a chain of generic events
//
// Key points:
// - All events use *Data[M'_] (wildcard)
// - When we pass [owned], M = owned throughout the entire chain
// - validate(M) → process(M) → finalize(M) all preserve [owned]
// - Similarly, [borrowed] would flow through consistently
~import "$app/data"
// Test: State variable chains consistently
~app.data:alloc()
| allocated a |> app.data:validate(d: a)
| validated v |> app.data:process(d: v)
| processed p |> app.data:finalize(d: p)
| done _ |> _
Imported Files
const std = @import("std");
const Data = struct { value: i32 };
~pub event alloc {}
| allocated *Data[owned]
~proc alloc {
const allocator = std.heap.page_allocator;
const ptr = allocator.create(Data) catch unreachable;
ptr.* = Data{ .value = 42 };
return .{ .allocated = ptr };
}
~pub event borrow { other: *Data[owned] }
| borrowed *Data[borrowed]
~proc borrow {
return .{ .borrowed = other };
}
// Chain of events that all preserve the same state variable M
~pub event validate { d: *Data[M'_] }
| validated *Data[M'_] // Preserves M
~proc validate {
return .{ .validated = d };
}
~pub event process { d: *Data[M'_] }
| processed *Data[M'_] // Preserves M
~proc process {
return .{ .processed = d };
}
~pub event finalize { d: *Data[M'_] }
| done *Data[M'_] // Preserves M
~proc finalize {
return .{ .done = d };
}
// Chain of events that all preserve the same state variable M
~pub event validate { data: *Data[M'_] }
| validated *Data[M'_] // Preserves M
~proc validate {
return .{ .validated = data };
}
~pub event process { data: *Data[M'_] }
| processed *Data[M'_] // Preserves M
~proc process {
return .{ .processed = data };
}
~pub event finalize { data: *Data[M'_] }
| done *Data[M'_] // Preserves M
~proc finalize {
return .{ .done = data };
}