Files
sx/examples/issue-0008.sx
agra dd14f1206b ir
2026-02-26 02:25:02 +02:00

27 lines
723 B
Plaintext

// Issue 0008: Chained ?? (null coalescing) doesn't work
//
// `a ?? b ?? c` where a: ?f32, b: ?f32, c: f32 fails with:
// "narrowing conversion from '?f32' to 'f32' requires explicit 'xx' cast"
//
// It parses as (a ?? b) ?? c, and the first ?? rejects ?f32 as the rhs.
//
// Expected: ?? should either be right-associative so it parses as a ?? (b ?? c),
// or allow ?T as the rhs (returning ?T when rhs is optional, T when rhs is concrete).
//
// Workaround: use parentheses — a ?? (b ?? c)
Foo :: struct {
x: ?f32;
y: ?f32;
}
main :: () -> void {
f := Foo.{ x = 1.0, y = 2.0 };
// This works:
ok := f.x ?? (f.y ?? 0.0);
// This should also work but fails:
bad := f.x ?? f.y ?? 0.0;
}