fix(lower): source-aware initial scan registration for identifier-RHS aliases [stdlib E1.5 attempt-2]
E1.5 attempt-1 made the forward-alias FIXPOINT source-aware but left the
EARLIER path — the `scanDecls` identifier-RHS alias branch — resolving the
RHS through the GLOBAL `type_alias_map` / global `findByName` (last-wins
across modules). When a namespaced import is scanned BEFORE a forward alias
`A :: B; B :: u64;`, dep's same-name `B :: u8` already sits in the global map,
so the early scan bound `A` to dep's `u8` and the per-source fixpoint guard
(`aliasResolvedInSource`) then skipped `A` — re-opening 0105 one layer down
(reviewer R1).
Cut the scan registration over to `selectNominalLeaf(rhs, src, is_raw)`,
resolving `B` AS SEEN FROM the alias's OWN source. Only the `.resolved`
outcome is written via the unified `putTypeAlias`; `.pending` / `.undeclared`
/ `.not_visible` leave `A` UNWRITTEN so the source-aware fixpoint re-tries it
once the local `B` registers. No raw `type_alias_map.put` / global `findByName`
selection reintroduced (E1 no-drift invariant). resolver.zig untouched
(single graph-walk invariant).
Also thread the backtick raw flag (`identifier.is_raw`) into BOTH the scan
registration and the fixpoint `selectNominalLeaf` calls, so a raw-RHS alias
(`` RawAlias :: `s2 ``) resolves to the nominal `` `s2 `` author, not the
builtin `s2` spelling (fixes 0154 under the new scan path; closes the same
latent hardcode in the fixpoint).
Regression: examples/0751-modules-forward-alias-ns-before — the reviewer's
exact ordering (ns import with `B :: u8` BEFORE `A :: B; B :: u64;`). Fails
on 2d34993 (`forward A` = 44, dep's u8) and passes after (= 300, local u64).
0750 + 0132/0133 + the full suite stay byte-identical (488/0).
This commit is contained in:
@@ -934,18 +934,26 @@ pub const Lowering = struct {
|
||||
}
|
||||
self.putTypeAlias(self.current_source_file, cd.name, target_ty);
|
||||
} else if (cd.value.data == .identifier) {
|
||||
// Identifier-RHS alias: MyAlias :: MyInt; WideAlias :: Wide;
|
||||
// Chase through type_alias_map, then look up named types
|
||||
// in the table. Forward references resolve lazily because
|
||||
// the .identifier branch of resolveTypeArg also consults
|
||||
// type_alias_map at use time.
|
||||
const rhs_name = cd.value.data.identifier.name;
|
||||
if (self.program_index.type_alias_map.get(rhs_name)) |chained| {
|
||||
self.putTypeAlias(self.current_source_file, cd.name, chained);
|
||||
} else {
|
||||
const name_id = self.module.types.internString(rhs_name);
|
||||
if (self.module.types.findByName(name_id)) |tid| {
|
||||
self.putTypeAlias(self.current_source_file, cd.name, tid);
|
||||
// Identifier-RHS alias: MyAlias :: MyInt; WideAlias :: Wide.
|
||||
// SOURCE-AWARE (E1.5). Resolve the RHS `B` AS SEEN FROM this
|
||||
// alias's OWN source via `selectNominalLeaf` (E1's source-
|
||||
// keyed nominal leaf), NEVER the global `type_alias_map` /
|
||||
// global `findByName` (last-wins across modules). Only the
|
||||
// `.resolved` outcome is written; `.pending` (B is itself a
|
||||
// forward alias not resolved yet), `.undeclared`, and
|
||||
// `.not_visible` (a same-name B authored only by a namespaced
|
||||
// import) leave A UNWRITTEN so the source-aware
|
||||
// `resolveForwardIdentifierAliases` fixpoint re-tries A once
|
||||
// the local B registers. A GLOBAL selection here would bind A
|
||||
// to a namespaced same-name B, and the per-source fixpoint
|
||||
// guard (`aliasResolvedInSource`) would then SKIP A — leaving
|
||||
// the wrong global TypeId and re-opening 0105 one layer down
|
||||
// (R1, E1.5). Same unified `putTypeAlias` writer (no-drift).
|
||||
const rhs = cd.value.data.identifier;
|
||||
if (self.current_source_file orelse self.main_file) |from| {
|
||||
switch (self.selectNominalLeaf(rhs.name, from, rhs.is_raw)) {
|
||||
.resolved => |tid| self.putTypeAlias(self.current_source_file, cd.name, tid),
|
||||
.pending, .undeclared, .not_visible => {},
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1396,8 +1404,11 @@ pub const Lowering = struct {
|
||||
if (cd.value.data != .identifier) continue;
|
||||
const src = decl.source_file orelse self.main_file orelse continue;
|
||||
if (self.aliasResolvedInSource(src, cd.name)) continue;
|
||||
const rhs_name = cd.value.data.identifier.name;
|
||||
switch (self.selectNominalLeaf(rhs_name, src, false)) {
|
||||
const rhs = cd.value.data.identifier;
|
||||
// Pass the backtick raw flag so a forward alias whose RHS is a raw
|
||||
// identifier (`` RawAlias :: `s2 ``, target declared later) resolves
|
||||
// to the nominal `` `s2 `` author, not the builtin `s2` spelling.
|
||||
switch (self.selectNominalLeaf(rhs.name, src, rhs.is_raw)) {
|
||||
.resolved => |tid| {
|
||||
self.putTypeAlias(decl.source_file, cd.name, tid);
|
||||
progressed = true;
|
||||
|
||||
Reference in New Issue
Block a user