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:
@@ -354,6 +354,7 @@ pub const ResolvedModule = struct {
|
||||
name: []const u8,
|
||||
other: ResolvedModule,
|
||||
span: ast.Span,
|
||||
is_raw: bool,
|
||||
) !void {
|
||||
const ns_node = try allocator.create(Node);
|
||||
ns_node.* = .{
|
||||
@@ -361,6 +362,10 @@ pub const ResolvedModule = struct {
|
||||
.data = .{ .namespace_decl = .{
|
||||
.name = name,
|
||||
.decls = other.decls,
|
||||
// Carry the backtick raw escape from the `name :: #import …`
|
||||
// form so a reserved-name namespace is exempt from the decl
|
||||
// check, symmetric to every other decl site (issue 0089).
|
||||
.is_raw = is_raw,
|
||||
} },
|
||||
};
|
||||
try self.scope.put(name, {});
|
||||
@@ -487,6 +492,7 @@ pub fn resolveImports(
|
||||
.data = .{ .namespace_decl = .{
|
||||
.name = ns_name,
|
||||
.decls = try ns_decls.toOwnedSlice(allocator),
|
||||
.is_raw = ci.is_raw,
|
||||
} },
|
||||
};
|
||||
ns_node.source_file = file_path;
|
||||
@@ -569,7 +575,7 @@ pub fn resolveImports(
|
||||
};
|
||||
|
||||
if (imp.name) |ns_name| {
|
||||
try mod.addNamespace(allocator, &decl_list, &own_decl_list, &seen_in_list, ns_name, imported_mod, decl.span);
|
||||
try mod.addNamespace(allocator, &decl_list, &own_decl_list, &seen_in_list, ns_name, imported_mod, decl.span, imp.is_raw);
|
||||
} else {
|
||||
try mod.mergeFlat(allocator, &decl_list, &seen_in_list, &seen_nodes, imported_mod);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user