fix(lower): single unified writer for the three decl-fact maps; close param-alias leak [stdlib E1 attempt-5]

Route EVERY write of type_alias_map / module_const_map / global_names (and
their *_by_source analogues) through one helper per map
(putTypeAlias/putModuleConst/putGlobal/dropModuleConst). The global put and the
by-source put are now inseparable, so no write-site can mirror one side and
miss the other — the dual-write drift that leaked ns-only aliases past the
source-aware bare-TYPE gate. Grep-clean: no raw .put/.remove to the three maps
outside the helpers (mirrors the no-raw-TypeTable.update discipline).

The generic-struct instantiation alias sites (Secret :: Box(s32), both the
.call and .parameterized_type_expr branches) previously registered only a named
struct in the TypeTable and never reached type_aliases_by_source, so
moduleTypeAuthor missed them and a bare ns-only use leaked (exit 42, no
diagnostic). Routing those writes through the unified putTypeAlias lands the
alias in the per-source cache and the leak closes BY CONSTRUCTION — a flat use
still resolves to the same TypeId findByName would, a ns-only use is rejected.

Regression 0749 (ns-only Secret :: Box(s32) bare -> "type 'Secret' is not
visible"): fail-before on daf4bbc exit 42 no diagnostic, pass-after exit 1.
Single-author resolution byte-identical (486 passed / 0 failed). resolver.zig
single graph-walk untouched; generic/param-protocol/Vector/type-fn stay legacy.
This commit is contained in:
agra
2026-06-07 19:31:13 +03:00
parent daf4bbc862
commit 78ef2ea3d8
6 changed files with 84 additions and 58 deletions

View File

@@ -0,0 +1,17 @@
// Bare PARAMETERIZED-struct alias visibility under a NAMESPACED-only import —
// the generic-struct sibling of 0747 (plain alias) and 0743 (named type). A
// generic-struct instantiation alias (`Secret :: Box(s32)`) registers ONLY a
// named struct type in the TypeTable; its raw import fact stays `.const_decl`,
// so before the fix it was NOT recognised as a type author and a BARE `Secret`
// leaked to the registered struct with NO diagnostic (the value silently came
// out 42). The unified declaration-fact writer routes the instantiation alias
// through `type_aliases_by_source`, so the bare-TYPE gate treats it like any
// other alias: `dep.sx` is imported only as `dep :: #import`, so bare `Secret`
// is reachable ONLY as `dep.Secret` and must NOT resolve. Regression
// (attempt-5 R4-parameterized-alias-leak).
dep :: #import "0749-modules-namespaced-only-bare-param-alias-not-visible/dep.sx";
main :: () -> s32 {
s : Secret = .{ value = 42 };
s.value
}

View File

@@ -0,0 +1,5 @@
Box :: struct($T: Type) {
value: T;
}
Secret :: Box(s32);

View File

@@ -0,0 +1,5 @@
error: type 'Secret' is not visible; #import the module that declares it
--> examples/0749-modules-namespaced-only-bare-param-alias-not-visible.sx:15:9
|
15 | s : Secret = .{ value = 42 };
| ^^^^^^