Closed
Description
modernize version
Installed modernize from commit 32ffaa3103522a0b05609e241d1b03b3b1abb9a6
$ modernize -V=full
/home/bmitch/data/golang/bin/modernize version devel comments-go-here buildID=45c8ca27715001da385a0579ed0e2a1f2def3a74abef28343cce339b6aa5032b
go env
$ go env
AR='ar'
CC='gcc'
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_ENABLED='1'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
CXX='g++'
GCCGO='gccgo'
GO111MODULE=''
GOAMD64='v1'
GOARCH='amd64'
GOAUTH='netrc'
GOBIN=''
GOCACHE='/home/bmitch/.cache/go-build'
GOCACHEPROG=''
GODEBUG=''
GOENV='/home/bmitch/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFIPS140='off'
GOFLAGS=''
GOGCCFLAGS='-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build1555326513=/tmp/go-build -gno-record-gcc-switches'
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMOD='/home/bmitch/data/git/go.googlesource.com/tools/gopls/go.mod'
GOMODCACHE='/home/bmitch/data/golang/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='linux'
GOPATH='/home/bmitch/data/golang'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/home/bmitch/sdk/go1.24.0'
GOSUMDB='sum.golang.org'
GOTELEMETRY='on'
GOTELEMETRYDIR='/home/bmitch/.config/go/telemetry'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/home/bmitch/sdk/go1.24.0/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='go1.24.0'
GOWORK=''
PKG_CONFIG='pkg-config'
What did you do?
Running modernize
from the master branch on my project github.com/regclient/regclient. I believe it is breaking on the following:
sort.Slice(keys, func(a, b int) bool {
if ip.entries[keys[a]].state != ip.entries[keys[b]].state {
return ip.entries[keys[a]].state > ip.entries[keys[b]].state
} else if ip.entries[keys[a]].state != types.CallbackActive {
return ip.entries[keys[a]].last.Before(ip.entries[keys[b]].last)
} else {
return ip.entries[keys[a]].cur > ip.entries[keys[b]].cur
}
})
What did you see happen?
$ modernize ./...
panic: interface conversion: ast.Stmt is *ast.IfStmt, not *ast.ReturnStmt
goroutine 912 [running]:
golang.org/x/tools/gopls/internal/analysis/modernize.sortslice.func1(0xc0016d05a0, 0xc002cec400)
/home/bmitch/data/git/go.googlesource.com/tools/gopls/internal/analysis/modernize/sortslice.go:60 +0x878
golang.org/x/tools/gopls/internal/analysis/modernize.sortslice.sortslice.filesUsing.func2.sortslice.sortslice.filesUsing.func2.Cursor.Children.func3.sortslice.sortslice.filesUsing.func2-range3.sortslice-range1-range4({0xc0039414b8?, 0x702aa5?})
/home/bmitch/data/git/go.googlesource.com/tools/gopls/internal/analysis/modernize/sortslice.go:110 +0x62
golang.org/x/tools/internal/astutil/cursor.Cursor.Preorder.func1(0xc005cfd480)
/home/bmitch/data/git/go.googlesource.com/tools/internal/astutil/cursor/cursor.go:98 +0xaf
golang.org/x/tools/gopls/internal/analysis/modernize.sortslice-range1(...)
/home/bmitch/data/git/go.googlesource.com/tools/gopls/internal/analysis/modernize/sortslice.go:108
golang.org/x/tools/gopls/internal/analysis/modernize.sortslice.sortslice.filesUsing.func2-range3(...)
/home/bmitch/data/git/go.googlesource.com/tools/gopls/internal/analysis/modernize/modernize.go:121
golang.org/x/tools/gopls/internal/analysis/modernize.sortslice.sortslice.filesUsing.func2.Cursor.Children.func3(...)
/home/bmitch/data/git/go.googlesource.com/tools/internal/astutil/cursor/cursor.go:364
golang.org/x/tools/gopls/internal/analysis/modernize.sortslice.filesUsing.func2(...)
/home/bmitch/data/git/go.googlesource.com/tools/gopls/internal/analysis/modernize/modernize.go:119
golang.org/x/tools/gopls/internal/analysis/modernize.sortslice(0xc0039487e0)
/home/bmitch/data/git/go.googlesource.com/tools/gopls/internal/analysis/modernize/sortslice.go:105 +0x312
golang.org/x/tools/gopls/internal/analysis/modernize.run(0xc0039487e0)
/home/bmitch/data/git/go.googlesource.com/tools/gopls/internal/analysis/modernize/modernize.go:74 +0x1a5
golang.org/x/tools/go/analysis/checker.(*Action).execOnce.func3(...)
/home/bmitch/data/git/go.googlesource.com/tools/go/analysis/checker/checker.go:367
golang.org/x/tools/go/analysis/checker.(*Action).execOnce(0xc005da34a0)
/home/bmitch/data/git/go.googlesource.com/tools/go/analysis/checker/checker.go:388 +0xad0
sync.(*Once).doSlow(0x0?, 0x0?)
/home/bmitch/sdk/go1.24.0/src/sync/once.go:78 +0xab
sync.(*Once).Do(...)
/home/bmitch/sdk/go1.24.0/src/sync/once.go:69
golang.org/x/tools/go/analysis/checker.(*Action).exec(...)
/home/bmitch/data/git/go.googlesource.com/tools/go/analysis/checker/checker.go:265
golang.org/x/tools/go/analysis/checker.execAll.func1(0x0?)
/home/bmitch/data/git/go.googlesource.com/tools/go/analysis/checker/checker.go:253 +0x45
created by golang.org/x/tools/go/analysis/checker.execAll in goroutine 1
/home/bmitch/data/git/go.googlesource.com/tools/go/analysis/checker/checker.go:259 +0x147
This appears to be triggered by:
What did you expect to see?
No panics.
Editor and settings
Run from the CLI.
Logs
n/a
Metadata
Metadata
Assignees
Labels
Type
Projects
Relationships
Development
No branches or pull requests
Activity
gabyhelp commentedon Feb 16, 2025
Related Issues
(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.)
gopherbot commentedon Feb 17, 2025
Change https://go.dev/cl/650215 mentions this issue:
gopls/internal/analysis/modernize: sortslice: fix crash
gopherbot commentedon Feb 18, 2025
Change https://go.dev/cl/650495 mentions this issue:
[gopls-release-branch.0.18] gopls/internal/analysis/modernize: sortslice: fix crash
[gopls-release-branch.0.18] gopls/internal/analysis/modernize: sortsl…
gopls/internal/analysis/modernize: sortslice: fix crash
slices.ContainsFunc
causes type errors #73269