Description
Symptom
--dump-typed on any file importing std shows free regex.w functions attributed as other modules' methods: fn BTreeMap.regex_compile_flags, fn Rc.regex_make_flags. Present in the current seed (v0.15.1-g21751b3be) and HEAD — pre-existing, alignment-dependent.
Root cause
SemaDecl.w compute_method_origins (the backwards walk at line ~34): from each NK_IMPL_DECL it walks preceding decls, adopting each NK_FN_DECL whose span nests inside the impl's span. Spans are compared NUMERICALLY with no same-file guard, so when the walk crosses a module boundary (the previous module's last decls), a foreign file's fn whose byte range happens to nest inside the impl's byte range — a different coordinate space — is adopted: method_decl_origins/method_impl_nodes/method_symbol_flags are poisoned for that symbol.
This is the same defect class #754 fixed for c_import decl adoption (decls_share_source_file exists for exactly this); this site never got the guard.
Impact
Beyond dump cosmetics, method_symbol_flags/method_has_inherent participate in call resolution — a free fn wrongly flagged as a method is a latent mis-resolution for method-syntax calls of the same name. No known miscompile today; found while root-causing the dump_typed_d22_contextual_copy phase-test failure (whose actual cause was the separate pretty-name wrong-buffer extraction, fixed alongside battery 8).
Fix shape
Add if self.decls_share_source_file(j, di) == 0: break to the backwards walk (and audit the "top-level method syntax" pass for the same assumption). Needs its own battery — method resolution churn.
Activity
sema: stop pretty-name extraction from slicing the wrong source file
ehartford commentedon Sep 1, 2026
Fixed — and it was the same defect TWICE, as the issue's 'audit the other pass' note predicted: (1) compute_method_origins' backwards walk now breaks at a file boundary via decls_share_source_file (the #754 guard), ending the cross-module adoption that poisoned method_symbol_flags/method_has_inherent; (2) impl_owner_type_name_for_decl — the typed-dump renderer's own independent whole-pool span scan — had the identical hole and re-derived the same wrong attribution even after the semantic fix; it now takes the decl index and applies the same guard.
Verified: analyze facts show regex_make_flags receiver=none/in-impl=false; --dump-typed shows zero cross-module attributions with 42 genuine method attributions unchanged on the probe; full :test green.
sema: method adoption and dump attribution require same-file spans (#756