✓
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.d) // M'_ accepts [owned], M = owned
| validated v |> app.data:process(d: v.d) // M'_ accepts [owned], M = owned
| processed p |> app.data:finalize(d: p.d) // M'_ accepts [owned], M = owned
| done _ |> _ // d.d: *Data[owned] - M preserved through entire chain!
Imported Files
const std = @import("std");
const Data = struct { value: i32 };
~pub event alloc {}
| allocated { d: *Data[owned] }
~proc alloc {
const allocator = std.heap.page_allocator;
const ptr = allocator.create(Data) catch unreachable;
ptr.* = Data{ .value = 42 };
return .{ .allocated = .{ .d = ptr } };
}
~pub event borrow { other: *Data[owned] }
| borrowed { d: *Data[borrowed] }
~proc borrow {
return .{ .borrowed = .{ .d = other } };
}
// Chain of events that all preserve the same state variable M
~pub event validate { d: *Data[M'_] }
| validated { d: *Data[M'_] } // Preserves M
~proc validate {
return .{ .validated = .{ .d = d } };
}
~pub event process { d: *Data[M'_] }
| processed { d: *Data[M'_] } // Preserves M
~proc process {
return .{ .processed = .{ .d = d } };
}
~pub event finalize { d: *Data[M'_] }
| done { d: *Data[M'_] } // Preserves M
~proc finalize {
return .{ .done = .{ .d = d } };
}
// Chain of events that all preserve the same state variable M
~pub event validate { data: *Data[M'_] }
| validated { data: *Data[M'_] } // Preserves M
~proc validate {
return .{ .validated = .{ .data = data } };
}
~pub event process { data: *Data[M'_] }
| processed { data: *Data[M'_] } // Preserves M
~proc process {
return .{ .processed = .{ .data = data } };
}
~pub event finalize { data: *Data[M'_] }
| done { data: *Data[M'_] } // Preserves M
~proc finalize {
return .{ .done = .{ .data = data } };
}