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).
This commit is contained in:
28
examples/0773-modules-qualified-generic-alias-author.sx
Normal file
28
examples/0773-modules-qualified-generic-alias-author.sx
Normal file
@@ -0,0 +1,28 @@
|
||||
// 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
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
// Author A's generic `Box` — one s64 field (size 8).
|
||||
Box :: struct($T: Type) { x: T; }
|
||||
@@ -0,0 +1,3 @@
|
||||
// Author B's generic `Box` — two s64 fields (size 16). Same template NAME as
|
||||
// A's, different layout: the qualified alias head must select by namespace author.
|
||||
Box :: struct($T: Type) { x: T; y: T; }
|
||||
@@ -0,0 +1 @@
|
||||
0
|
||||
@@ -0,0 +1 @@
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
alias a=8 b=16
|
||||
ab.x=1 bb.x=10 bb.y=20
|
||||
Reference in New Issue
Block a user