Skip to content

x/tools/go/callgraph/cha: spurious callgraph edges to unexported functions #66689

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
jcd2 opened this issue Apr 5, 2024 · 1 comment
Closed
Labels
FixPending Issues that have a fix which has not yet been reviewed or submitted. FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done. Tools This label describes issues relating to any tools in the x/tools repository.
Milestone

Comments

@jcd2
Copy link

jcd2 commented Apr 5, 2024

When the cha library processes a method call on an interface value, it must calculate the concrete methods that it may call at runtime. It does this by finding all methods whose name matches the selector, and whose type satisfies the interface. The name matching is done using plain string equality, but this is not quite right, because unexported identifiers in different packages are always considered different, even if they are spelled the same.

Performing the string matching on the output of go/types.Id for the selector and method names would fix this.

See the test program in https://go.dev/cl/574955 for an example. There, a type S1 which embeds a types.Object, and a method order are defined:

type S1 struct {
        types.Object
        X int
}

func (s *S1) order(x int) int {
        return s.X + x
}

S1 satisfies the go/types.Object interface, but code in go/types that calls order on a types.Object value cannot call the order method of S1 defined here, it can only call an order method of the embedded types.Object which was defined in go/types.

@gopherbot gopherbot added the Tools This label describes issues relating to any tools in the x/tools repository. label Apr 5, 2024
@gopherbot gopherbot added this to the Unreleased milestone Apr 5, 2024
@gopherbot
Copy link
Contributor

Change https://go.dev/cl/574955 mentions this issue: go/callgraph/cha: more precise resolution of unexported methods

@dmitshur dmitshur added NeedsFix The path to resolution is known, but the work has not been done. FixPending Issues that have a fix which has not yet been reviewed or submitted. labels Apr 5, 2024
@golang golang locked and limited conversation to collaborators Apr 12, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FixPending Issues that have a fix which has not yet been reviewed or submitted. FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done. Tools This label describes issues relating to any tools in the x/tools repository.
Projects
None yet
Development

No branches or pull requests

3 participants