feat(resolver): source-aware nominal leaf (Lowering-side) + ns-const tightening [stdlib E1]

Route the Lowering-side bare type leaf through the source-keyed caches (E0):
nominal author via collectVisibleAuthors(.user_bare_flat) + alias via
type_aliases_by_source, instead of the global findByName first-match. The
binding-free resolveAstType path + registration sites stay on the global
compat readers (move later). Single-author resolution byte-identical (no
shadows yet). Folded req #1: a namespaced-only import's const is no longer
bare-visible in array-dim/comptime-scalar position. Adds regression 0742
(ns-only bare const) and 0210 (generics/Vector/type-fn stay legacy).

Salvaged from a worker killed at the wall before commit; manager verified
the gate at ground truth (zig build test exit 0; run_examples 479/0 with
0210+0742 ok, prior 477 byte-identical; m3te ios-sim exit 0; folded fix
confirmed fail-before on master 7ffc0c1 exit 0 / pass-after exit 1).
This commit is contained in:
agra
2026-06-07 15:24:43 +03:00
parent a5d6c940dd
commit 7cd12b0ed5
10 changed files with 212 additions and 7 deletions

View File

@@ -0,0 +1,31 @@
// Resolver E1 lock: the bare-type-leaf cutover to the source-aware
// `selectNominalLeaf` must NOT touch the NON-leaf type heads. A generic-struct
// instantiation (`Box(s32)`), a `Vector(N, T)` builtin, and a type-returning
// function (`Make(3, s64)`) are all resolved by `resolveTypeWithBindings`
// ABOVE the bare-name leaf switch (`resolveParameterizedWithBindings` /
// `resolveTypeCallWithBindings` / the `Vector` builtin path), so they stay on
// the legacy resolution and never reach `selectNominalLeaf`. Parameterized
// protocols share the same `resolveParameterizedWithBindings` pre-leaf path
// (covered by 0204/0206). This example pins that all three still resolve
// identically after the cutover.
#import "modules/std.sx";
Box :: struct($T: Type) {
value: T;
}
Make :: ($K: u32, $T: Type) -> Type { return [K]T; }
N :: 3;
main :: () {
b : Box(s32) = .{ value = 42 };
print("box: {}\n", b.value);
v : Vector(4, f32) = .[1, 2, 3, 4];
print("vec: {} {}\n", v.x, v.w);
a : Make(N, s64) = ---;
a[0] = 10; a[2] = 30;
print("typefn: len={} a0={} a2={}\n", a.len, a[0], a[2]);
}

View File

@@ -0,0 +1,15 @@
// Bare module-const visibility under a NAMESPACED-only import — the const
// sibling of 0736 (folded req #1 of the source-aware resolver, Phase E1).
// `dep.sx` is imported only as `dep :: #import`, so its top-level `DEP_LEN`
// is reachable ONLY as `dep.DEP_LEN`. A BARE `DEP_LEN` in a comptime
// array-dimension position must NOT resolve: bare module-const visibility
// joins over the FLAT import edges (`flat_import_graph`), and a namespaced
// alias is not a flat edge. Before the fix the bare const leaked through the
// global `module_const_map` first-match (and its float-fold fallback) straight
// into the `[VAL]s32` dimension, so the array silently got length 3.
dep :: #import "0742-modules-namespaced-only-bare-const-not-visible/dep.sx";
main :: () -> s32 {
arr : [DEP_LEN]s32 = ---;
0
}

View File

@@ -0,0 +1 @@
DEP_LEN :: 3;

View File

@@ -0,0 +1 @@
0

View File

@@ -0,0 +1 @@

View File

@@ -0,0 +1,3 @@
box: 42
vec: 1.000000 4.000000
typefn: len=3 a0=10 a2=30

View File

@@ -0,0 +1,5 @@
error: array dimension must be a compile-time integer constant
--> examples/0742-modules-namespaced-only-bare-const-not-visible.sx:13:12
|
13 | arr : [DEP_LEN]s32 = ---;
| ^^^^^^^