The generic-struct author-selection matrix {bare,qualified} × {site} × {layout,
body} drifted per-site across 12 attempts because method bodies were resolved by
bare template name in `fn_ast_map["Box.method"]`, independent of which author
produced the instance's layout. Collapse it into four choke-points so
layout-author ≡ body-author by construction:
CP-1 `selectGenericStructHead` — the single layout-head selector every generic
struct head site funnels through (alias-RHS .call/.parameterized, array-
literal, static head, resolveTypeCall/ParameterizedWithBindings). Emits the
visibility / missing-member diagnostics inline; returns a control-flow-only
union. No head site reads `struct_template_map` for selection directly.
CP-2 author stamp — non-optional `decl: *StructDecl` on `StructTemplate` (set at
the sole producer `buildGenericStructTemplate`) + `struct_instance_author`
written at `instantiateGenericStruct` from the SAME `tmpl` that builds the
layout; re-stamped on the dedup fast-path so an instance is never returned
without an author.
CP-3 alias metadata copy — mirror template/bindings/author from the mangled
instance onto the alias display name, so an `ABox`-typed receiver is a
first-class dispatch instance (Counter-2).
CP-4 `genericInstanceMethod` / `ensureGenericInstanceMethodLowered` — the single
body reader: inline methods select via the stamped author (`structMethodFn`,
source-pin follows for free); impl-block methods fall back to the template-
keyed `fn_ast_map` entry. Routes the four bespoke body sites (static head,
instance dispatch, param typing, protocol thunk) + the new qualified static
head (`a.Box(s64).make(7)`, finding #2).
A debug assert locks `struct_instance_author` / `struct_instance_template` keyset
coincidence so a future third writer that forgets the author trips a test.
Goldens 0777/0778/0780 (bare instance method — ptr/by-value/param-typed, finding
#1), 0779/0785 (qualified static head + missing member, finding #2), 0783 (alias
instance dispatch, Counter-2), 0782 (ambiguity containment). 0414/0415/0543 and
the FFI suites stay green.
25 lines
1.2 KiB
Plaintext
25 lines
1.2 KiB
Plaintext
// A BARE generic struct INSTANCE method (`x.tag()`) must dispatch to the method
|
|
// authored alongside the instance's layout — the single bare-VISIBLE author —
|
|
// NOT the global last-wins `fn_ast_map["Box.tag"]`, which a NON-visible
|
|
// 2-flat-hop same-name template's method can win.
|
|
//
|
|
// `b.sx` declares a one-field `Box($T)` (size 8) whose `tag` returns `self.x+8`,
|
|
// and itself flat-imports `c.sx`, whose two-field `Box($T)` (size 16) declares a
|
|
// `tag` returning `self.x+16`. This file flat-imports ONLY `b.sx`, so `b.Box` is
|
|
// one flat hop away (visible) and `c.Box` is two hops (NOT bare-visible).
|
|
//
|
|
// Regression (Phase E4 finding #1, instance-method site): the static head
|
|
// `Box(s64).make(7)` already selected `b.Box` for the layout (size 8), but the
|
|
// instance method `x.tag()` resolved by bare template name in `fn_ast_map`, so it
|
|
// ran `c.Box.tag` (returning 7+16=23) on the b instance. Fail-before printed
|
|
// `size=8 tag=23`; with body-author ≡ layout-author it runs b's `tag` (7+8=15).
|
|
|
|
#import "modules/std.sx";
|
|
#import "0777-modules-bare-generic-instance-method-visible-author/b.sx";
|
|
|
|
main :: () -> s32 {
|
|
x := Box(s64).make(7);
|
|
print("size={} tag={}\n", size_of(type_of(x)), x.tag());
|
|
0
|
|
}
|