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.
16 lines
760 B
Plaintext
16 lines
760 B
Plaintext
// issue 0105 / F1 regression — FORWARD + MUTUAL refs between same-name struct
|
|
// shadows. Two flat-imported modules each declare `Box` and `Node`; module B's
|
|
// `Box` forward-refs B's `Node` (declared later) and B's `Node` back-refs B's
|
|
// `Box`. Every cross-reference must bind to B's OWN nominal identities, proving
|
|
// the up-front genuine-shadow reservation: ALL of a genuine shadow's authors are
|
|
// reserved in `type_decl_tids` before any field resolves, so a forward / mutual
|
|
// ref never falls back to the global findByName first-author (A's `Node`).
|
|
#import "modules/std.sx";
|
|
#import "0758-modules-same-name-struct-mutual-ref/a.sx";
|
|
#import "0758-modules-same-name-struct-mutual-ref/b.sx";
|
|
|
|
main :: () -> s32 {
|
|
print("b={}\n", b_test());
|
|
0
|
|
}
|