fix(resolver): treat type aliases as bare-TYPE authors in both gate directions [stdlib E1 attempt-4]

R4: a type alias is a `const_decl`, not a named-type decl, so the bare-TYPE
visibility gate ignored aliases — a namespaced-only alias leaked bare (silent
empty-struct stub, no diagnostic) and a flat-visible alias was poisoned by an
invisible same-name named type. Unify both type-author kinds (named type AND
alias) behind one per-module predicate `moduleTypeAuthor`, returning the author
KIND so resolution is decoupled from `findByName` timing (a forward/self
reference like `next: *ArenaChunk`, unregistered mid-registration, is still
recognised as an author and falls to the legacy stub instead of a false
"not visible"). The leak detector `nameAuthoredAsTypeAnywhere` now also scans
`type_aliases_by_source`. Single source of truth across named types, top-level
aliases, and parameterized/type-fn aliases — leak side and false-rejection side.

Behavior-preserving for single-author names (full suite byte-identical, paths
normalized). Generic / parameterized-protocol / Vector / type-function heads
stay legacy (0210). Block-local `Name :: <type>` remains a value const under the
reserved-name duality (pre-existing; the gate handles it safely, no leak).

Regressions: 0747 (ns-only alias bare -> not visible), 0748 (flat-visible alias
not poisoned by ns-only same-name struct). Both fail-before on 4bd57c8 /
pass-after here.
This commit is contained in:
agra
2026-06-07 18:41:01 +03:00
parent 4bd57c857e
commit daf4bbc862
11 changed files with 213 additions and 94 deletions

View File

@@ -0,0 +1,16 @@
// Bare TYPE-ALIAS visibility under a NAMESPACED-only import — the alias sibling
// of 0743 (bare named type) and 0742 (bare const). A type ALIAS is a `const_decl`
// whose value resolved to a type, so it never registers a `findByName` named-type
// entry; the source-aware leaf must still treat it as a TYPE author (R4). `dep.sx`
// is imported only as `dep :: #import`, so its top-level `Secret :: s32` alias is
// reachable ONLY as `dep.Secret`. A BARE `Secret` in a type position must NOT
// resolve: bare-TYPE visibility joins over the FLAT import edges, and a namespaced
// alias is not a flat edge. Before the fix the ns-only alias was NOT a recognised
// type author, so the bare reference fell to the legacy empty-struct stub with NO
// diagnostic (the value silently came out 0). Regression (issue R4).
dep :: #import "0747-modules-namespaced-only-bare-alias-not-visible/dep.sx";
main :: () -> s32 {
x : Secret = 7;
x
}

View File

@@ -0,0 +1 @@
Secret :: s32;

View File

@@ -0,0 +1,18 @@
// A flat-visible (here own-module) type ALIAS must resolve even when a
// namespaced-only import authors a same-name NAMED type — the alias↔named-type
// analog of 0745/0746 (R4, FALSE-REJECTION direction). `dep.sx` is namespaced
// (`ns :: #import`) and authors a top-level `Secret` STRUCT; `main` authors its
// OWN top-level alias `Secret :: s32`. A bare `Secret` must resolve to MAIN's
// alias (`s32`), NOT be poisoned by the invisible same-name struct: the alias is
// the only flat-visible TYPE author. Before the fix the leaf saw the global
// `findByName` struct and, finding no NAMED-type author in `main` (an alias is a
// `const_decl`, not a named type), wrongly rejected the bare reference as "not
// visible". Regression (issue R4).
ns :: #import "0748-modules-flat-alias-shadows-ns-only-type/dep.sx";
Secret :: s32;
main :: () -> s32 {
x : Secret = 42;
x
}

View File

@@ -0,0 +1,4 @@
Secret :: struct {
x: s32;
y: s32;
}

View File

@@ -0,0 +1,5 @@
error: type 'Secret' is not visible; #import the module that declares it
--> examples/0747-modules-namespaced-only-bare-alias-not-visible.sx:14:9
|
14 | x : Secret = 7;
| ^^^^^^