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).
34 lines
891 B
Plaintext
34 lines
891 B
Plaintext
// Comptime return-trace resolution (ERR E3.0 slice 3b). A `#run` block that
|
|
// raises, propagates via `try`, and catches the error, then formats the trace
|
|
// with `trace.print_current()`. At comptime a frame is a packed
|
|
// `(func_id, span.start)` (not a `*Frame`); the interpreter's `.trace_resolve`
|
|
// unpacks it and resolves `file:line:col` via the module + source map — so the
|
|
// comptime trace prints the same `func at file:line:col` form as a runtime one.
|
|
// Expected exit: 0 (the error is caught; the trace is printed during the build).
|
|
|
|
#import "modules/std.sx";
|
|
trace :: #import "modules/trace.sx";
|
|
|
|
TErr :: error { Bad };
|
|
|
|
leaf :: () -> !TErr {
|
|
raise error.Bad;
|
|
}
|
|
|
|
mid :: () -> !TErr {
|
|
try leaf();
|
|
}
|
|
|
|
probe :: () {
|
|
mid() catch (e) {
|
|
print("comptime caught {}\n", e);
|
|
trace.print_current();
|
|
};
|
|
}
|
|
|
|
#run probe();
|
|
|
|
main :: () -> s32 {
|
|
return 0;
|
|
}
|