dominikh / go-tools

Staticcheck - The advanced Go linter
https://staticcheck.dev
MIT License
6.22k stars 377 forks source link

Panic in the ir.(*Program).needMethods with v5.0 #1587

Open hawkingrei opened 3 months ago

hawkingrei commented 3 months ago
ERROR: /root/.cache/bazel/_bazel_root/37ff7b0eddea115f60ab9f853788d7f5/external/com_github_google_renameio_v2/BUILD.bazel:3:11: GoCompilePkg external/com_github_google_renameio_v2/renameio.a failed: (Exit 1): builder failed: error executing command (from target @com_github_google_renameio_v2//:renameio) bazel-out/k8-opt-exec-2B5CBBC6-ST-00bca8d33aad/bin/external/go_sdk/builder_reset/builder compilepkg -sdk external/go_sdk -installsuffix linux_amd64_race -tags race -src ... (remaining 31 arguments skipped)
compilepkg: panic: internal error: unhandled case *types.Alias
goroutine 552 [running]:
honnef.co/go/tools/analysis/lint.ExhaustiveTypeSwitch(...)
    external/co_honnef_go_tools/analysis/lint/lint.go:242
honnef.co/go/tools/go/ir.(*Program).needMethods(0xc0010422a0, {0x4f5788, 0xc001113c80}, 0x0)
    external/co_honnef_go_tools/go/ir/methods.go:239 +0x579
honnef.co/go/tools/go/ir.(*Program).needMethods(0xc0010422a0, {0x4f5710, 0xc00069ff20}, 0x0)
    external/co_honnef_go_tools/go/ir/methods.go:235 +0x687
honnef.co/go/tools/go/ir.(*Program).needMethods(0xc0010422a0, {0x4f5738, 0xc001078a80}, 0x0)
    external/co_honnef_go_tools/go/ir/methods.go:211 +0x419
honnef.co/go/tools/go/ir.(*Program).needMethodsOf(0xc0010422a0, {0x4f5738?, 0xc001078a80?})
    external/co_honnef_go_tools/go/ir/methods.go:148 +0x70
honnef.co/go/tools/go/ir.(*Package).build(0xc000b30c60)
    external/co_honnef_go_tools/go/ir/builder.go:2579 +0xf6
sync.(*Once).doSlow(0xc0010422a0?, 0xc0003577a0?)
    bazel-out/k8-opt-exec-2B5CBBC6-ST-e4bf93cdf86e/bin/external/io_bazel_rules_go/stdlib_/src/sync/once.go:76 +0xb4
sync.(*Once).Do(...)
    bazel-out/k8-opt-exec-2B5CBBC6-ST-e4bf93cdf86e/bin/external/io_bazel_rules_go/stdlib_/src/sync/once.go:67
honnef.co/go/tools/go/ir.(*Package).Build(...)
    external/co_honnef_go_tools/go/ir/builder.go:2567
honnef.co/go/tools/internal/passes/buildir.run(0xc0010421c0)
    external/co_honnef_go_tools/internal/passes/buildir/buildir.go:86 +0x18b
main.(*action).execOnce(0xc000b6c3c0)
    external/io_bazel_rules_go/go/tools/builders/nogo_main.go:354 +0x8b7
sync.(*Once).doSlow(0x0?, 0x0?)
    bazel-out/k8-opt-exec-2B5CBBC6-ST-e4bf93cdf86e/bin/external/io_bazel_rules_go/stdlib_/src/sync/once.go:76 +0xb4
sync.(*Once).Do(...)
    bazel-out/k8-opt-exec-2B5CBBC6-ST-e4bf93cdf86e/bin/external/io_bazel_rules_go/stdlib_/src/sync/once.go:67
main.(*action).exec(...)
    external/io_bazel_rules_go/go/tools/builders/nogo_main.go:281
main.execAll.func1(0x0?)
    external/io_bazel_rules_go/go/tools/builders/nogo_main.go:275 +0x65
created by main.execAll in goroutine 437
    external/io_bazel_rules_go/go/tools/builders/nogo_main.go:273 +0x48
ERROR: /home/prow/go/src/github.com/pingcap/tidb/tests/realtikvtest/importintotest/BUILD.bazel:3:8 GoCompilePkgExternal tests/realtikvtest/importintotest/importintotest_test_test.external.a failed: (Exit 1): builder failed: error executing command (from target @com_github_google_renameio_v2//:renameio) bazel-out/k8-opt-exec-2B5CBBC6-ST-00bca8d33aad/bin/external/go_sdk/builder_reset/builder compilepkg -sdk external/go_sdk -installsuffix linux_amd64_race -tags race -src ... (remaining 31 arguments skipped) 

https://tiprow.hawkingrei.com/view/gs/pingcapprow/pr-logs/pull/pingcap_tidb/51126/fast_test_tiprow/1823540729058693120

hawkingrei commented 3 months ago

It runs with go1.23

dominikh commented 3 months ago

Please provide

EsterfanoLopes commented 3 months ago

Same here. Does not look to be a problem with go 1.22.6 though. The given panics only appears when running go 1.23.0

staticcheck -debug.version

staticcheck 2024.1.1 (0.5.1)

Compiled with Go version: go1.23.0
Main module:
        honnef.co/go/tools@v0.5.1 (sum: h1:4bH5o3b5ZULQ4UrBmP+63W9r7qIkqJClEA9ko5YKx+I=)
Dependencies:
        github.com/BurntSushi/toml@v1.4.1-0.20240526193622-a339e1f7089c (sum: h1:pxW6RcqyfI9/kWtOwnv/G+AzdKuy2ZrqINhenH4HyNs=)
        golang.org/x/exp/typeparams@v0.0.0-20231108232855-2478ac86f678 (sum: h1:1P7xPZEwZMoBoz0Yze5Nx2/4pxj6nw9ZqHWXqP0iRgQ=)
        golang.org/x/mod@v0.17.0 (sum: h1:zY54UmvipHiNd+pm+m0x9KhZ9hl1/7QNMyxXbc6ICqA=)
        golang.org/x/sync@v0.7.0 (sum: h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M=)
        golang.org/x/tools@v0.21.1-0.20240531212143-b6235391adb3 (sum: h1:SHq4Rl+B7WvyM4XODon1LXtP7gcG49+7Jubt1gWWswY=)

go version go version go1.23.0 darwin/arm64

go env

GO111MODULE=''
GOARCH='arm64'
GOBIN='/Users/esterfano.lopes/go/bin'
GOCACHE='/Users/esterfano.lopes/Library/Caches/go-build'
GOENV='/Users/esterfano.lopes/Library/Application Support/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='arm64'
GOHOSTOS='darwin'
GOINSECURE=''
GOMODCACHE='/Users/esterfano.lopes/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='darwin'
GOPATH='/Users/esterfano.lopes/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/Users/esterfano.lopes/sdk/go1.23.0'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/Users/esterfano.lopes/sdk/go1.23.0/pkg/tool/darwin_arm64'
GOVCS=''
GOVERSION='go1.23.0'
GODEBUG=''
GOTELEMETRY='local'
GOTELEMETRYDIR='/Users/esterfano.lopes/Library/Application Support/go/telemetry'
GCCGO='gccgo'
GOARM64='v8.0'
AR='ar'
CC='clang'
CXX='clang++'
CGO_ENABLED='1'
GOMOD='/Users/esterfano.lopes/Development/motain/news/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/6d/_lcfw1qd03d822wbyxv7dj800000gq/T/go-build1989325247=/tmp/go-build -gno-record-gcc-switches -fno-common'
lesiw commented 3 months ago

This seems to be happening because of the new *types.Alias type.

By default, go/types now produces Alias type nodes for type aliases. This behavior can be controlled by the GODEBUG gotypesalias flag. Its default has changed from 0 in Go 1.22 to 1 in Go 1.23.

- Go 1.23 release notes

You should be able to work around it by setting GODEBUG=gotypesalias=0.

dominikh commented 3 months ago

It'd also be useful to have a minimal reproducer for this problem, because Staticcheck 2024.1 is supposed to handle the new type.