ERR/E1.8: reject dropping a failable's error slot on destructure
The error slot of a value-carrying failable can no longer be silently dropped on a bare destructure. In lowerDestructureDecl, when the RHS is failable (errorChannelOf(ty) != null), the error slot (always the last tuple field) must be bound to a non-`_` name. Reject when it is omitted entirely (fewer names than slots — e.g. `a, c := inc(5)` for `inc: -> (s32,s32,!E)`) or bound to `_` (`v, _ := parse(5)`). The `try` / `catch` / `or value` consumer forms all strip the error channel (their result type is non-failable), so the check never fires on them — only a bare failable destructure is rejected. Value-slot `_` discards stay legal (`a, _, ae := pair()` binds the error). This is the discard-rejection slice of E1.8; the path-sensitive flow-check (value live only where err==null is provable) is a separate follow-up. examples/236-failable-discard-reject.sx covers both rejected shapes (exit 1). Gates: zig build, zig build test, 274/274 examples.
This commit is contained in:
1
tests/expected/236-failable-discard-reject.exit
Normal file
1
tests/expected/236-failable-discard-reject.exit
Normal file
@@ -0,0 +1 @@
|
||||
1
|
||||
11
tests/expected/236-failable-discard-reject.txt
Normal file
11
tests/expected/236-failable-discard-reject.txt
Normal file
@@ -0,0 +1,11 @@
|
||||
error: the error slot of a failable cannot be dropped — bind it (`v, err := …`) and handle it, or use `try` / `catch`
|
||||
--> /Users/agra/projects/sx/examples/236-failable-discard-reject.sx:27:13
|
||||
|
|
||||
27 | a, b := pair(5); // ERROR: error slot omitted (3 slots, 2 names)
|
||||
| ^^^^^^^
|
||||
|
||||
error: the error slot of a failable cannot be dropped — bind it (`v, err := …`) and handle it, or use `try` / `catch`
|
||||
--> /Users/agra/projects/sx/examples/236-failable-discard-reject.sx:28:13
|
||||
|
|
||||
28 | v, _ := parse(5); // ERROR: error slot discarded with `_`
|
||||
| ^^^^^^^^
|
||||
Reference in New Issue
Block a user