feat(lang): universal raw identifier — parser exhaustiveness + raw type continuations + sema/LSP [F0.6]
Closes the remaining three F0.6 findings so the universal backtick raw identifier holds in BOTH classifiers and at EVERY parser construction site. 1. Struct-body constants thread is_raw + name_span. The struct-body const forms (untyped `` `s2 :: 5 `` and typed `` `s2 : T : v ``) built the const_decl node without name_span/is_raw, so a backtick const was falsely rejected and a bare reserved-name const caretted at 1:1. They now capture both. Structural cure: `ast.ConstDecl`'s name_span + is_raw carry NO default, so the compiler rejects any construction site that omits them (mirrors checkBindingName's required `is_raw` arg). FnDecl keeps its defaults — every parser fn_decl routes through parseFnDecl whose `name_is_raw` is a required parameter (equivalent guarantee). 2. Raw identifier in TYPE position flows through the normal continuations. parseTypeExpr no longer returns a terminal type_expr for a raw atom; the raw flag rides the atom through the qualified-path / Closure / parameterized continuations, so `` `s2(s64) ``, `` *`s2 ``, `` ?`s2 `` all parse. ParameterizedTypeExpr carries is_raw; resolveParameterizedWithBindings skips the `Vector` intrinsic when raw. 3. sema/LSP (the second classifier) honors is_raw. Type.fromTypeExpr returns null for a raw type_expr; resolveTypeNode skips the builtin classifier when raw; resolveTypeNameStr takes a skip_builtin arg threaded from te/id.is_raw (compound inner names pass false). A backtick reserved-name annotation now resolves to the user type in the editor index, not the builtin. Tests: examples/0156 (struct-body const), 0157 (parameterized raw type + wrappers), 1142 (bare struct-body const errors, caret on name); src/sema.test.zig pins the LSP raw-type resolution (fail-before verified). Gate: 365 unit tests, 429 examples, 0 failed.
This commit is contained in:
21
examples/0156-types-backtick-struct-const.sx
Normal file
21
examples/0156-types-backtick-struct-const.sx
Normal file
@@ -0,0 +1,21 @@
|
||||
// Backtick raw-identifier escape at a STRUCT-BODY constant — both the untyped
|
||||
// `` `name :: value `` and the typed `` `name : T : value `` forms. A struct
|
||||
// member constant is a binding site like any top-level const (examples/0153),
|
||||
// so a reserved type spelling (`s2`, `u8`) needs the backtick to be used as the
|
||||
// constant's name; the value is read back via `Holder.`name`. A *bare*
|
||||
// reserved-name struct const still errors with the caret on the name (see
|
||||
// examples/1142). The backtick is never part of the name's text.
|
||||
// Regression (issue 0089 — attempt-5: struct-body const decls thread is_raw +
|
||||
// the precise name_span, previously dropped to a false reject / 1:1 caret).
|
||||
#import "modules/std.sx";
|
||||
|
||||
Holder :: struct {
|
||||
`s2 :: 5; // untyped raw struct-body const
|
||||
`u8 : s64 : 9; // typed raw struct-body const
|
||||
}
|
||||
|
||||
main :: () -> s32 {
|
||||
print("untyped = {}\n", Holder.`s2);
|
||||
print("typed = {}\n", Holder.`u8);
|
||||
return 0;
|
||||
}
|
||||
30
examples/0157-types-backtick-parameterized-raw-type.sx
Normal file
30
examples/0157-types-backtick-parameterized-raw-type.sx
Normal file
@@ -0,0 +1,30 @@
|
||||
// Backtick raw identifier in PARAMETERIZED type position. A raw type reference
|
||||
// (`` `s2 ``) flows through the SAME type-expression continuations as a bare
|
||||
// name, so a reserved-spelled GENERIC template can be instantiated
|
||||
// (`` `s2(s64) ``) and the result composes under pointer/field wrappers
|
||||
// (`` *`s2(s64) ``, a struct field typed `` `s2(s64) ``). A bare `s2` in type
|
||||
// position is still the 2-bit signed int. Complements examples/0154 (nullary
|
||||
// raw type references).
|
||||
// Regression (issue 0089 — attempt-5: the raw type atom no longer parses as a
|
||||
// terminal `type_expr`; it reaches the parameterized + wrapper continuations).
|
||||
#import "modules/std.sx";
|
||||
|
||||
`s2 :: struct($T: Type) {
|
||||
x: $T;
|
||||
}
|
||||
|
||||
Wrapper :: struct {
|
||||
inner: `s2(s64); // raw parameterized type as a struct field
|
||||
}
|
||||
|
||||
main :: () -> s32 {
|
||||
v : `s2(s64);
|
||||
v.x = 7;
|
||||
p : *`s2(s64) = @v; // pointer to a raw parameterized type
|
||||
w : Wrapper = ---;
|
||||
w.inner.x = 12;
|
||||
print("val = {}\n", v.x);
|
||||
print("ptr = {}\n", p.x);
|
||||
print("fld = {}\n", w.inner.x);
|
||||
return 0;
|
||||
}
|
||||
20
examples/1142-diagnostics-reserved-name-struct-const.sx
Normal file
20
examples/1142-diagnostics-reserved-name-struct-const.sx
Normal file
@@ -0,0 +1,20 @@
|
||||
// A bare reserved/builtin type-name spelling is rejected as the NAME of a
|
||||
// STRUCT-BODY constant too — both the untyped (`s2 :: 5`) and the typed
|
||||
// (`u8 : s64 : 9`) forms — exactly like a top-level const (examples/1140) or a
|
||||
// type decl (examples/1141). A struct member constant is a binding site, so a
|
||||
// bare reserved spelling mis-classifies and is rejected; the caret lands ON the
|
||||
// constant's name (not at 1:1). The backtick escape (examples/0156) is the only
|
||||
// way to spell these names in handwritten sx.
|
||||
//
|
||||
// Regression (issue 0089 — attempt-5: 0076 holds for struct-body consts, with
|
||||
// the caret on the name). Expected: one error per const, caret on the name; exit 1.
|
||||
#import "modules/std.sx";
|
||||
|
||||
Holder :: struct {
|
||||
s2 :: 5;
|
||||
u8 : s64 : 9;
|
||||
}
|
||||
|
||||
main :: () -> s32 {
|
||||
return 0;
|
||||
}
|
||||
1
examples/expected/0156-types-backtick-struct-const.exit
Normal file
1
examples/expected/0156-types-backtick-struct-const.exit
Normal file
@@ -0,0 +1 @@
|
||||
0
|
||||
@@ -0,0 +1 @@
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
untyped = 5
|
||||
typed = 9
|
||||
@@ -0,0 +1 @@
|
||||
0
|
||||
@@ -0,0 +1 @@
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
val = 7
|
||||
ptr = 7
|
||||
fld = 12
|
||||
@@ -0,0 +1 @@
|
||||
1
|
||||
@@ -0,0 +1,11 @@
|
||||
error: 's2' is a reserved type name and cannot be used as an identifier
|
||||
--> examples/1142-diagnostics-reserved-name-struct-const.sx:14:5
|
||||
|
|
||||
14 | s2 :: 5;
|
||||
| ^^
|
||||
|
||||
error: 'u8' is a reserved type name and cannot be used as an identifier
|
||||
--> examples/1142-diagnostics-reserved-name-struct-const.sx:15:5
|
||||
|
|
||||
15 | u8 : s64 : 9;
|
||||
| ^^
|
||||
@@ -0,0 +1 @@
|
||||
|
||||
Reference in New Issue
Block a user