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.
21 lines
897 B
Plaintext
21 lines
897 B
Plaintext
// A BARE generic struct instance method that takes a PARAM (`x.combine(3)`) must
|
|
// type its arguments against — and run the body of — the VISIBLE author's method.
|
|
// The arg-typing path (`resolveCallParamTypes`) reads the instance's STAMPED
|
|
// author for the method's param types, and dispatch runs that same author's body.
|
|
//
|
|
// `b.sx` (one field, size 8) declares `combine(self, v) => self.x + v`; the
|
|
// 2-flat-hop `c.sx` (two fields) declares `combine(self, v) => self.x * v + 16`.
|
|
// Importing only b.sx, `x.combine(3)` on the visible `b.Box` instance must run
|
|
// b's body (`7 + 3 = 10`), not c's (`7 * 3 + 16 = 37`).
|
|
//
|
|
// Regression (Phase E4 finding #1, param-typed instance-method site).
|
|
|
|
#import "modules/std.sx";
|
|
#import "0780-modules-bare-generic-instance-param-typed-author/b.sx";
|
|
|
|
main :: () -> s32 {
|
|
x := Box(s64).make(7);
|
|
print("combine={}\n", x.combine(3));
|
|
0
|
|
}
|