Files
sx/examples/232-failable-or-reject.sx
agra 50e5515080 ERR/E2.4a: failable or value-terminator
`lhs or value` where `lhs` is a value-carrying failable (`-> (T, !E)`): on
success the result is the LHS value, on failure the LHS error is discarded and
the result is the terminator value — the whole expression is non-failable (T).
Unblocked by the value ABI (E2.1); needs no fallback-routing (it's a 2-operand,
non-chained `or`).

- lowerBinaryOp `.or_op`: a failable LHS now routes to lowerFailableOr instead
  of the E1.4a loud bail; non-failable `or` (boolean / optional-unwrap)
  unchanged.
- lowerFailableOr: chain form (a `try`-marked LHS, whose own type is its
  success value, or a failable RHS) bails → E2.4b (fallback routing). Pure
  failable `or value` rejected ("no success value to fall back to — use
  catch"). Value-carrying: tuple_get the value/error, condBr, merge the LHS
  value (success) or the terminator (failure) through a block-param phi.
  Multi-value bails (E2).
- inferExprType `.or_op`: a failable `or value` types as the LHS success type
  (was always `.bool`); non-failable `or` still `.bool`.

Tests: examples/231-failable-or.sx (success + Bad + Empty terminators; exit
116), examples/232-failable-or-reject.sx (pure-failable `or value` rejected;
exit 1). Gates: zig build, zig build test, 270/270 examples.
2026-05-31 22:16:28 +03:00

20 lines
568 B
Plaintext

// Failable `or` rejection (ERR step E2.4a): the value-terminator form
// (`lhs or value`) requires a value-carrying failable LHS — a pure failable
// (`-> !`) has no success value to fall back to, so `or value` is rejected
// (use `catch` to absorb the error). The positive cases live in
// `examples/231-failable-or.sx`.
#import "modules/std.sx";
E :: error { Bad }
must :: (n: s32) -> !E {
if n < 0 { raise error.Bad; }
return;
}
main :: () -> s32 {
x := must(-1) or 0; // error: `-> !` has no success value to fall back to
return 0;
}