Files
sx/examples/1123-diagnostics-reserved-name-catch-onfail.sx
agra fcc76b9391 fix(diagnostics): make reserved-type-name binding check exhaustive (issue 0076)
The reserved/builtin-type-name binding diagnostic was a hand-walked subset
of binding-bearing AST nodes with a silent `else => {}`, so each review
found another syntactic binding form that bypassed it and hit the original
LLVM verifier abort: destructure names (`s2, x := …`), `impl` method
params/locals, and `if` / `while` / `for` / match-arm / `catch` / `onfail`
captures.

Rewrite `checkBindingNames` (src/ir/semantic_diagnostics.zig) as an
EXHAUSTIVE `switch` over every `Node.Data` tag with NO `else` arm — a future
binding-bearing node type now fails to compile until it is handled here, so
coverage is enforced by the compiler instead of a hand-maintained list. The
check stays in the pre-lowering semantic pass rather than moving to the
`Scope.put` scope-registration choke point: lowering is lazy, so an
uncalled function's bindings never reach `Scope.put`, yet they must still be
rejected at their declaration (e.g. the never-called `takes_u8` in 1119).
No lowering special-case; `lower.zig` unchanged.

Regression tests (fail-before: LLVM abort or silent accept → pass-after:
clean diagnostic, exit 1):
- 1121 control-flow: destructure, if/while bindings, for capture+index,
  match-arm capture
- 1122 impl-block method: reserved param AND reserved local
- 1123 catch + onfail tag bindings
- 1124 destructure name reserved in an imported module
Existing 0125 / 1119 / 0135 / 1120 tests kept; full suite 368 passed.
2026-06-03 20:09:46 +03:00

29 lines
864 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;
}