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).
37 lines
1.6 KiB
Plaintext
37 lines
1.6 KiB
Plaintext
// Source-aware forward-alias fixpoint — the INITIAL scan registration (E1.5).
|
|
// Sibling of 0750, but the namespaced import is placed BEFORE the forward alias:
|
|
//
|
|
// ns :: #import ".../dep.sx"; // authors a same-name `B :: u8`
|
|
// A :: B; // forward alias
|
|
// B :: u64; // its LOCAL target, declared later
|
|
//
|
|
// Because `ns` is scanned first, dep's `B :: u8` is already in the global
|
|
// `type_alias_map` when `A :: B` is scanned. The pre-E1.5-attempt-2 `scanDecls`
|
|
// identifier-RHS branch resolved the RHS through that GLOBAL map and bound `A` to
|
|
// dep's `u8` right there; the per-source fixpoint guard then saw `A` already
|
|
// resolved and skipped it, so the source-aware leaf never corrected it (`A` came
|
|
// out `u8`, truncating 300 -> 44). The source-aware scan registration resolves
|
|
// `B` AS SEEN FROM main's source: dep's `B` is namespaced-only (not bare-visible)
|
|
// and main's `B` is not registered yet, so `A` is left UNWRITTEN and the fixpoint
|
|
// binds it to the local `B :: u64` once that registers.
|
|
//
|
|
// Observable: a runtime 300 coerced into an `A`-typed slot round-trips as 300
|
|
// when `A` is `u64` (correct) and truncates to 44 when `A` is wrongly `u8`.
|
|
// Regression (stdlib E1.5).
|
|
#import "modules/std.sx";
|
|
|
|
ns :: #import "0751-modules-forward-alias-ns-before/dep.sx";
|
|
|
|
A :: B;
|
|
B :: u64;
|
|
|
|
main :: () -> s32 {
|
|
n : s64 = 300;
|
|
a : A = xx n;
|
|
b : B = xx n;
|
|
print("forward A (u64=300): {}\n", cast(s64) a);
|
|
print("direct B (u64=300): {}\n", cast(s64) b);
|
|
print("ns.width(): {}\n", ns.width());
|
|
return 0;
|
|
}
|