go: x/tools: nilness panics "no concrete method"

What version of Go are you using (go version)?

$ go version
go version go1.20 linux/amd64

Does this issue reproduce with the latest release?

Yes, having installed with go install golang.org/x/tools/go/analysis/passes/nilness/cmd/nilness@latest:

go version -m $(which nilness)
/go/bin/nilness: go1.20
	path	golang.org/x/tools/go/analysis/passes/nilness/cmd/nilness
	mod	golang.org/x/tools	v0.5.0	h1:+bSpV5HIeWkuvgaMfI3UmKRThoTA5ODJTUd8T17NO+4=
	dep	golang.org/x/mod	v0.7.0	h1:LapD9S96VoQRhi/GrNTqeBJFrUjs5UHCAtTlgwA5oZA=
	dep	golang.org/x/sys	v0.4.0	h1:Zr2JFtRQNX3BCZ8YtxRE9hNJYC8J6I1MVbMg6owUp18=
	build	-buildmode=exe
	build	-compiler=gc
	build	CGO_ENABLED=1
	build	CGO_CFLAGS=
	build	CGO_CPPFLAGS=
	build	CGO_CXXFLAGS=
	build	CGO_LDFLAGS=
	build	GOARCH=amd64
	build	GOOS=linux
	build	GOAMD64=v1

I’ve also tried with @master (golang.org/x/tools v0.5.1-0.20230202234227-811111804389)

What operating system and processor architecture are you using (go env)?

I am on an Intel Mac, but I am running this in a container in a Linux VM. This also happens in a container running on Linux directly.

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/root/.cache/go-build"
GOENV="/root/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/opt/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/opt/go/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.20"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/tmp/test/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 -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build2170370967=/tmp/go-build -gno-record-gcc-switches"

What did you do?

As part of a CI process, we run nilness ./... over a project’s sources. For three different applications we hit this panic. In all three cases they are panicking on a method inside of google.golang.org/protobuf but the exact package and method varies. So far we’ve seen it on:

func (google.golang.org/protobuf/encoding/protowire.Number).IsValid() bool
func (google.golang.org/protobuf/reflect/protoreflect.Cardinality).GoString() string
A full panic
nilness ./...
panic: no concrete method: func (google.golang.org/protobuf/reflect/protoreflect.Cardinality).GoString() string

goroutine 2017 [running]:
golang.org/x/tools/go/ssa.(*Program).declaredFunc(0xc002032000, 0xc00158df80)
	/go/pkg/mod/golang.org/x/tools@v0.5.0/go/ssa/methods.go:149 +0xf9
golang.org/x/tools/go/ssa.(*Program).originFunc(0xc002549450?, 0xc004828868?)
	/go/pkg/mod/golang.org/x/tools@v0.5.0/go/ssa/source.go:193 +0x32
golang.org/x/tools/go/ssa.(*Program).addMethod(0xc002032000, 0xc0044248c0, 0xc002549450, 0x71b0e0?)
	/go/pkg/mod/golang.org/x/tools@v0.5.0/go/ssa/methods.go:109 +0x18c
golang.org/x/tools/go/ssa.(*Program).needMethods(0xc002032000, {0x7f8088?, 0xc0012fbf80?}, 0x0, 0x9ad620?)
	/go/pkg/mod/golang.org/x/tools@v0.5.0/go/ssa/methods.go:200 +0x705
golang.org/x/tools/go/ssa.(*Program).needMethods(0xc002032000, {0x7f8178?, 0xc00037b380?}, 0x0, 0x9ad620?)
	/go/pkg/mod/golang.org/x/tools@v0.5.0/go/ssa/methods.go:260 +0x5ae
golang.org/x/tools/go/ssa.(*Program).needMethods(0xc002032000, {0x7f8088?, 0xc0012fbf10?}, 0x0, 0x9ad620?)
	/go/pkg/mod/golang.org/x/tools@v0.5.0/go/ssa/methods.go:209 +0x1f7
golang.org/x/tools/go/ssa.(*Program).needMethods(0xc002032000, {0x7f8178?, 0xc00037be30?}, 0x0, 0x9ad620?)
	/go/pkg/mod/golang.org/x/tools@v0.5.0/go/ssa/methods.go:260 +0x5ae
golang.org/x/tools/go/ssa.(*Program).needMethods(0xc002032000, {0x7f8088?, 0xc0012fbea0?}, 0x0, 0x9ad620?)
	/go/pkg/mod/golang.org/x/tools@v0.5.0/go/ssa/methods.go:208 +0x1d0
golang.org/x/tools/go/ssa.(*Program).needMethods(0xc002032000, {0x7f8178?, 0xc000c595d8?}, 0x0, 0x9ad620?)
	/go/pkg/mod/golang.org/x/tools@v0.5.0/go/ssa/methods.go:260 +0x5ae
golang.org/x/tools/go/ssa.(*Program).needMethods(0xc002032000, {0x7f80d8?, 0xc000fb3e40?}, 0x0, 0x9ad620?)
	/go/pkg/mod/golang.org/x/tools@v0.5.0/go/ssa/methods.go:209 +0x1f7
golang.org/x/tools/go/ssa.(*Program).needMethods(0xc002032000, {0x7f8178?, 0xc000c59728?}, 0x0, 0x9ad620?)
	/go/pkg/mod/golang.org/x/tools@v0.5.0/go/ssa/methods.go:260 +0x5ae
golang.org/x/tools/go/ssa.(*Program).needMethods(0xc002032000, {0x7f80d8?, 0xc000fb3fb0?}, 0x0, 0x9ad620?)
	/go/pkg/mod/golang.org/x/tools@v0.5.0/go/ssa/methods.go:209 +0x1f7
golang.org/x/tools/go/ssa.(*Program).needMethods(0xc002032000, {0x7f8178?, 0xc000c59818?}, 0x0, 0x9ad620?)
	/go/pkg/mod/golang.org/x/tools@v0.5.0/go/ssa/methods.go:260 +0x5ae
golang.org/x/tools/go/ssa.(*Program).needMethods(0xc002032000, {0x7f80d8?, 0xc000e28a10?}, 0x0, 0x9ad620?)
	/go/pkg/mod/golang.org/x/tools@v0.5.0/go/ssa/methods.go:209 +0x1f7
golang.org/x/tools/go/ssa.(*Program).needMethods(0xc002032000, {0x7f8178?, 0xc000c59e78?}, 0x0, 0x9ad620?)
	/go/pkg/mod/golang.org/x/tools@v0.5.0/go/ssa/methods.go:260 +0x5ae
golang.org/x/tools/go/ssa.(*Program).needMethods(0xc002032000, {0x7f80d8?, 0xc000e28a90?}, 0x0, 0x9ad620?)
	/go/pkg/mod/golang.org/x/tools@v0.5.0/go/ssa/methods.go:209 +0x1f7
golang.org/x/tools/go/ssa.(*Program).needMethods(0xc002032000, {0x7f8178?, 0xc000c59ef0?}, 0x0, 0x9ad620?)
	/go/pkg/mod/golang.org/x/tools@v0.5.0/go/ssa/methods.go:260 +0x5ae
golang.org/x/tools/go/ssa.(*Program).needMethods(0xc002032000, {0x7f8088?, 0xc0012fb260?}, 0x0, 0x9ad620?)
	/go/pkg/mod/golang.org/x/tools@v0.5.0/go/ssa/methods.go:208 +0x1d0
golang.org/x/tools/go/ssa.(*Program).needMethods(0xc002032000, {0x7f8010?, 0xc000c59f50?}, 0x0, 0x9ad620?)
	/go/pkg/mod/golang.org/x/tools@v0.5.0/go/ssa/methods.go:226 +0x30f
golang.org/x/tools/go/ssa.(*Program).needMethods(0xc002032000, {0x7f8178?, 0xc000c59f68?}, 0x0, 0x9ad620?)
	/go/pkg/mod/golang.org/x/tools@v0.5.0/go/ssa/methods.go:260 +0x5ae
golang.org/x/tools/go/ssa.(*Program).needMethods(0xc002032000, {0x7f8088?, 0xc0012fb1f0?}, 0x0, 0x9ad620?)
	/go/pkg/mod/golang.org/x/tools@v0.5.0/go/ssa/methods.go:208 +0x1d0
golang.org/x/tools/go/ssa.(*Program).needMethods(0xc002032000, {0x7f8178?, 0xc001534ab0?}, 0x0, 0x9ad620?)
	/go/pkg/mod/golang.org/x/tools@v0.5.0/go/ssa/methods.go:260 +0x5ae
golang.org/x/tools/go/ssa.(*Program).needMethods(0xc002032000, {0x7f80d8?, 0xc0041f40c0?}, 0x0, 0x9ad620?)
	/go/pkg/mod/golang.org/x/tools@v0.5.0/go/ssa/methods.go:208 +0x1d0
golang.org/x/tools/go/ssa.(*Program).needMethods(0xc002032000, {0x7f8088?, 0xc0019b4690?}, 0x0, 0xc0008178c0?)
	/go/pkg/mod/golang.org/x/tools@v0.5.0/go/ssa/methods.go:242 +0x458
golang.org/x/tools/go/ssa.(*Program).needMethodsOf(0xc002032000, {0x7f8088?, 0xc0019b4690?}, 0x624c508726b89f64?)
	/go/pkg/mod/golang.org/x/tools@v0.5.0/go/ssa/methods.go:172 +0x7f
golang.org/x/tools/go/ssa.(*Package).build(0xc0041e4600)
	/go/pkg/mod/golang.org/x/tools@v0.5.0/go/ssa/builder.go:2501 +0x13f
sync.(*Once).doSlow(0xc002032000?, 0xc0012d7810?)
	/opt/go/src/sync/once.go:74 +0xc2
sync.(*Once).Do(...)
	/opt/go/src/sync/once.go:65
golang.org/x/tools/go/ssa.(*Package).Build(...)
	/go/pkg/mod/golang.org/x/tools@v0.5.0/go/ssa/builder.go:2477
golang.org/x/tools/go/analysis/passes/buildssa.run(0xc002030000)
	/go/pkg/mod/golang.org/x/tools@v0.5.0/go/analysis/passes/buildssa/buildssa.go:72 +0x1a8
golang.org/x/tools/go/analysis/internal/checker.(*action).execOnce(0xc0017268c0)
	/go/pkg/mod/golang.org/x/tools@v0.5.0/go/analysis/internal/checker/checker.go:725 +0x9ec
sync.(*Once).doSlow(0x0?, 0x0?)
	/opt/go/src/sync/once.go:74 +0xc2
sync.(*Once).Do(...)
	/opt/go/src/sync/once.go:65
golang.org/x/tools/go/analysis/internal/checker.(*action).exec(0x0?)
	/go/pkg/mod/golang.org/x/tools@v0.5.0/go/analysis/internal/checker/checker.go:641 +0x3d
golang.org/x/tools/go/analysis/internal/checker.execAll.func1(0x0?)
	/go/pkg/mod/golang.org/x/tools@v0.5.0/go/analysis/internal/checker/checker.go:629 +0x25
created by golang.org/x/tools/go/analysis/internal/checker.execAll
	/go/pkg/mod/golang.org/x/tools@v0.5.0/go/analysis/internal/checker/checker.go:635 +0x165

~I haven’t yet been able to reduce it to a sharable test case.~ A minimal test case is below. Simply using those types above doesn’t trigger it.

In the application that panics with func (google.golang.org/protobuf/reflect/protoreflect.Cardinality).GoString() string, in its go.mod is google.golang.org/protobuf v1.26.0 // indirect.

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Reactions: 1
  • Comments: 19 (17 by maintainers)

Commits related to this issue

Most upvoted comments

Change https://go.dev/cl/465936 mentions this issue: internal/gcimporter: compute imports for unified IR