Skip to content

Go same-file member calls can resolve to a method on the wrong receiver type #4962

Closed

Description

@xiongjianxu

Tested on v8 at 32e5efe.

package demo

type A struct{}
type B struct{}
func (*A) apply() {}
func (*B) apply() {}
func Use(a *A) { a.apply() }

Extracting this file produces Use -> B.apply with confidence=EXTRACTED. Reversing the two method declarations changes the target to A.apply.

Expected: Use resolves to A.apply through the declared receiver type, independently of declaration order. An unknown receiver or a receiver whose type does not define the method must not bind to an unrelated same-named method.

The per-file label_to_nid table includes methods and overwrites entries by bare name. The same-file fast path emits an edge before the receiver-aware resolver can inspect the call. Bare calls to package-level functions can also be captured by a same-named method in this table.

This is separate from package-qualified type resolution: the reproducer uses one file and local types only.

Activity

  1. github-actions commented on Nov 3, 2026

    @github-actions

    Thanks for opening this issue, @xiongjianxu. A maintainer will take a look soon.

    If you would like to discuss it in real time, come say hi on our Discord server. For longer-form questions and ideas there is also GitHub Discussions.

    To help us triage, please make sure the report includes what you expected, what actually happened, and the steps (and a small sample) to reproduce it.

  2. safishamsi commented on Nov 3, 2026

    @safishamsi
    Member

    Fixed in 0.9.102 (published to PyPI) via #4966. A Go same-file member call now resolves through the receiver's type instead of a declaration-order-dependent same-named method.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions