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
Same-named types in two modules: Self in a struct literal resolves to the other module's type; same-named methods collide (Item.total) #1457
Spec: §18.1 modules (each module's declarations are its own; an impl names its module's type). Related to #1446 (codegen layout), which the #1446 branch fixes; this is the Sema layer of the same situation.
Two modules each declare pub type Item. Inside module ca, Self in a struct literal resolves to the other module's Item:
use ca
use cb
fn main:
let a = new_a()
show_a(&a)
show_a(&a.twin_a())
Expected a 5 6 / a 6 5. On the #1446 branch: a 5 0 / a 0 0; on origin/main 1c76062: a 6 / a 5 (plus the #1446 layout collision). --dump-mir of Item.make_a: _0: ty235 (ca's Item) but the literal's temp is _1: ty236 (cb's Item) with fields const 5ty3, const 6ty3 — Sema recorded the struct literal Self { ... } as cb's type (the flat name map's newest Item), and the fields were typed against a struct that has no x/y. Spelling the literal Item { x: 5, y: 6 } gives the right answer.
Second symptom, same layer: a method name both impls declare collides. Give both Items a pub fn total() -> i64 and call each from its own module:
error: invalid MIR before codegen: body index map mismatch for fn symbol 778
Method symbols are Item.total for both declarations.
Expected: Self and method symbols are those of the impl's own declaration.
Verified on main (30f89aa, installed with = 1688728), with the issue's exact two-module program:
$ with run main.w
a 5 6
a 6 5
Symptom 1 (Self { .. } in a method body built the other module's Item) is fixed by f3005a6 (#1581): check_fn_body_with_sig_at binds Self to the method owner's declaration for the body.
Symptom 2 (same-named method on both Items, total) is no longer invalid MIR, but it is still refused, by design of that commit, with a located error:
error: method 'total' is declared for two different types named 'Item' (the other is in lib/ca.w); a method name shared by same-named types in two modules is not supported yet (#1457)
--> lib/cb.w:4:5
The remaining work is the method half of #1446's name$<tid> split: a method symbol must carry its owning declaration through Sema's owner-keyed method tables (lookup_method_sig, method_impl_nodes, method_owner_symbol_for_type) and codegen's function naming (two Item.total LLVM functions). Leaving open for that; the diagnostic cites this issue.
Activity
Codegen: each type declaration gets its own LLVM type; a name two mod…
Codegen: each type declaration gets its own LLVM type; a name two mod…
Codegen: each type declaration gets its own LLVM type; a name two mod…
Sema: `Self { .. }` in a method body is the method's own declaration;…
Sema: `Self { .. }` in a method body is the method's own declaration;…
ehartford commentedon Oct 2, 2026
Verified on main (30f89aa, installed
with= 1688728), with the issue's exact two-module program:Symptom 1 (
Self { .. }in a method body built the other module'sItem) is fixed by f3005a6 (#1581):check_fn_body_with_sig_atbindsSelfto the method owner's declaration for the body.Symptom 2 (same-named method on both
Items,total) is no longer invalid MIR, but it is still refused, by design of that commit, with a located error:The remaining work is the method half of #1446's
name$<tid>split: a method symbol must carry its owning declaration through Sema's owner-keyed method tables (lookup_method_sig,method_impl_nodes,method_owner_symbol_for_type) and codegen's function naming (twoItem.totalLLVM functions). Leaving open for that; the diagnostic cites this issue.behav_1457_same_named_method_two_types: the interim collision error b…
D65: methods and trait impls of same-named types are their declaratio…
ehartford commentedon Oct 3, 2026
Fixed on main by 0f0d76b (#2012, battery green on 6644771). audit:all over src/main.w: 13 violations → 0.
The LLVM backend reads a sizeof/alignof type argument from Sema inste…
The LLVM backend reads a sizeof/alignof type argument from Sema inste…
#1647 phases 2–4 completion: owner facts in codegen, per-instance Sem…
A method's owner is the key Sema registered it under, recorded per fu…
A method's owner is the key Sema registered it under, recorded per fu…
A method's owner is the key Sema registered it under, recorded per fu…
A method's owner is the key Sema registered it under, recorded per fu…
#2043: name-callee calls lower by Sema's resolved kind; sym_is_generi…
MirLower decides nothing from a name's spelling (#2043); each impl ha…
An interface's own mention demands its declaration; an impl's name re…
Migrated unit constants stay in their unit; a later global read by an…