ERR/E1.5: catch sema (pure-failable slice) + error-set match subjects
`expr catch [e] BODY` consumes a failable's error inline. Pure-failable slice
(value-carrying `-> (T, !)` catch deferred to E2's tuple ABI).
- lowerExpr `.catch_expr` -> lowerCatch; inferExprType `.catch_expr` ->
operand's success type (void for pure-failable).
- lowerCatch: operand must be failable (else "catch requires a failable
expression"); pure-failable LHS only (value-carrying bails to E2). Eval
operand -> err tag; condBr to handle (error) / merge (success). In handle:
child scope binds `e` to the tag (typed as the error set), lower body
(block or expr); if the body didn't diverge, br merge. Result is void.
`catch` needs no failable enclosing function — it handles the error locally.
- All four body forms work: block, no-binding `catch { }`, bare-expr, and
the match-body `catch e == { case ... }`. Re-raise (`raise e`) and diverging
bodies (`return`) rely on E1.3 / E1.4c.
Also: lowerMatch now supports error-set subjects — `case .X` resolves to the
global tag id (was the arm index, dispatching wrong), and the switch operand
is the error-set value (its u32 tag) directly rather than via enumTag. This
is what the catch match-body form (and a plain `if e == { case .X }`) needs.
Tests: examples/226-catch.sx (block / no-binding / match-body / re-raise /
diverging body / success-skip; exit 18), examples/227-catch-rejections.sx
(operand-not-failable; exit 1). Gates: zig build, zig build test,
265/265 examples.
This commit is contained in:
1
tests/expected/226-catch.exit
Normal file
1
tests/expected/226-catch.exit
Normal file
@@ -0,0 +1 @@
|
||||
18
|
||||
1
tests/expected/226-catch.txt
Normal file
1
tests/expected/226-catch.txt
Normal file
@@ -0,0 +1 @@
|
||||
catch result: 18
|
||||
1
tests/expected/227-catch-rejections.exit
Normal file
1
tests/expected/227-catch-rejections.exit
Normal file
@@ -0,0 +1 @@
|
||||
1
|
||||
5
tests/expected/227-catch-rejections.txt
Normal file
5
tests/expected/227-catch-rejections.txt
Normal file
@@ -0,0 +1,5 @@
|
||||
error: `catch` requires a failable expression; operand has type 's32'
|
||||
--> /Users/agra/projects/sx/examples/227-catch-rejections.sx:11:5
|
||||
|
|
||||
11 | plain() catch e { return 1; }; // error: operand has type s32 (not failable)
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
Reference in New Issue
Block a user