diff --git a/selfhost/cmd/w6c/main.combined.ww b/selfhost/cmd/w6c/main.combined.ww index c1039f5e..d448cd45 100644 --- a/selfhost/cmd/w6c/main.combined.ww +++ b/selfhost/cmd/w6c/main.combined.ww @@ -7666,7 +7666,20 @@ fn exprtype(c: *checker, e: *node) *node = { if (callee.kind == nkind.N_IDENT) { nm = callee.str; }; if (callee.kind == nkind.N_DOT) { nm = callee.str; }; if (nm.len == 0) { return nil; }; - let s: *sym = scopelookup(c.cur, nm); + // #56: bare-leaf N_IDENT calls go through scopelookupprefer so + // `foo()` inside module M binds to M.foo rather than another + // module's same-leaf foo at the head of the flat scope bucket. + // Mirrors cstage cexpr N_IDENT routing through + // scope_lookup_prefer with c->cur_mod. N_DOT keeps the bare + // scopelookup — its module-qualified resolution is a separate + // gap (parser stores the leaf in callee.str; mod is in + // callee.lhs.str, not consumed here yet). + let s: *sym = nil; + if (callee.kind == nkind.N_IDENT) { + s = scopelookupprefer(c.cur, c.curmod, nm); + } else { + s = scopelookup(c.cur, nm); + }; if (s == nil) { return nil; }; if (s.skind != skind.SK_FN) { return nil; }; if (s.decl == nil) { return nil; }; diff --git a/selfhost/cmd/wcc/check.ww b/selfhost/cmd/wcc/check.ww index 3ded9f30..76a7712f 100644 --- a/selfhost/cmd/wcc/check.ww +++ b/selfhost/cmd/wcc/check.ww @@ -672,7 +672,20 @@ fn exprtype(c: *checker, e: *node) *node = { if (callee.kind == nkind.N_IDENT) { nm = callee.str; }; if (callee.kind == nkind.N_DOT) { nm = callee.str; }; if (nm.len == 0) { return nil; }; - let s: *sym = scopelookup(c.cur, nm); + // #56: bare-leaf N_IDENT calls go through scopelookupprefer so + // `foo()` inside module M binds to M.foo rather than another + // module's same-leaf foo at the head of the flat scope bucket. + // Mirrors cstage cexpr N_IDENT routing through + // scope_lookup_prefer with c->cur_mod. N_DOT keeps the bare + // scopelookup — its module-qualified resolution is a separate + // gap (parser stores the leaf in callee.str; mod is in + // callee.lhs.str, not consumed here yet). + let s: *sym = nil; + if (callee.kind == nkind.N_IDENT) { + s = scopelookupprefer(c.cur, c.curmod, nm); + } else { + s = scopelookup(c.cur, nm); + }; if (s == nil) { return nil; }; if (s.skind != skind.SK_FN) { return nil; }; if (s.decl == nil) { return nil; }; diff --git a/selfhost/cmd/wwdump/main.combined.ww b/selfhost/cmd/wwdump/main.combined.ww index 5b0ae1b4..c773f9c7 100644 --- a/selfhost/cmd/wwdump/main.combined.ww +++ b/selfhost/cmd/wwdump/main.combined.ww @@ -7666,7 +7666,20 @@ fn exprtype(c: *checker, e: *node) *node = { if (callee.kind == nkind.N_IDENT) { nm = callee.str; }; if (callee.kind == nkind.N_DOT) { nm = callee.str; }; if (nm.len == 0) { return nil; }; - let s: *sym = scopelookup(c.cur, nm); + // #56: bare-leaf N_IDENT calls go through scopelookupprefer so + // `foo()` inside module M binds to M.foo rather than another + // module's same-leaf foo at the head of the flat scope bucket. + // Mirrors cstage cexpr N_IDENT routing through + // scope_lookup_prefer with c->cur_mod. N_DOT keeps the bare + // scopelookup — its module-qualified resolution is a separate + // gap (parser stores the leaf in callee.str; mod is in + // callee.lhs.str, not consumed here yet). + let s: *sym = nil; + if (callee.kind == nkind.N_IDENT) { + s = scopelookupprefer(c.cur, c.curmod, nm); + } else { + s = scopelookup(c.cur, nm); + }; if (s == nil) { return nil; }; if (s.skind != skind.SK_FN) { return nil; }; if (s.decl == nil) { return nil; };