fix(lower): reserve genuine same-name struct shadows before fields — close F1 [stdlib E2 attempt-2]
A self / forward / mutual reference inside a same-name struct shadow bound to
the FIRST same-name author (another module's struct) instead of its own nominal
TypeId: registerStructDecl resolved a shadow's field types BEFORE registering its
decl key in type_decl_tids, so namedRefTid fell through to the name-only
findByName first-author fallback (F1).
Fix: a genuine same-name struct shadow (≥2 DISTINCT struct decls author the name
in the scanned decl set) reserves ALL its authors' distinct nominal slots up-front
in scanDecls — the first at id 0, the rest at fresh nonzero ids — BEFORE any field
resolves. Every self / forward / mutual ref to the shadow name then resolves via
type_decl_tids to its OWN nominal TypeId.
Gating on the scanned decls, not nameHasMultipleTypeAuthors (the raw import facts
over-count a single file reached via two un-normalized import spellings, e.g.
math/matrix44), keeps single-real-decl names on the legacy id-0 post-field path —
byte-identical (494 prior markers unchanged, single-author old==new).
internNamedTypeDecl now takes the precomputed nominal_id; no-drift + single
graph-walk invariants untouched; generics / enum / union / error-set stay legacy.
Regressions: 0757 (self-ref *Box → reads B's own field), 0758 (forward + mutual
*Node/*Box between two shadows). Fail-before on d98ad5c
("field 'y'/'m' not found"), pass-after.
This commit is contained in:
3
examples/0758-modules-same-name-struct-mutual-ref/a.sx
Normal file
3
examples/0758-modules-same-name-struct-mutual-ref/a.sx
Normal file
@@ -0,0 +1,3 @@
|
||||
// Module A authors its OWN `Box` and `Node` (the FIRST same-name authors).
|
||||
Box :: struct { x: s64; }
|
||||
Node :: struct { n: s64; }
|
||||
13
examples/0758-modules-same-name-struct-mutual-ref/b.sx
Normal file
13
examples/0758-modules-same-name-struct-mutual-ref/b.sx
Normal file
@@ -0,0 +1,13 @@
|
||||
// Module B authors same-name `Box` and `Node` shadows that reference EACH OTHER.
|
||||
// B's `Box` has a FORWARD ref to B's `Node` (declared after it), and B's `Node`
|
||||
// back-refs B's `Box`. Both forward and mutual refs must resolve to B's OWN
|
||||
// nominal TypeIds, not the first same-name authors in A.
|
||||
Box :: struct { y: s64; peer: *Node; }
|
||||
Node :: struct { m: s64; owner: *Box; }
|
||||
b_test :: () -> s64 {
|
||||
nd := Node.{ m = 99, owner = null };
|
||||
bx := Box.{ y = 7, peer = @nd };
|
||||
// Reads B's Node.m (99); pre-fix the forward ref bound to A's Node (which has
|
||||
// field `n`, not `m`) → "field 'm' not found on type 'Node'".
|
||||
return bx.peer.*.m;
|
||||
}
|
||||
Reference in New Issue
Block a user