Something went wrong. Try again.
Jam Programming Language jamlang.org
compiler
Something went wrong. Try again.
12345678910111213141516171819202122232425262728// std.maybe — Maybe(T) tests.//// Single-value init / assumeInit round-trip. The Vec-upgrade pattern// (`Maybe(T).assumeInitVec(vec)` — Rust's `Box::new_uninit_slice + assume_init`)// is TODO in std/maybe.jam; it needs a `Vec.allocUninit(n)` constructor// first. When that lands, add a test that allocates Vec(Maybe(T)), fills// every slot, and round-trips to Vec(T).
const { assert } = import("test");const { Maybe } = import("std/maybe");
tfn maybeU32() { const m: Maybe(u32) = Maybe(u32).init(42); assert(m.assumeInit(), 42);}
// Same shape for a struct payload — confirms the wrapper handles// non-primitive Ts (sizeof + layout right) and assumeInit returns the// struct by value.const Point = struct { x: i32, y: i32 };
tfn maybeStruct() { const m: Maybe(Point) = Maybe(Point).init(Point { x: 3, y: 4 }); const p: Point = m.assumeInit(); assert(p.x, 3); assert(p.y, 4);}