You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
A trait impl resolves its trait by bare name in the merged prelude scope: a user trait named like a std trait rebinds std's impls (and vice versa) #2520
Found 2026-10-20 while adding pub trait One: fn one() -> Self to lib/std/traits.w (#2220 step 2, it.product()): test/behavior/behav_1346_trait_impl_body_forms.w declares its own trait One with an instance method fn one() -> i32. With both in scope:
error: undefined variable (`self` in the user's `impl One for X: fn one(): self.v + 2`)
error: 'X.one' is a function of the type and takes no receiver; call it as `X.one(...)`
error: a float where an integer is demanded … --> <embedded-std>/std/traits.w:60 (`impl One for f32: fn one(): 1.0`)
So the user's impl One for X bound to std's One (a static -> Self), and std's own impl One for f32 bound to the user's One (-> i32): trait impls resolve their trait by bare name in the merged prelude scope, whichever module declared them. D70 (last import wins) is about the user's names; an impl written in std.traits must bind to std.traits' One, and a user's impl of their own trait to theirs, as a user's type Foo beside a std Foo already does for types.
Expected: an impl's trait resolves in the impl's own module scope first; a user trait shadowing a prelude trait of the same name changes nothing in std. Workaround: the fixture's trait is renamed (One → PlusTwo) in the step 2 PR with a comment naming this issue; the rename is undone when this is fixed.
Second shape, 2026-10-21: two traits each declaring a method named one, both implemented for f64 (std.traits' One.one and a test's Unit1.one), collide on the f64.one method symbol and MIR reports "body index map mismatch for fn symbol N" (two bodies for one symbol). Method identity is the bare Type.method name, not (trait, Type, method). The D140 fixture names its method unit until this is fixed.
Triage 2026-10-25, with v0.15.3.0 (main a261b65): reproduced, both shapes.
$ cat main.w # a user trait named like std's One
trait One:
fn one(self: &Self) -> i32
type X { v: i32 }
impl One for X:
fn one(): self.v + 2
fn main:
let x = X { v: 1 }
print(x.one())
$ with run main.w
error: undefined variable
--> main.w:5:15
error: 'X.one' is a function of the type and takes no receiver; call it as `X.one(...)`
$ cat two.w # a second trait with a method `one`, implemented for f64
trait Unit1:
fn one() -> Self
impl Unit1 for f64:
fn one(): 2.0
fn main:
print(f64.one())
$ with run two.w
error: internal compiler error: invalid MIR before codegen (a bug in the With compiler, not in this program): body index map mismatch for fn symbol 909 in ``
pre-release: ordinary user traits collide with std names, one way with a wrong diagnostic and one with an internal error.
Fix campaign 2026-10-25: both root causes located; the fix is a multi-step change to trait and method identity, so it goes to Eric to schedule.
Shape 1 (a user trait named like std's One):Sema.trait_lookup: HashMap[i32, i32] (src/Sema.w:1007) maps a trait's bare name symbol to one trait index. A user trait One and std.traits.One are the same key, so impl One for X binds to whichever registered last; the user impl is then checked against std's fn one() -> Self (no receiver), giving "undefined variable self" and "X.one is a function of the type". 24 reads of trait_lookup (SemaDecl 10, Sema 5, SemaCheck 9) assume the name is the identity.
Shape 2 (two traits with a method one, both implemented for f64): an impl method's symbol is Type.method with no trait in it, so One.one and Unit1.one for f64 are one fn symbol with two bodies, and MIR reports "body index map mismatch for fn symbol N".
What the spec already rules. Trait names resolve through modules like every other name (D70: imports are namespaces). §11.4 (011_traits.md:147-152) makes a bare call ambiguous when two packages give a type the same method name, and the fully-qualified spelling pkg.method_name(value) disambiguates.
What the fix needs. (1) Trait identity is (declaring module, name), with impl sites resolving the trait name through D70 scope the way types do (named_type_candidate_head). (2) An impl method's symbol carries its trait (Type.Trait.method) so two traits' one on one type are two functions. (3) A bare x.one() with two candidates is the §11.4 ambiguity error. These touch Sema's trait tables, method symbols in MIR and codegen, and the trait-table audit.
The question: schedule it as its own campaign (my recommendation, since it is not a one-PR fix), or narrow it for the release to a loud error when a user trait shares a std trait's name?
Phase-3 fix campaign, 2026-10-26: both shapes re-reproduced on current main (dee141b79, installed with v0.15.3.0) — the user trait One still binds std's impl ("undefined variable self", "X.one is a function of the type"), and two traits with a method one on f64 still ICE ("body index map mismatch for fn symbol"). Root causes stand as located 2026-10-25 (Sema.trait_lookup keyed by bare name; impl method symbols carry no trait).
This is the multi-step trait/method-identity change, not a one-PR fix, so it stays human attn needed on do-before-release for scheduling: its own campaign, or a release-scoped loud error when a user trait shares a std trait's name?
Root causes: Ast.inherit_trait_impl_receivers took the first same-named NK_TRAIT_DECL (std's One) for a user's trait; method symbols were Owner.method, so two traits giving one type the same method collided in the MIR body map; trait_lookup was flat last-wins.
Fix (per ruling, #751 scoped to traits): traits keyed by (module, name) candidates; trait_idx_for_impl resolves from the impl's own module; impl method symbols are Owner.Trait.method (identity-hashed segment only when the trait name collides); (owner, trait, method) registries; a bare call with two candidates is the §11.4 ambiguity error. Battery follow-ups in the same PR: dyn global-effect bodies and async declaration take Sema's semantic symbol; multi-index lowering and drop-owner detection read Sema's registries, not symbol text.
Regression: test/behavior/behav_2520_{user_trait_shadows_std,two_traits_dispatch_by_bound,two_traits_instance_bound}.w, test/compile_errors/err_2520_ambiguous_bare_trait_method.w. Known remainder: dyn trait-object dispatch still resolves by bare name (pre-existing, #751).
Reopened 2026-10-28 on review of #2764 (main fc27c65e8, installed with v0.15.3.0-gfc27c65e8). Both original shapes are fixed, but a user trait still collides with a prelude trait, and the diagnostic's remedy has no spelling.
trait Unit1:
fn one() -> Self
impl Unit1 for f64:
fn one(): 2.0
fn main:
print(f64.one())
error: ambiguous trait method 'one' for type 'f64'; candidates: f64.One.one, f64.Unit1.one; name the trait through a bound (§11.4)
The user never imported One; it is std's prelude trait (lib/std/traits.w:45). §18.1/§18.2: a visible user declaration wins over a prelude name in its scope, so f64.one() here should be the user's Unit1.one, not an ambiguity.
The remedy names a bound, which a static call does not have. Unit1.one() ("undefined variable") and f64.Unit1.one() ("unknown field 'Unit1'") are both refused; only wrapping the call in fn get[T: Unit1]() -> T: T.one() works. A diagnostic whose remedy cannot be written is ceremony with no exit.
Also left by fix 2520 #2764 and not filed: dyn trait-object dispatch still resolves traits by bare name (find_dyn_trait_method_info), so a user trait named like a std trait still rebinds on the dyn path.
Expected: the prelude tier loses to the user's trait (§18.2 precedence), the §11.4 ambiguity applies only between candidates of equal precedence, and a qualified spelling exists for a static call.
Landed in stack #2797 (24222fe): #2795 — a program's trait outranks the prelude's of the same name (§18.2), the ambiguity chain keeps every candidate (it held two, so a third trait went unseen), and dyn Name resolves the trait by module through codegen (trait tables keyed by Sema's trait identity); #2798 — D169 Trait.method(args) (§11.4, words blessed) spells the choice between equal-rank traits, and the ambiguity error now names it. Found on the way: #2794, D143 now covers recursive methods.
Activity
ehartford commentedon Oct 21, 2026
Second shape, 2026-10-21: two traits each declaring a method named
one, both implemented forf64(std.traits'One.oneand a test'sUnit1.one), collide on thef64.onemethod symbol and MIR reports "body index map mismatch for fn symbol N" (two bodies for one symbol). Method identity is the bareType.methodname, not (trait, Type, method). The D140 fixture names its methodunituntil this is fixed.D140: an impl method takes its parameter types from the trait; a writ…
std: ListIter is a view of the list; the list-iterator intrinsics ret…
D103 at every demand site; D140 impl signatures from the trait; D141 …
ehartford commentedon Oct 25, 2026
Triage 2026-10-25,
with v0.15.3.0(main a261b65): reproduced, both shapes.pre-release: ordinary user traits collide with std names, one way with a wrong diagnostic and one with an internal error.
ehartford commentedon Oct 25, 2026
Fix campaign 2026-10-25: both root causes located; the fix is a multi-step change to trait and method identity, so it goes to Eric to schedule.
Shape 1 (a user trait named like std's
One):Sema.trait_lookup: HashMap[i32, i32](src/Sema.w:1007) maps a trait's bare name symbol to one trait index. A usertrait Oneandstd.traits.Oneare the same key, soimpl One for Xbinds to whichever registered last; the user impl is then checked against std'sfn one() -> Self(no receiver), giving "undefined variableself" and "X.oneis a function of the type". 24 reads oftrait_lookup(SemaDecl 10, Sema 5, SemaCheck 9) assume the name is the identity.Shape 2 (two traits with a method
one, both implemented forf64): an impl method's symbol isType.methodwith no trait in it, soOne.oneandUnit1.oneforf64are one fn symbol with two bodies, and MIR reports "body index map mismatch for fn symbol N".What the spec already rules. Trait names resolve through modules like every other name (D70: imports are namespaces). §11.4 (
011_traits.md:147-152) makes a bare call ambiguous when two packages give a type the same method name, and the fully-qualified spellingpkg.method_name(value)disambiguates.What the fix needs. (1) Trait identity is (declaring module, name), with impl sites resolving the trait name through D70 scope the way types do (
named_type_candidate_head). (2) An impl method's symbol carries its trait (Type.Trait.method) so two traits'oneon one type are two functions. (3) A barex.one()with two candidates is the §11.4 ambiguity error. These touch Sema's trait tables, method symbols in MIR and codegen, and the trait-table audit.The question: schedule it as its own campaign (my recommendation, since it is not a one-PR fix), or narrow it for the release to a loud error when a user trait shares a std trait's name?
ehartford commentedon Oct 27, 2026
Phase-3 fix campaign, 2026-10-26: both shapes re-reproduced on current main (
dee141b79, installedwith v0.15.3.0) — the usertrait Onestill binds std's impl ("undefined variableself", "X.oneis a function of the type"), and two traits with a methodoneonf64still ICE ("body index map mismatch for fn symbol"). Root causes stand as located 2026-10-25 (Sema.trait_lookupkeyed by bare name; impl method symbols carry no trait).This is the multi-step trait/method-identity change, not a one-PR fix, so it stays
human attn neededondo-before-releasefor scheduling: its own campaign, or a release-scoped loud error when a user trait shares a std trait's name?fix 2520 (#2764)
ehartford commentedon Oct 28, 2026
Fixed by #2764 (64ace83), battery-green on 4062c27 and merged.
Root causes: Ast.inherit_trait_impl_receivers took the first same-named NK_TRAIT_DECL (std's One) for a user's trait; method symbols were Owner.method, so two traits giving one type the same method collided in the MIR body map; trait_lookup was flat last-wins.
Fix (per ruling, #751 scoped to traits): traits keyed by (module, name) candidates; trait_idx_for_impl resolves from the impl's own module; impl method symbols are Owner.Trait.method (identity-hashed segment only when the trait name collides); (owner, trait, method) registries; a bare call with two candidates is the §11.4 ambiguity error. Battery follow-ups in the same PR: dyn global-effect bodies and async declaration take Sema's semantic symbol; multi-index lowering and drop-owner detection read Sema's registries, not symbol text.
Regression: test/behavior/behav_2520_{user_trait_shadows_std,two_traits_dispatch_by_bound,two_traits_instance_bound}.w, test/compile_errors/err_2520_ambiguous_bare_trait_method.w. Known remainder: dyn trait-object dispatch still resolves by bare name (pre-existing, #751).
ehartford commentedon Oct 28, 2026
Reopened 2026-10-28 on review of #2764 (main
fc27c65e8, installedwith v0.15.3.0-gfc27c65e8). Both original shapes are fixed, but a user trait still collides with a prelude trait, and the diagnostic's remedy has no spelling.One; it is std's prelude trait (lib/std/traits.w:45). §18.1/§18.2: a visible user declaration wins over a prelude name in its scope, sof64.one()here should be the user'sUnit1.one, not an ambiguity.Unit1.one()("undefined variable") andf64.Unit1.one()("unknown field 'Unit1'") are both refused; only wrapping the call infn get[T: Unit1]() -> T: T.one()works. A diagnostic whose remedy cannot be written is ceremony with no exit.find_dyn_trait_method_info), so a user trait named like a std trait still rebinds on thedynpath.Expected: the prelude tier loses to the user's trait (§18.2 precedence), the §11.4 ambiguity applies only between candidates of equal precedence, and a qualified spelling exists for a static call.
sema: D143 holds for methods and functions of a type: self.m(…) and O…
sema, codegen: a program's trait outranks the prelude's of the same n…
sema: a trait names its method as §11.4 names an extension's: Trait.m…
ehartford commentedon Oct 29, 2026
Landed in stack #2797 (24222fe): #2795 — a program's trait outranks the prelude's of the same name (§18.2), the ambiguity chain keeps every candidate (it held two, so a third trait went unseen), and
dyn Nameresolves the trait by module through codegen (trait tables keyed by Sema's trait identity); #2798 — D169Trait.method(args)(§11.4, words blessed) spells the choice between equal-rank traits, and the ambiguity error now names it. Found on the way: #2794, D143 now covers recursive methods.