fix(stdlib/E4): route reflection/literal/value/match bare-type sites through the non-transitive gate
attempt-3 closed the leaf + parameterized-head leaks but several more
sites still resolved an UNQUALIFIED type name via the global
type_alias_map / findByName / type_bridge.resolveAstType without the
single-hop visibility gate, so a 2-flat-hop bare type leaked through:
- resolveTypeArg (reflection / size_of / align_of / type_name / type_eq):
identifier + type_expr leaves now gate via headTypeLeak; the wrapped /
structural forms (*T, [N]T, []T, ?T, fn-ptr, tuple) route through the
already-gated resolveTypeWithBindings so each inner leaf recurses the
source-aware resolveNominalLeaf.
- resolveTupleLiteralTypeArg: each element leaf is resolved through the
source-aware resolver before the delegated build, so (COnly, s64) is
gated.
- resolveArrayLiteralType (T.[...] typed array/vector-literal head):
identifier + type_expr leaves gate via headTypeLeak.
- type-as-value lowerExpr identifier (x: Type = COnly, x == COnly).
- type-category match arm (case COnly:).
Qualified ns.X / 1-hop / source-pinned library-internal references stay
exempt (the gate falls through for reachable / unauthored names, and
returns the existing "unresolved type" diagnostic for genuinely-undeclared
names). README notes the type gate holds wherever a bare type name is
named. New regressions 0765 (2-hop reject) / 0766 (1-hop pass).
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
// `#import` is non-transitive for a type named in a REFLECTION / type-arg slot
|
||||
// (`size_of(T)`, `size_of(*T)`) and in a TYPED ARRAY-LITERAL annotation
|
||||
// (`T.[...]`), exactly like a bare leaf annotation (0763), a parameterized head
|
||||
// (0764), and values/functions (0706): when A imports B and B imports C, A must
|
||||
// NOT see C's top-level types here either. This file imports `b.sx` (which
|
||||
// imports `c.sx`) and references C's `Nums` / `COnly` in those positions — each
|
||||
// is rejected with a "type ... is not visible; #import the module that declares
|
||||
// it" diagnostic, BEFORE the global type table can resolve it.
|
||||
//
|
||||
// `b.sx` ↔ `c.sx` together still compile: `b_sizes` / `b_arr` resolve `Nums` /
|
||||
// `COnly` because b.sx directly imports c.sx (one flat hop there, two from a
|
||||
// file that imports b.sx).
|
||||
//
|
||||
// Regression (Phase E4): before the bare-TYPE gate reached the reflection
|
||||
// type-arg and array-literal leaf sites, these 2-flat-hop references leaked
|
||||
// through the global `type_alias_map` / `findByName` / `type_bridge` lookup.
|
||||
|
||||
#import "modules/std.sx";
|
||||
#import "0765-modules-import-reflection-type-non-transitive/b.sx";
|
||||
|
||||
main :: () -> s32 {
|
||||
print("{}\n", size_of(Nums));
|
||||
print("{}\n", size_of(*COnly));
|
||||
xs := Nums.[1, 2];
|
||||
print("{} {}\n", xs[0], xs[1]);
|
||||
0
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
#import "c.sx";
|
||||
|
||||
// b.sx directly imports c.sx, so it CAN name these types in reflection /
|
||||
// type-arg / array-literal positions — the type is one flat hop away here,
|
||||
// two from a file that imports b.sx.
|
||||
b_sizes :: () -> s64 {
|
||||
size_of(Nums) + size_of(*COnly)
|
||||
}
|
||||
|
||||
b_arr :: () -> s64 {
|
||||
xs := Nums.[1, 2];
|
||||
xs[0] + xs[1]
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
Nums :: [2]s64;
|
||||
|
||||
COnly :: struct { v: s64 = 0; }
|
||||
16
examples/0766-modules-reflection-type-direct-ok.sx
Normal file
16
examples/0766-modules-reflection-type-direct-ok.sx
Normal file
@@ -0,0 +1,16 @@
|
||||
// The pass side of 0765: a DIRECTLY imported module's types are bare-visible in
|
||||
// reflection / type-arg slots (`size_of(Nums)`, `size_of(*COnly)`) and in a
|
||||
// typed array-literal annotation (`Nums.[...]`) — single-hop visibility, so a
|
||||
// 1-flat-hop type resolves exactly as before the E4 gate. Confirms the gate
|
||||
// only rejects the 2-hop case (0765), never a directly-imported reference.
|
||||
|
||||
#import "modules/std.sx";
|
||||
#import "0766-modules-reflection-type-direct-ok/c.sx";
|
||||
|
||||
main :: () -> s32 {
|
||||
print("{}\n", size_of(Nums));
|
||||
print("{}\n", size_of(*COnly));
|
||||
xs := Nums.[1, 2];
|
||||
print("{} {}\n", xs[0], xs[1]);
|
||||
0
|
||||
}
|
||||
3
examples/0766-modules-reflection-type-direct-ok/c.sx
Normal file
3
examples/0766-modules-reflection-type-direct-ok/c.sx
Normal file
@@ -0,0 +1,3 @@
|
||||
Nums :: [2]s64;
|
||||
|
||||
COnly :: struct { v: s64 = 0; }
|
||||
@@ -0,0 +1 @@
|
||||
1
|
||||
@@ -0,0 +1,17 @@
|
||||
error: type 'Nums' is not visible; #import the module that declares it
|
||||
--> /Users/agra/projects/sx/examples/0765-modules-import-reflection-type-non-transitive.sx:22:27
|
||||
|
|
||||
22 | print("{}\n", size_of(Nums));
|
||||
| ^^^^
|
||||
|
||||
error: type 'COnly' is not visible; #import the module that declares it
|
||||
--> /Users/agra/projects/sx/examples/0765-modules-import-reflection-type-non-transitive.sx:23:28
|
||||
|
|
||||
23 | print("{}\n", size_of(*COnly));
|
||||
| ^^^^^
|
||||
|
||||
error: type 'Nums' is not visible; #import the module that declares it
|
||||
--> /Users/agra/projects/sx/examples/0765-modules-import-reflection-type-non-transitive.sx:24:11
|
||||
|
|
||||
24 | xs := Nums.[1, 2];
|
||||
| ^^^^
|
||||
@@ -0,0 +1 @@
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
0
|
||||
@@ -0,0 +1,3 @@
|
||||
16
|
||||
8
|
||||
1 2
|
||||
Reference in New Issue
Block a user