Files
sx/examples/0773-modules-qualified-generic-alias-author.sx
agra 8c59acbd25 fix(stdlib/E4): qualified generic alias head a.Box(..) selects the namespace author
The const-decl alias-registration path treated a qualified generic head
(`ABox :: a.Box(s64)`) only as a gate exemption, then read the bare last-wins
`struct_template_map` — so `ABox` and `BBox` both instantiated whichever
same-name template won globally (both size 16). attempt-9 routed the annotation
head sites through `qualifiedStructTemplate`; this applies the same selection to
the two alias-registration branches (.call and .parameterized_type_expr) before
the bare fallback, and extracts the shared instantiate-and-register logic into
`registerGenericStructAlias`.

ABox :: a.Box(s64) now resolves to a's template (size 8); BBox :: b.Box(s64) to
b's (size 16). Regression 0773 pins it (fail-before alias a=16 b=16, after a=8
b=16).
2026-06-08 17:56:29 +03:00

29 lines
1.3 KiB
Plaintext

// A type alias whose RHS is a qualified generic head `ns.Box(args)` must
// instantiate the template AUTHORED by `ns`'s module — not the global same-name
// template that won the last-wins `struct_template_map`. Two namespaces each
// author a same-name generic `Box($T)` with a DIFFERENT layout (a: one field,
// b: two fields). `ABox :: a.Box(s64)` and `BBox :: b.Box(s64)` must register
// aliases over their OWN module's template (sizes 8 and 16) and stay DISTINCT,
// so the field unique to b's layout (`y`) is reachable only through `BBox`.
//
// Regression (Phase E4): before the alias-registration path selected the
// qualified author, the const-decl alias `.call` branch stripped the head to the
// bare name and read the global `struct_template_map`, so `ABox` and `BBox` both
// instantiated the last-wins template (both size 16). attempt-9 fixed the
// annotation head sites; this pins the alias-registration sibling.
#import "modules/std.sx";
a :: #import "0773-modules-qualified-generic-alias-author/a.sx";
b :: #import "0773-modules-qualified-generic-alias-author/b.sx";
ABox :: a.Box(s64);
BBox :: b.Box(s64);
main :: () -> s32 {
ab : ABox = .{ x = 1 };
bb : BBox = .{ x = 10, y = 20 };
print("alias a={} b={}\n", size_of(ABox), size_of(BBox));
print("ab.x={} bb.x={} bb.y={}\n", ab.x, bb.x, bb.y);
0
}