Repository navigation
Sema: Self { .. } in a method body is the method's own declaration; a same-named method on two same-named types is a located error, not invalid MIR (#1457, part) - #1581
Merged
ehartford merged 1 commit intoSep 24, 2026
Conversation
… a same-named method on two same-named types is a located error, not invalid MIR (#1457, part) Two modules each declare `pub type Item`. In module a's `impl Item`, the literal `Self { x: 5, y: 6 }` was built as module b's `Item` (`a 5 0` after #1446; `a 6` before it). `--dump-mir` showed `_0: ty235` (a's Item) but the literal's temp `_1: ty236` (b's). Root cause. SemaCheck.check_struct_literal types a `Self` literal from `named_types[Self]`, which only collect_fn_decl binds, for the signature, and unbinds before the bodies are checked (SemaDecl.w:1784). check_fn_body_with_sig_at never bound it, so in a body the literal came back untyped: `analyze` shows the node as `type=<error>`, and no error was emitted (the `pool_resolve(name) != "Self"` guard skipped it). MirLower then resolved the untyped literal BY NAME (MirLower.w:2386-2398), through the flat named_types map, which holds the newest declaration of that name in any module: cb's Item. Fix. check_fn_body_with_sig_at binds `Self` to the method owner's type visible from the body's module (method_decl_owner_symbol + lookup_named_type_visible, after update_decl_source_context) for the duration of the body and restores it after, for non-generic owners; a generic owner's methods are checked per instantiation with `Self` in the substitution (check_fn_body_concrete), and binding the template there made `Cell.wrap -> Self: Self { value }` a return type mismatch (issue61_query_method_cache_keys). A `Self` literal with no binding is now an error, never a silent untyped node. The method-symbol collision (both impls declare `total`, one symbol `Item.total`, the later declaration shadowed the earlier and its body was skipped, "invalid MIR before codegen: body index map mismatch for fn symbol N") is reported at the second declaration with both modules named ("method 'total' is declared for two different types named 'Item' ... not supported yet (#1457)") instead of the ICE. It is NOT fixed: a method's symbol must carry its owning declaration (the method half of #1446's `name$<tid>` split) through Sema's owner-keyed method tables (lookup_method_sig, method_impl_nodes, method_owner_symbol_for_type) and codegen's function naming, where two `Item.total` LLVM functions would also collide. That is its own change. Matrix (stage1 before -> after): a.twin_a() `a 0 0` -> `a 6 5`; new_a() `a 5 0` -> `a 5 6`; b's twin_b/make_b unchanged and right; two types with Self literals in one module unchanged; generic owner `Self { value }` unchanged; same-named `total` on both: ICE -> located error. `stage1 check src/main.w`: ok. The impl/method/module/self/trait/extension test list (84 files) passes except behav_migrate_module_paths, which fails the same way on the layer below. examples/ and the UAT fixtures check the same as on the base. Fixtures: behav_1457_self_literal_own_module_type (lib/issue1457/{ca,cb}), err_1457_same_named_method_two_types (lib/issue1457/{ma,mb}).
Self { .. } in a method body is the method's own declaration; a same-named method on two same-named types is a located error, not invalid MIR (#1457, part)
This was referenced Sep 23, 2026
Contributor
Author
|
Stack #1582 battery (seed-driven, new seed, cold c_import cache, with :drop-audit/:move-audit) on main 02301f8 + #1571 → … → #1581 (head dca1a8f; every PR head is a tested commit): build ok, :fixpoint ok, :drop-audit ok, :move-audit ok, :test ok (no reds), :test-green ok, :last-green ok. Merges cleanly into main. Merge the stack: |
ehartford
marked this pull request as ready for review
September 23, 2026 22:04
This was referenced Sep 23, 2026
ehartford
added a commit
that referenced
this pull request
Sep 24, 2026
…uilt Vec[i32]; main red at stage2 after #1546 + #1581 (#1596) * MIR: the three switch tables built from Vec[i32] take Vec[i64] — discriminants are i64 end to end (#1541) and the width check (#1368) now rejects the narrowed table; main was red at stage2 * drop-audit: the field_join_view match cell indents its arms under the match — the seed parsed the flush arms by accident; §29.13 (#1391) rejects them * MirValidationTests: the last switch table built from Vec[i32] takes Vec[i64] — the internals tests compile this file, src/main.w does not --------- Co-authored-by: Eric Hartford <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Two modules each declare
pub type Item. In module a'simpl Item, theliteral
Self { x: 5, y: 6 }was built as module b'sItem(a 5 0after #1446;
a 6before it).--dump-mirshowed_0: ty235(a'sItem) but the literal's temp
_1: ty236(b's).Root cause. SemaCheck.check_struct_literal types a
Selfliteral fromnamed_types[Self], which only collect_fn_decl binds, for the signature,and unbinds before the bodies are checked (SemaDecl.w:1784).
check_fn_body_with_sig_at never bound it, so in a body the literal came
back untyped:
analyzeshows the node astype=<error>, and no errorwas emitted (the
pool_resolve(name) != "Self"guard skipped it). MirLowerthen resolved the untyped literal BY NAME (MirLower.w:2386-2398), through
the flat named_types map, which holds the newest declaration of that
name in any module: cb's Item.
Fix. check_fn_body_with_sig_at binds
Selfto the method owner's typevisible from the body's module (method_decl_owner_symbol +
lookup_named_type_visible, after update_decl_source_context) for the
duration of the body and restores it after, for non-generic owners; a
generic owner's methods are checked per instantiation with
Selfin thesubstitution (check_fn_body_concrete), and binding the template there
made
Cell.wrap -> Self: Self { value }a return type mismatch(issue61_query_method_cache_keys). A
Selfliteral with no binding isnow an error, never a silent untyped node.
The method-symbol collision (both impls declare
total, one symbolItem.total, the later declaration shadowed the earlier and its bodywas skipped, "invalid MIR before codegen: body index map mismatch for fn
symbol N") is reported at the second declaration with both modules named
("method 'total' is declared for two different types named 'Item' ...
not supported yet (#1457)") instead of the ICE. It is NOT fixed: a
method's symbol must carry its owning declaration (the method half of
#1446's
name$<tid>split) through Sema's owner-keyed method tables(lookup_method_sig, method_impl_nodes, method_owner_symbol_for_type) and
codegen's function naming, where two
Item.totalLLVM functions wouldalso collide. That is its own change.
Matrix (stage1 before -> after): a.twin_a()
a 0 0->a 6 5; new_a()a 5 0->a 5 6; b's twin_b/make_b unchanged and right; two types withSelf literals in one module unchanged; generic owner
Self { value }unchanged; same-named
totalon both: ICE -> located error.stage1 check src/main.w: ok. The impl/method/module/self/trait/extension testlist (84 files) passes except behav_migrate_module_paths, which fails the
same way on the layer below. examples/ and the UAT fixtures check the
same as on the base.
Fixtures: behav_1457_self_literal_own_module_type (lib/issue1457/{ca,cb}),
err_1457_same_named_method_two_types (lib/issue1457/{ma,mb}).
Stack #1582, layer 11/11. Draft until the batch battery is green (D56).