Skip to content

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

@jcd2

Description

@jcd2

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    FixPendingIssues that have a fix which has not yet been reviewed or submitted.FrozenDueToAgeNeedsFixThe path to resolution is known, but the work has not been done.ToolsThis label describes issues relating to any tools in the x/tools repository.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions