feat(lang): universal backtick raw identifier — valid in value, decl, AND type position [F0.6]

AGRA ruling (attempt 4): `` `name `` is THE LITERAL identifier `name`, usable in
EVERY position — the backtick only means "treat this token as a plain identifier,
never the reserved keyword/type", and is never part of the name's text.

- Raw in TYPE position is now VALID (reverses attempt-2 "raw is not a type"):
  `parseTypeExpr` emits a raw `type_expr`; `TypeResolver.resolveNamed` gains a
  `skip_builtin` flag (threaded from `te.is_raw` via lower.zig + type_bridge) so a
  `` `s2 `` reference resolves to a `` `s2 ``-declared type (struct/enum/union/alias),
  else a normal "unknown type 's2'" error (reportIfUnknownType skips the builtin
  exemption when raw). Bare `s2` in type position stays the builtin int.
- Every declaration-name site is is_raw-exemptible: `is_raw` added to TypeExpr +
  StructDecl/EnumDecl/UnionDecl/ErrorSetDecl/ProtocolDecl/ForeignClassDecl/UfcsAlias/
  NamespaceDecl/ImportDecl/CImportDecl/LibraryDecl; parser threads name_is_raw to
  every decl parse fn; namespace imports carry it through imports.addNamespace.
  Typed-const path (`` `s2 : s64 : 5 ``) now threads name_span+is_raw (fixes the
  1:1-caret bug).
- Check<->exemption made structurally symmetric: checkBindingName/checkDeclName take
  is_raw as a REQUIRED argument and skip inside the check, so no call site can
  validate a name without honoring the exemption (the desync cause of prior rounds).
- Bare reserved-name declarations of every kind still error (0076 preserved);
  `#import c` foreign names stay auto-raw + bare-callable.

specs.md + readme.md updated to the universal model. issue 0089 RESOLVED banner
rewritten. Examples: replace 1139 (raw-not-a-type) with 0154 (raw type reference);
add 0155 (typed const + union tag) and 1141 (bare type-decl negatives).
Gate: zig build + zig build test + run_examples (426 passed, 0 failed).
This commit is contained in:
agra
2026-06-04 20:27:53 +03:00
parent c0e1a5db82
commit 023971cae5
26 changed files with 441 additions and 212 deletions

View File

@@ -105,26 +105,31 @@ y : s32 = 0; // explicit type
z : s32 = ---; // uninitialized
```
Builtin type names (`s2`, `u8`, `bool`, `string`, …) are reserved and can't be used
as bare identifiers at **any** binding site — a value binding (`:=` / typed local /
parameter), a `::` constant or function declaration, or a `::` type declaration
(`struct` / `enum` / `union` / alias / `protocol` / …) — each is an error
(`s2 :: 5` and `s2 :: (n) { … }` are rejected just like `s2 := 5`). A leading
backtick at the binding site escapes one into a raw identifier its text drops the
backtick and it's never read as a type — so reserved spellings (and keywords) work
as ordinary names. The backtick is needed only where the name is declared; a later
bare reference in value position resolves to the binding, while a bare `s2` in type
position is still the type. It works in every identifier position (local, global,
parameter, field, function name, constant, and the control-flow / capture / binding
forms — destructure, `if`/`while` binding, `for` capture, match capture,
`catch`/`onfail` tag), and a reserved-spelled function is bare-callable:
Builtin type names (`s2`, `u8`, `bool`, `string`, …) are reserved and a *bare*
spelling can't be used as an identifier at **any** binding site — a value binding
(`:=` / typed local / parameter), a `::` constant or function declaration, or a
`::` type declaration (`struct` / `enum` / `union` / alias / `protocol` / …) — each
is an error (`s2 :: 5` and `s2 :: (n) { … }` are rejected just like `s2 := 5`). A
leading backtick escapes one into a **raw identifier**: `` `name `` is the literal
identifier `name` (the backtick drops out of the text), usable in **every**
position — value, declaration, and type. It is the only way handwritten sx can
spell a reserved name.
```sx
`s2 := 2.5; // value identifier "s2", distinct from the s2 type
print("{}\n", `s2); // 2.5 (or bare `s2`)
`s2 := 2.5; // identifier "s2", distinct from the s2 type
print("{}\n", `s2); // 2.5 (or bare `s2` in value position)
`s2 :: struct { x: s64; } // declare a type named with a reserved spelling
v : `s2 = ---; // and reference it as a type — resolves to the struct
x : s2 = 3; // bare `s2` in type position is still the int type
```
A raw identifier is a value name, never a type — `x : `s2 = 1` is an error.
It works in every identifier position — local, global, parameter, struct field,
union tag, function name, type/alias/import name, constant, and the control-flow /
capture / binding forms (destructure, `if`/`while` binding, `for` capture, match
capture, `catch`/`onfail` tag) — and a reserved-spelled function is bare-callable
(`s2(10)`). A backtick name used as a type resolves to a `` `name ``-declared type,
else a normal `unknown type` error.
Foreign declarations from `#import c { … }` are exempt automatically: C names that
collide with reserved type names (e.g. `s1`, `s2`) import unedited, and a foreign