Files
sx/examples/1054-errors-backtick-reserved-binding.sx
agra 640f59dc54 feat(lang): backtick raw identifier in every binding form + raw-not-a-type + foreign reserved-name fn bare-call [F0.6]
Completes the issue-0089 backtick raw-identifier / `#import c` exemption
across all remaining identifier positions and closes three boundary gaps
the F0.6 review found.

1. Exhaustive raw-binding coverage. The `is_raw` bit now threads through
   `ast.Identifier` and EVERY binding/capture form — `IfExpr`/`WhileExpr`
   optional bindings, `ForExpr` capture + index, `MatchArm` capture,
   `CatchExpr`/`OnFailStmt` tag bindings, `DestructureDecl` per-name, and
   the protocol-default-body / foreign-class method param lists — not just
   `var_decl`/`param`. `UnknownTypeChecker` skips the reserved-name check at
   each arm when raw, so a backtick works in every identifier position while
   a bare reserved spelling still errors (issue 0076 preserved).

2. Raw identifier is never a type. `parseTypeExpr`'s atom rejects a raw
   identifier in type position (`x : `s2 = 1`, `List(`s2)`) with an accurate
   diagnostic instead of silently type-classifying it.

3. Reserved-name function bare-callable. A bare `s2(4)` parses its callee as
   a `.type_expr` (reserved spelling); `lowerCall` now rewrites a type_expr
   callee to an identifier when a function of that name is in scope, so a
   backtick-declared sx fn and a `#import c` foreign fn whose C name collides
   with a reserved type spelling both resolve by their bare name.
   (`TypeName(val)` is not a cast, so there is no ambiguity.)

Tests: examples/0152 (every control-flow/capture form + bare ref/call/member
access), examples/1054 (catch/onfail tag bindings), examples/1139 (raw in
type position rejected), examples/1220 extended (foreign reserved-name
function bare-call). 0076 negatives 1119/1121/1122/1123/1124/1125 stay green.
Gate: zig build + zig build test + 422 examples pass. specs.md + readme.md
updated; issues/0089 RESOLVED banner refreshed.
2026-06-04 18:31:08 +03:00

41 lines
1.3 KiB
Plaintext

// Backtick raw identifier as the error-tag binding of `catch` and `onfail`. A
// reserved type-name spelling (`s2`, `u8`) is a value name when backticked, so
// it is accepted as the tag binding and a later reference resolves to it. A
// *bare* reserved spelling in the same position is still rejected (see
// examples/1123), so the backtick escape is the only way to spell these tags.
// Regression (issue 0089 — attempt-2 catch/onfail coverage).
#import "modules/std.sx";
E :: error { Bad, Empty }
parse :: (n: s32) -> (s32, !E) {
if n < 0 { raise error.Bad; }
if n == 0 { raise error.Empty; }
return n * 2;
}
// `catch` tag binding spelled `s2`, referenced in the match body.
classify :: (n: s32) -> s32 {
return parse(n) catch `s2 == {
case .Bad: 1;
case .Empty: 2;
else: 3
};
}
// `onfail` tag binding spelled `u8`, referenced in the cleanup body.
cleanup :: (n: s32) -> !E {
onfail `u8 { if `u8 == error.Bad { print("cleanup: bad\n"); } }
if n < 0 { raise error.Bad; }
return;
}
main :: () -> s32 {
print("classify(-1) = {}\n", classify(-1));
print("classify(0) = {}\n", classify(0));
print("classify(5) = {}\n", classify(5));
c := cleanup(-1);
print("done\n");
return 0;
}