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).
30 lines
1.0 KiB
Plaintext
30 lines
1.0 KiB
Plaintext
// Error-tag `{}` interpolation (ERR step E3 — tag-name table). Formatting an
|
|
// error-set value with `{}` renders the tag NAME (`BadDigit`), not the raw id,
|
|
// reusing the `any_to_string` dispatch (new `error_set` category → the
|
|
// `error_tag_name` builtin → the always-linked tag-name table indexed by global
|
|
// tag id). Works for a bound tag, a re-raised/caught tag, and inside text.
|
|
|
|
#import "modules/std.sx";
|
|
|
|
E :: error { BadDigit, Empty, Overflow }
|
|
|
|
parse :: (n: s32) -> (s32, !E) {
|
|
if n < 0 { raise error.BadDigit; }
|
|
if n == 0 { raise error.Empty; }
|
|
return n * 2;
|
|
}
|
|
|
|
main :: () -> s32 {
|
|
a : E = error.BadDigit;
|
|
b : E = error.Overflow;
|
|
print("a={} b={}\n", a, b); // a=BadDigit b=Overflow
|
|
|
|
// A tag bound by `catch` interpolates too (diverging handler).
|
|
v := parse(0) catch (e) {
|
|
print("parse failed with {}\n", e); // parse failed with Empty
|
|
return 0;
|
|
};
|
|
print("v={}\n", v); // not reached (parse(0) raises Empty)
|
|
return 0;
|
|
}
|