fix(resolver): type-author-aware + local-safe bare-TYPE gate; R3 model escalated [stdlib E1 attempt-3]

R1 (type-author-aware gate): the bare-TYPE visibility gate now requires a
flat-import-reachable TYPE author (struct/enum/union/error-set/protocol/foreign
class). A same-name flat VALUE/FUNCTION no longer makes a namespaced-only TYPE
bare-visible — the name-only `m.names.contains` check (attempt-2) is replaced by
`moduleAuthorsType` (kind-checked via `RawDeclRef`). Regression 0745.

R2 (no local false-positive): a block-local type clobbers the global type-table
entry for its name (`registerStructDecl`'s findByName-orelse-intern +
updatePreservingKey), so it IS the resolved type — never a namespaced-only leak.
A new `local_type_names` set, populated at both block-local type-decl paths,
exempts such names from the gate. Regression 0746.

readme.md: drop the false "transitively" claim — flat-import bare visibility for
functions and constants is NON-transitive (0706).

R3 (foundational model consistency) is ESCALATED, not resolved here — see the
attempt-3 worker report. Ground truth: making the TYPE gate single-hop (to match
the value/function model) breaks ~19 tests, ~13 of them library-INTERNAL generic
refs (e.g. `List.append`'s `alloc: Allocator`, lowered in the caller's source
context). That needs source-pinning generic instantiation to the template's
defining module — a separate architectural piece beyond E1's leaf-cut scope, and
proven risky (a `monomorphizeFunction` pin broke 4 FFI objc-block tests and did
not even take, since template method bodies lack a reliable `source_file`). The
TYPE gate therefore stays on the (type-author-aware) transitive flat closure for
E1; the non-transitive reconciliation is a routed follow-up.
This commit is contained in:
agra
2026-06-07 17:51:09 +03:00
parent 7188481761
commit 4bd57c857e
13 changed files with 179 additions and 72 deletions

View File

@@ -0,0 +1,15 @@
// Type-author-aware bare-TYPE visibility gate (Phase E1, R1). `flatval.sx` is
// flat-imported and authors a VALUE/FUNCTION `Secret`; `nstype.sx` is namespaced
// (`nst :: #import`) and authors a TYPE `Secret`. A bare `Secret` in a type
// position must NOT resolve: the only flat-visible `Secret` author is a FUNCTION,
// and a same-name flat value does NOT make the namespaced-only TYPE bare-visible.
// The leak this closes: a name-only gate would see the flat function and let the
// global `findByName` first-match return the namespaced-only struct. The type is
// reachable only as `nst.Secret`.
#import "0745-modules-flat-value-shadows-ns-only-type/flatval.sx";
nst :: #import "0745-modules-flat-value-shadows-ns-only-type/nstype.sx";
main :: () -> s32 {
s : Secret = .{ x = 5, y = 6 };
s.x
}

View File

@@ -0,0 +1,2 @@
// A flat-visible VALUE/FUNCTION named `Secret` (not a type).
Secret :: () -> s32 { 0 }

View File

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

View File

@@ -0,0 +1,13 @@
// A block-LOCAL type resolves even when a namespaced-only import authors a
// top-level type of the same name (Phase E1, R2). `dep.sx` is namespaced
// (`dep :: #import`) and authors a top-level `Secret`; `main` declares its OWN
// block-local `Secret`. The local must resolve to ITS fields (a legitimately-
// scoped local is never a namespaced-only leak), not be rejected by the bare-TYPE
// visibility gate just because the namespaced import shares the name.
dep :: #import "0746-modules-local-type-shadows-ns-only-type/dep.sx";
main :: () -> s32 {
Secret :: struct { z: s32; }
s : Secret = .{ z = 7 };
s.z
}

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/0745-modules-flat-value-shadows-ns-only-type.sx:13:9
|
13 | s : Secret = .{ x = 5, y = 6 };
| ^^^^^^