Repository: go
Issue: x/tools/cmd/callgraph: calls to interface implementation not reported in cha callgraph
Labels: NeedsInvestigation,Tools

### Go version

go version go1.22.1 darwin/arm64

### Output of `go env` in your module/workspace:

```shell
GO111MODULE='auto'
GOARCH='arm64'
GOBIN=''
GOCACHE='/Users/usr/Library/Caches/go-build'
GOENV='/Users/usr/Library/Application Support/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='arm64'
GOHOSTOS='darwin'
GOINSECURE=''
GOMODCACHE='/Users/usr/pkg/mod'
GONOPROXY='github.com/redacted-org'
GONOSUMDB='github.com/redacted-org'
GOOS='darwin'
GOPATH='/Users/usr'
GOPRIVATE='github.com/redacted-org'
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/opt/homebrew/Cellar/go/1.22.1/libexec'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/opt/homebrew/Cellar/go/1.22.1/libexec/pkg/tool/darwin_arm64'
GOVCS=''
GOVERSION='go1.22.1'
GCCGO='gccgo'
AR='ar'
CC='cc'
CXX='c++'
CGO_ENABLED='1'
GOMOD='/Users/usr/src/github.com/samuknet/ssa-bug-report/go.mod'
GOWORK=''
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -ffile-prefix-map=/var/folders/q3/l93pryxj2dz39p1d2gy9v2p40000gn/T/go-build1879381070=/tmp/go-build -gno-record-gcc-switches -fno-common'
```


### What did you do?

1. Create example.go in a temporary package

```go
package example

func EntryPoint(ex exampleInterface) {
	ex.InterfaceFn()
}

type exampleInterface interface {
	InterfaceFn()
}

type exampleA struct{}

func (u *exampleA) InterfaceFn() {}

type exampleB struct{}

func (u *exampleB) InterfaceFn() {}

// NewA() returns an exampleA.  Note return type is exampleInterface.
// Results in exampleA.InterfaceFn() being added to the callgraph, as expected.
func NewA() exampleInterface {
	return &exampleA{}
}

// NewB() returns an exampleB. Note the return type is *exampleB.
// exampleB.InterfaceFn() is not included in the callgraph.
func NewB() *exampleB {
	return &exampleB{}
}
```

2. Install latest version of `callgraph`

```
go mod init
go get golang.org/x/tools/callgraph
    go: added golang.org/x/mod v0.16.0
    go: added golang.org/x/tools v0.19.0
go install golang.org/x/tools/cmd/callgraph
```
3. Run ` callgraph -algo=cha .` in the directory of `example.go`

 Output is
 ```
github.com/samuknet/ssa-bug-report.EntryPoint   --dynamic-9:16-->       (*github.com/samuknet/ssa-bug-report.exampleA).InterfaceFn
```

### What did you see happen?

Output includes just `exampleA.InterfaceFn()`:

```
github.com/samuknet/ssa-bug-report.EntryPoint   --dynamic-9:16-->       (*github.com/samuknet/ssa-bug-report.exampleA).InterfaceFn
```

### What did you expect to see?

Output to also include `exampleB.InterfaceFn()` in addition to `exampleA.InterfaceFn()`.


Note this report is similar to [this issue](https://github.com/golang/go/issues/66251),  but more specific to interfaces and reproduces regardless of whether the interface type is exported.

In particular:
-  if the function signature uses the interface as the return type, then the interface implementation is included in the callgraph. See `NewA()` example above.
- if the function signature uses the concrete struct as the return type, then the interface implementation is not included in the callgraph. See `NewB()` above.

The issue persists regardless of whether or not the interface type is exported.


**Findings so far**
We've identified [this commit](https://github.com/golang/tools/commit/9e94edb6139d29b241744a97ac806623c608cb8b) resulted in the change of behaviour.

Prior to this commit, the callgraph for `example.go` contains both interface implementations. After the commit it includes just `exampleA.InterfaceFn()` but not `exampleB.InterfaceFn()`. 

From the commit I can see  it's now expected for unexported types not to be included in the callgraph by default. Though I'd like to understand whether this change also intended to no longer include interface implementations in the callgraph in the example above.