✓
Passing This code compiles and runs correctly.
Code
// Test 523: Constrained state variable accepts valid states
// Tests that M'owned|borrowed accepts both owned and borrowed
//
// Key points:
// - data:process has d: *Data[M'owned|borrowed]
// - M is constrained to ONLY owned OR borrowed
// - [owned] should be accepted, M = owned
// - [borrowed] should be accepted, M = borrowed
// - Output preserves the specific state that was passed
~import "$app/data"
// Test 1: Constraint accepts [owned]
~app.data:alloc()
| allocated a |> app.data:process(d: a)
| 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 d = allocator.create(Data) catch unreachable;
d.* = Data{ .value = 42 };
return .{ .allocated = d };
}
~pub event borrow { other: *Data[owned] }
| borrowed *Data[borrowed]
~proc borrow {
return .{ .borrowed = other };
}
// Generic processor constrained to owned OR borrowed
// Will NOT accept other states like "gc" or "static"
~pub event process { d: *Data[M'owned|borrowed] }
| done *Data[M'owned|borrowed] // Preserves whichever state was passed
~proc process {
return .{ .done = d };
}
// Generic processor constrained to owned OR borrowed
// Will NOT accept other states like "gc" or "static"
~pub event process { data: *Data[M'owned|borrowed] }
| done *Data[M'owned|borrowed] // Preserves whichever state was passed
~proc process {
return .{ .done = data };
}