lang: catch/onfail error bindings take parens
try foo() catch (e) { } // legal
try foo() catch e { } // parse error with a migration hint
Same capture style as the for-loop. All four catch shapes keep working
with the parenthesized binding — block, bare-expression body, and the
== match sugar — and the no-binding forms are unchanged. onfail follows
the same rule (onfail (e) { }); its expression-cleanup form is
disambiguated by the paren-group-before-brace lookahead, so
onfail (f()); stays an expression cleanup.
AST unchanged; the printer renders the parens; the #run escape help
text updated. Corpus migrated (57 catch + 3 onfail bindings, in-source
parser test strings, specs incl. grammar rules, readme untouched —
no catch examples there).
Regression: examples/1157-diagnostics-catch-binding-needs-parens.sx;
re-captured stderr for 1010/1013/1037/1123 (migrated source echoed in
carets + help text).
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
error: `catch` requires a failable expression; operand has type 's32'
|
||||
--> /Users/agra/projects/sx/examples/1010-errors-catch-rejections.sx:11:5
|
||||
--> examples/1010-errors-catch-rejections.sx:11:5
|
||||
|
|
||||
11 | plain() catch e { return 1; }; // error: operand has type s32 (not failable)
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
11 | plain() catch (e) { return 1; }; // error: operand has type s32 (not failable)
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
error: `catch` body must produce a value of type 's32' (or diverge with `return` / `raise`)
|
||||
--> /Users/agra/projects/sx/examples/1013-errors-value-failable-reject.sx:17:10
|
||||
--> examples/1013-errors-value-failable-reject.sx:17:10
|
||||
|
|
||||
17 | x := parse(-1) catch e { print("oops\n") }; // error: body yields no value
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
17 | x := parse(-1) catch (e) { print("oops\n") }; // error: body yields no value
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
error: comptime `#run` (x) raised an unhandled error: error.Bad
|
||||
error return trace (most recent call last):
|
||||
parse at 1037-errors-comptime-run-escape.sx:11:17
|
||||
help: handle it at the `#run` site — `#run <expr> catch e { ... }` or `#run <expr> or <default>`
|
||||
help: handle it at the `#run` site — `#run <expr> catch (e) { ... }` or `#run <expr> or <default>`
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
error: 's64' is a reserved type name and cannot be used as an identifier
|
||||
--> examples/1123-diagnostics-reserved-name-catch-onfail.sx:20:12
|
||||
--> examples/1123-diagnostics-reserved-name-catch-onfail.sx:20:13
|
||||
|
|
||||
20 | onfail s64 { } // onfail tag binding
|
||||
| ^^^
|
||||
20 | onfail (s64) { } // onfail tag binding
|
||||
| ^^^
|
||||
|
||||
error: 'u8' is a reserved type name and cannot be used as an identifier
|
||||
--> examples/1123-diagnostics-reserved-name-catch-onfail.sx:21:19
|
||||
--> examples/1123-diagnostics-reserved-name-catch-onfail.sx:21:20
|
||||
|
|
||||
21 | must(n) catch u8 { return; }; // catch tag binding
|
||||
| ^^
|
||||
21 | must(n) catch (u8) { return; }; // catch tag binding
|
||||
| ^^
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
1
|
||||
@@ -0,0 +1,5 @@
|
||||
error: the catch error binding needs parens: `catch (e) { ... }`
|
||||
--> examples/1157-diagnostics-catch-binding-needs-parens.sx:12:20
|
||||
|
|
||||
12 | v := f() catch e { 0 };
|
||||
| ^
|
||||
@@ -0,0 +1 @@
|
||||
|
||||
Reference in New Issue
Block a user