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).
29 lines
868 B
Plaintext
29 lines
868 B
Plaintext
// A reserved/builtin type name is rejected as the error-tag binding of a
|
|
// `catch` (`u8`) and of an `onfail` (`s64`). Both are reached through the
|
|
// exhaustive binding-name walk's `catch_expr` / `onfail_stmt` arms. The tag is
|
|
// a scalar, so before the diagnostic these spellings were silently accepted
|
|
// (they never reached the address-of mis-lowering) — the binding must still be
|
|
// rejected at its declaration.
|
|
//
|
|
// Regression (issue 0076, attempt-4 coverage). Expected: one error for each
|
|
// binding; exit 1.
|
|
#import "modules/std.sx";
|
|
|
|
E :: error { Bad }
|
|
|
|
must :: (n: s32) -> !E {
|
|
if n < 0 { raise error.Bad; }
|
|
return;
|
|
}
|
|
|
|
classify :: (n: s32) -> !E {
|
|
onfail (s64) { } // onfail tag binding
|
|
must(n) catch (u8) { return; }; // catch tag binding
|
|
return;
|
|
}
|
|
|
|
main :: () -> s32 {
|
|
classify(-1) catch { };
|
|
return 0;
|
|
}
|