fix: give error-set decls per-decl nominal identity (issue 0134)

A local 'error { ... }' set with the same name as an imported one collapsed
onto the import, losing its own tags, because registerErrorSetDecl deduped via
the flat findByName path while struct/enum/union use E6a per-decl identity.
Build the .error_set TypeInfo (new buildErrorSetInfo helper factored from
resolveInlineErrorSet) and intern via internNamedTypeDecl with shadowNominalId;
reserve a distinct shadow slot in scanDecls; consult per-decl type_decl_tids in
namedRefTid before findByName. The inline/anonymous findByName short-circuit is
preserved.

Regression: examples/1059-errors-same-name-error-set-own-wins.sx (moved from
issues/0134).
This commit is contained in:
agra
2026-06-21 09:11:06 +03:00
parent ad45ae07ef
commit 333f57026c
8 changed files with 81 additions and 4 deletions

View File

@@ -1939,7 +1939,13 @@ pub fn namedRefTid(self: *Lowering, ref: resolver_mod.RawDeclRef, name: []const
.struct_decl => |d| (table.type_decl_tids.get(@ptrCast(d)) orelse table.findByName(table.internString(name))),
.enum_decl => |d| (table.type_decl_tids.get(@ptrCast(d)) orelse table.findByName(table.internString(name))),
.union_decl => |d| (table.type_decl_tids.get(@ptrCast(d)) orelse table.findByName(table.internString(name))),
.error_set_decl, .protocol_decl, .runtime_class_decl => table.findByName(table.internString(name)),
// Error sets now carry per-decl nominal identity (issue 0134), so prefer
// the own author's reserved TypeId over the name-keyed first-author
// `findByName` — mirroring the struct/enum/union arms above. A set that
// was not decl-registered (no `type_decl_tids` entry) falls back to the
// name lookup, byte-identical to pre-0134.
.error_set_decl => |d| (table.type_decl_tids.get(@ptrCast(d)) orelse table.findByName(table.internString(name))),
.protocol_decl, .runtime_class_decl => table.findByName(table.internString(name)),
.fn_decl, .const_decl, .var_decl, .namespace_decl => null,
};
}