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:
16
examples/0757-modules-same-name-struct-self-ref.sx
Normal file
16
examples/0757-modules-same-name-struct-self-ref.sx
Normal file
@@ -0,0 +1,16 @@
|
||||
// issue 0105 / F1 regression — a SELF-REFERENCE inside a same-name struct shadow.
|
||||
// Two flat-imported modules each declare a top-level `Box`; module B's `Box` has
|
||||
// a field `next: *Box` referencing its own name. The shadow must resolve that
|
||||
// self-ref to ITS OWN nominal identity, not the first same-name author (A's
|
||||
// `Box`), so `head.next.*.y` reads B's `y` (= 42). Proves the reserve-before-
|
||||
// fields ordering: a shadow author's decl key is recorded before its fields are
|
||||
// resolved, so a self / forward ref binds via `type_decl_tids`, never the global
|
||||
// findByName first-author fallback.
|
||||
#import "modules/std.sx";
|
||||
#import "0757-modules-same-name-struct-self-ref/a.sx";
|
||||
#import "0757-modules-same-name-struct-self-ref/b.sx";
|
||||
|
||||
main :: () -> s32 {
|
||||
print("a={} b={}\n", a_box(), b_chain());
|
||||
0
|
||||
}
|
||||
Reference in New Issue
Block a user