Files
sx/examples/0776-modules-bare-generic-static-method-visible-author.sx
agra 7ba64d5756 fix(stdlib/E4): bare generic static-method head selects the visible author (type + method)
The static-method-call head `Box(s64).make(7)` was the last uncovered bare-
generic-head instantiation site: it gated visibility with `headTypeLeak` but
then instantiated the global last-wins `struct_template_map` entry and ran the
name-keyed `Box.make` from `fn_ast_map`, so a NON-visible 2-flat-hop same-name
template (and its method) won. `size_of(Box(s64))` picked the visible `b.Box`
(8) while `Box(s64).make(7)` returned a `c.Box`-shaped (16) value.

Route the static-method head through the single bare-VISIBLE author for BOTH
the instantiated type layout AND the method body: split the existing visible-
author selection into `bareVisibleStructDecl` (returns the StructDecl + source;
single selection point, `bareVisibleStructTemplate` now delegates to it — no
drift) and source-pin the method body via the author's own `sd.methods`
(`structMethodFn`) instead of the last-wins `fn_ast_map`. Ambiguity (>1 visible
author) is already diagnosed by the pre-existing `headTypeLeak` gate.

Exhaustive bare-head instantiation-site audit (all callers reaching
`instantiateGenericStruct` / `struct_template_map` for a bare head): .call alias,
.parameterized_type_expr alias, resolveType .call, resolveTypeCallWithBindings,
resolveParameterizedWithBindings — all already route through the visible-author
selection; the static-method head was the only remaining one and is now covered.

Regression 0776: bare generic static-method head with a 2-hop same-name template
asserts the visible author's layout (xtype=8, x reachable); fail-before xtype=16.
2026-06-08 19:06:13 +03:00

28 lines
1.4 KiB
Plaintext

// A BARE generic struct head used as a STATIC-METHOD-CALL target
// (`Box(s64).make(7)`) must instantiate — and call the method of — the template
// authored by the single bare-VISIBLE author, NOT the global last-wins
// `struct_template_map` (and its name-keyed `Box.make`), which a NON-visible
// 2-flat-hop same-name template can win.
//
// `b.sx` declares a one-field `Box($T)` (size 8) with its own `make`, and itself
// flat-imports `c.sx`, which declares a two-field `Box($T)` (size 16) with its
// own `make`. This file flat-imports ONLY `b.sx`, so `b.Box` is one flat hop away
// (visible) and `c.Box` is two hops away (NOT bare-visible, mirrors
// 0764/0774/0706). The static-method head `Box(s64).make(7)` must select `b.Box`
// (size 8) for BOTH the instantiated type layout and the method body.
//
// Regression (Phase E4 finding #1, static-method site): before the static-method
// head consulted the source-keyed visible author, `size_of(Box(s64))` correctly
// picked the visible `b.Box` (8) but `Box(s64).make(7)` instantiated the global
// last-wins `c.Box` and ran `c.Box.make`, returning a 16-byte value. Fail-before
// printed `size=8 xtype=16 x=7`.
#import "modules/std.sx";
#import "0776-modules-bare-generic-static-method-visible-author/b.sx";
main :: () -> s32 {
x := Box(s64).make(7);
print("size={} xtype={} x={}\n", size_of(Box(s64)), size_of(type_of(x)), x.x);
0
}