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).
31 lines
1.3 KiB
Plaintext
31 lines
1.3 KiB
Plaintext
// E6b — own-wins for an ERROR-SET name in a CLOSURE-LITERAL return annotation
|
|
// (`closure(() -> !IoErr { … })`). `main` flat-imports `dep.sx` (which authors
|
|
// `IoErr { Net }`) AND authors its OWN `IoErr { Disk }`. The closure literal's
|
|
// `-> !IoErr` channel must resolve to `main`'s OWN author (own-wins), so the
|
|
// `raise error.Disk` inside the closure body validates against main's `{ Disk }`;
|
|
// meanwhile `dep_err` keeps dep's DISTINCT `IoErr { Net }`.
|
|
//
|
|
// Fail-before (attempt-1): `lowerLambda` resolved the explicit `lam.return_type`
|
|
// through the STATELESS `type_bridge.resolveAstType`, so the closure's `!IoErr`
|
|
// channel bound the global last-wins author (dep's `{ Net }`); `error.Disk` was
|
|
// then "not in error set 'IoErr'" and the program exited 1.
|
|
//
|
|
// Pass-after: the lambda return annotation routes through the source-aware
|
|
// `resolveTypeWithBindings` (same path as the regular function-return channel),
|
|
// main's own `IoErr` wins, `error.Disk` validates, exit 0.
|
|
|
|
#import "modules/std.sx";
|
|
#import "0813-modules-same-name-error-set-lambda-own-wins/dep.sx";
|
|
|
|
IoErr :: error { Disk }
|
|
|
|
main :: () -> s32 {
|
|
fail_own := closure(() -> !IoErr { raise error.Disk; });
|
|
fail_own() catch (e) {
|
|
if e == error.Disk { print("own=Disk\n"); }
|
|
};
|
|
d := dep_err();
|
|
print("dep={}\n", d);
|
|
return 0;
|
|
}
|