defaults and ?|
defaults gives a Result-producing expression chain a shared fallback.
?| is its shorthand spelling.
int32:x = a() + b() defaults 0i32;
int32:y = a() + b() ?| 0i32;
The two forms share the same AST and lowering path.
Value flow
For Result<T>:
| Input | Output |
|---|---|
Result(_, V, false) defaults F |
V |
Result(_, _, true) defaults F |
F |
Result(_, V, false) ?| F |
V |
Result(_, _, true) ?| F |
F |
Scoped expression fallback
The left side is low-precedence, so arithmetic and calls to the left are captured as part of the expression being defaulted.
int32:x = a() + b() defaults 0i32;
If either Result-producing part of the chain fails, the fallback supplies the final value.
Primary-expression fallback rule
The shipped parser restricts the fallback operand to a primary expression. That makes this shape intentionally asymmetric:
good() defaults 2 + 5 == (good() defaults 2) + 5
The + 5 is outside the fallback. Add parentheses or bind an intermediate
if you want a compound fallback expression.
int32:fb = 2i32 + 5i32;
int32:x = good() defaults fb;
When to prefer ?
Use ? for a single receiver:
int32:x = maybe() ? 0i32;
Use defaults / ?| when the expression around the receiver should share
the fallback:
int32:x = maybe_a() + maybe_b() defaults 0i32;