fix(diagnostics): point reserved-type-name binding errors at the binding (issue 0076)
The reserved-type-name binding diagnostic fired correctly but underlined the enclosing statement / if / while / for / match / protocol / #objc_class block because every binding-name check reused the parent `node.span`. Thread each binding name's own span through the AST and parser, and pass it to `checkBindingNames`: - ast: add name spans to VarDecl, DestructureDecl, If/WhileExpr, ForExpr (capture + index), MatchArm, Catch/OnFailStmt, Protocol/ForeignMethodDecl. - parser: populate each span at the binding site from the name token's loc; destructure reuses each target identifier's own span. - semantic_diagnostics: every checkBindingName call now passes the binding's own span — no site falls back to node.span. fn/lambda params already used Param.name_span. Carets now land on the offending identifier itself. New regression examples/1125 asserts the protocol default-body and sx-defined #objc_class method param spans; 0125/1119-1124 expected updated to the precise carets.
This commit is contained in:
30
examples/1125-diagnostics-reserved-name-method-param.sx
Normal file
30
examples/1125-diagnostics-reserved-name-method-param.sx
Normal file
@@ -0,0 +1,30 @@
|
||||
// A reserved/builtin type name used as a PARAMETER name is rejected inside the
|
||||
// two method-with-body forms that carry their params as bare name lists rather
|
||||
// than `Param` nodes: a protocol default-body method (`u8`) and a sx-defined
|
||||
// foreign-class (`#objc_class`) method (`s16`). The declaration-site diagnostic
|
||||
// underlines the OFFENDING PARAMETER itself, not the enclosing `protocol` /
|
||||
// `#objc_class` block — each method's `param_name_spans` is threaded from the
|
||||
// parser so the caret lands on the parameter token.
|
||||
//
|
||||
// Regression (issue 0076, attempt-5 span precision). Expected: one error per
|
||||
// offending parameter, each caret on the parameter name; exit 1.
|
||||
#import "modules/std.sx";
|
||||
#import "modules/compiler.sx";
|
||||
|
||||
Greeter :: protocol {
|
||||
greet :: (self: *Self, u8: s64) -> s64 {
|
||||
return u8;
|
||||
}
|
||||
}
|
||||
|
||||
SxFoo :: #objc_class("SxFoo") {
|
||||
counter: s32;
|
||||
|
||||
bump :: (self: *Self, s16: s32) {
|
||||
self.counter += s16;
|
||||
}
|
||||
}
|
||||
|
||||
main :: () -> s32 {
|
||||
return 0;
|
||||
}
|
||||
@@ -2,4 +2,4 @@ error: 's2' is a reserved type name and cannot be used as an identifier
|
||||
--> /Users/agra/projects/sx/examples/0125-types-type-named-var-rejected.sx:10:5
|
||||
|
|
||||
10 | s2 := 42;
|
||||
| ^^^^^^^^^
|
||||
| ^^
|
||||
|
||||
@@ -8,16 +8,16 @@ error: 's64' is a reserved type name and cannot be used as an identifier
|
||||
--> /Users/agra/projects/sx/examples/1119-diagnostics-reserved-type-name-as-identifier.sx:12:5
|
||||
|
|
||||
12 | s64 : s32 = 3;
|
||||
| ^^^^^^^^^^^^^^
|
||||
| ^^^
|
||||
|
||||
error: 'bool' is a reserved type name and cannot be used as an identifier
|
||||
--> /Users/agra/projects/sx/examples/1119-diagnostics-reserved-type-name-as-identifier.sx:13:5
|
||||
|
|
||||
13 | bool : bool = true;
|
||||
| ^^^^^^^^^^^^^^^^^^^
|
||||
| ^^^^
|
||||
|
||||
error: 'string' is a reserved type name and cannot be used as an identifier
|
||||
--> /Users/agra/projects/sx/examples/1119-diagnostics-reserved-type-name-as-identifier.sx:14:5
|
||||
|
|
||||
14 | string := "x";
|
||||
| ^^^^^^^^^^^^^^
|
||||
| ^^^^^^
|
||||
|
||||
@@ -2,4 +2,4 @@ error: 's2' is a reserved type name and cannot be used as an identifier
|
||||
--> examples/1120-diagnostics-imported-reserved-type-name/mod.sx:11:5
|
||||
|
|
||||
11 | s2 := Box.{ total = 0, count = 0 };
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
| ^^
|
||||
|
||||
@@ -2,40 +2,34 @@ error: 's2' is a reserved type name and cannot be used as an identifier
|
||||
--> examples/1121-diagnostics-reserved-name-control-flow.sx:18:5
|
||||
|
|
||||
18 | s2, rest := pair(); // destructure name
|
||||
| ^^^^^^^^^^^^^^^^^^^
|
||||
| ^^
|
||||
|
||||
error: 'u8' is a reserved type name and cannot be used as an identifier
|
||||
--> examples/1121-diagnostics-reserved-name-control-flow.sx:19:5
|
||||
--> examples/1121-diagnostics-reserved-name-control-flow.sx:19:8
|
||||
|
|
||||
19 | if u8 := maybe() { } // if optional binding
|
||||
| ^^^^^^^^^^^^^^^^^^^^
|
||||
| ^^
|
||||
|
||||
error: 's16' is a reserved type name and cannot be used as an identifier
|
||||
--> examples/1121-diagnostics-reserved-name-control-flow.sx:20:5
|
||||
--> examples/1121-diagnostics-reserved-name-control-flow.sx:20:11
|
||||
|
|
||||
20 | while s16 := maybe() { break; } // while optional binding
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
| ^^^
|
||||
|
||||
error: 'bool' is a reserved type name and cannot be used as an identifier
|
||||
--> examples/1121-diagnostics-reserved-name-control-flow.sx:22:5
|
||||
--> examples/1121-diagnostics-reserved-name-control-flow.sx:22:14
|
||||
|
|
||||
22 | for xs: (bool) { } // for capture name
|
||||
| ^^^^^^^^^^^^^^^^^^
|
||||
| ^^^^
|
||||
|
||||
error: 's32' is a reserved type name and cannot be used as an identifier
|
||||
--> examples/1121-diagnostics-reserved-name-control-flow.sx:23:5
|
||||
--> examples/1121-diagnostics-reserved-name-control-flow.sx:23:17
|
||||
|
|
||||
23 | for xs: (v, s32) { } // for index name
|
||||
| ^^^^^^^^^^^^^^^^^^^^
|
||||
| ^^^
|
||||
|
||||
error: 'string' is a reserved type name and cannot be used as an identifier
|
||||
--> examples/1121-diagnostics-reserved-name-control-flow.sx:25:10
|
||||
--> examples/1121-diagnostics-reserved-name-control-flow.sx:26:22
|
||||
|
|
||||
25 | r := if opt == { // match-arm capture
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
26 | case .some: (string) { 0 }
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
27 | case .none: { 0 }
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
28 | };
|
||||
| ^^^^^
|
||||
| ^^^^^^
|
||||
|
||||
@@ -8,4 +8,4 @@ error: 's2' is a reserved type name and cannot be used as an identifier
|
||||
--> examples/1122-diagnostics-reserved-name-impl-method.sx:20:9
|
||||
|
|
||||
20 | s2 := Box.{ total = 1 };
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
| ^^
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
error: 's64' is a reserved type name and cannot be used as an identifier
|
||||
--> examples/1123-diagnostics-reserved-name-catch-onfail.sx:20:5
|
||||
--> examples/1123-diagnostics-reserved-name-catch-onfail.sx:20:12
|
||||
|
|
||||
20 | onfail s64 { } // onfail tag binding
|
||||
| ^^^^^^^^^^^^^^
|
||||
| ^^^
|
||||
|
||||
error: 'u8' is a reserved type name and cannot be used as an identifier
|
||||
--> examples/1123-diagnostics-reserved-name-catch-onfail.sx:21:5
|
||||
--> examples/1123-diagnostics-reserved-name-catch-onfail.sx:21:19
|
||||
|
|
||||
21 | must(n) catch u8 { return; }; // catch tag binding
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
| ^^
|
||||
|
||||
@@ -2,4 +2,4 @@ error: 's2' is a reserved type name and cannot be used as an identifier
|
||||
--> examples/1124-diagnostics-imported-reserved-destructure/mod.sx:6:5
|
||||
|
|
||||
6 | s2, rest := pair(); // destructure name in an IMPORTED module
|
||||
| ^^^^^^^^^^^^^^^^^^^
|
||||
| ^^
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
1
|
||||
@@ -0,0 +1,11 @@
|
||||
error: 'u8' is a reserved type name and cannot be used as an identifier
|
||||
--> examples/1125-diagnostics-reserved-name-method-param.sx:15:28
|
||||
|
|
||||
15 | greet :: (self: *Self, u8: s64) -> s64 {
|
||||
| ^^
|
||||
|
||||
error: 's16' is a reserved type name and cannot be used as an identifier
|
||||
--> examples/1125-diagnostics-reserved-name-method-param.sx:23:27
|
||||
|
|
||||
23 | bump :: (self: *Self, s16: s32) {
|
||||
| ^^^
|
||||
@@ -0,0 +1 @@
|
||||
|
||||
Reference in New Issue
Block a user