fix(stdlib/E4): qualified generic head ns.Box(..) selects the namespace author
A qualified generic type head `ns.Box(args)` was stripped to its bare name and
read from the last-wins `struct_template_map`, so the namespace qualifier never
selected the template author: `a.Box(s64)` and `b.Box(s64)` (two namespaces each
authoring a same-name `Box($T)` with different layouts) both instantiated the
global same-name template. The documented ambiguity escape hatch ("qualify it as
ns.Box") silently produced the wrong layout.
Select the template via the namespace edge (importer -> alias -> NamespaceTarget)
instead of the bare map, at both the .call and parameterized-type-expr head
sites. Two same-name templates instantiated with the same args would also collide
on the mangled name `Box__s64`, so tag the non-canonical author's mangled name
with its source (the canonical bare-map author keeps the untagged name -> no
churn for single-author generics).
Extract `buildGenericStructTemplate` so the bare registration and the new
namespace-qualified selection share one template builder.
Regression: examples/0772 — two namespaces each authoring Box($T) with different
layouts; ns_a.Box(s64) and ns_b.Box(s64) resolve to their own module's template
(sizes 8 and 16). Fail-before on 566de96 (a=16 b=16), pass-after (a=8 b=16).
This commit is contained in:
@@ -422,7 +422,12 @@ enforced at every one of those sites as well: a bare type (including a type-retu
|
||||
function head) that two or more flat imports each declare — with no own author to
|
||||
win — is **ambiguous and rejected** (`type 'X' is ambiguous: it is declared in
|
||||
multiple flat-imported modules; qualify the reference or remove the duplicate
|
||||
import`) — never a silent pick of one author. (A library's own *internal* type references still resolve: a generic
|
||||
import`) — never a silent pick of one author. Qualifying the reference is a real
|
||||
escape hatch for a **generic head** too: `ns.Box(args)` selects the template
|
||||
AUTHORED by `ns`'s module, so two namespaces each declaring a same-name
|
||||
`Box($T)` with different layouts stay distinct types (`a.Box(s64)` and
|
||||
`b.Box(s64)` instantiate their own author's fields), never the global last-wins
|
||||
template. (A library's own *internal* type references still resolve: a generic
|
||||
struct / pack fn / protocol body is instantiated in the module that defines it, so
|
||||
e.g. `List(T).append`'s `alloc: Allocator` is visible there regardless of the call
|
||||
site.)
|
||||
|
||||
Reference in New Issue
Block a user