Go version
go1.24.3
Output of go env in your module/workspace:
AR='ar'
CC='cc'
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_ENABLED='1'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
CXX='c++'
GCCGO='gccgo'
GO111MODULE=''
GOARCH='arm64'
GOARM64='v8.0'
GOAUTH='netrc'
GOBIN='/Users/mac/go/bin'
GOCACHE='/Users/mac/Library/Caches/go-build'
GOCACHEPROG=''
GODEBUG=''
GOENV='/Users/mac/Library/Application Support/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFIPS140='off'
GOFLAGS=''
GOGCCFLAGS='-fPIC -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -ffile-prefix-map=/var/folders/tq/m955dwkd1519phkp2hwpv9_80000gn/T/go-build2400307511=/tmp/go-build -gno-record-gcc-switches -fno-common'
GOHOSTARCH='arm64'
GOHOSTOS='darwin'
GOINSECURE=''
GOMOD='/dev/null'
GOMODCACHE='/Users/mac/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='darwin'
GOPATH='/Users/mac/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/usr/local/go'
GOSUMDB='sum.golang.org'
GOTELEMETRY='local'
GOTELEMETRYDIR='/Users/mac/Library/Application Support/go/telemetry'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/usr/local/go/pkg/tool/darwin_arm64'
GOVCS=''
GOVERSION='go1.24.3'
GOWORK=''
PKG_CONFIG='pkg-config'
What did you do?
package main
import "fmt"
type Expression interface{}
type Column struct {
UniqueID int64
}
func (col *Column) EqualColumn(expr Expression) bool {
other, ok := expr.(*Column)
if !ok {
return false
}
return col.UniqueID == other.UniqueID
}
func (col *Column) InColumnArray(cols []*Column) bool {
for _, c := range cols {
if col.EqualColumn(c) { // c is *Column, but EqualColumn expects Expression
return true
}
}
return false
}
func main() {
cols := []*Column{
{UniqueID: 1},
{UniqueID: 2},
{UniqueID: 3},
}
colToCheck := &Column{UniqueID: 2}
fmt.Println("Is column in array?", colToCheck.InColumnArray(cols)) // true
colToCheck2 := &Column{UniqueID: 5}
fmt.Println("Is column in array?", colToCheck2.InColumnArray(cols)) // false
}
The Output:
Is column in array? true
Is column in array? false
What did you see happen?
After executing modernize -fix -test ./..., it will become.
package main
import "slices"
import "fmt"
type Expression interface{}
type Column struct {
UniqueID int64
}
func (col *Column) EqualColumn(expr Expression) bool {
other, ok := expr.(*Column)
if !ok {
return false
}
return col.UniqueID == other.UniqueID
}
func (col *Column) InColumnArray(cols []*Column) bool {
return slices.ContainsFunc(cols, col.EqualColumn)
}
func main() {
cols := []*Column{
{UniqueID: 1},
{UniqueID: 2},
{UniqueID: 3},
}
colToCheck := &Column{UniqueID: 2}
fmt.Println("Is column in array?", colToCheck.InColumnArray(cols)) // true
colToCheck2 := &Column{UniqueID: 5}
fmt.Println("Is column in array?", colToCheck2.InColumnArray(cols)) // false
}
Output:
# command-line-arguments
./main2.go:22:28: in call to slices.ContainsFunc, S (type []*Column) does not satisfy ~[]E
What did you expect to see?
Do not take action on this situation.
Comment From: gopherbot
Change https://go.dev/cl/693879 mentions this issue: gopls/internal/analysis/modernize: fix the compilation error caused
Comment From: gabyhelp
Related Issues
- x/tools/gopls/internal/analysis/modernize: slicescontains offers fix that elides an implicit interface conversion #73564 (closed)
- x/tools/gopls/internal/analysis/modernize: the conversion of variadic functions to `slices.ContainsFunc` causes type errors #73269 (closed)
- x/tools/gopls/internal/analysis/modernize: append([]T{}, x...) -> slices.Clone(x) fix may unsoundly return nil #73557 (closed)
- x/tools/gopls/internal/analysis/modernize: rangeint produces invalid syntax due to use of types.RelativeTo #74687
- x/tools/gopls/internal/analyzer/modernize: bug in slices.Contains transformation #71313 (closed)
- x/tools/gopls/internal/analysis/modernize: Panic in modernize/sortslice.go #71786 (closed)
- x/tools/gopls/internal/analysis/modernize: rangeint generates correct but not idiomatic transformation #71725 (closed)
(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.)
Comment From: findleyr
Thanks for the report. We've fixed similar issues in the past -- was this with gopls@v0.20.0?
Nevertheless, we should fix this for the next release.
Comment From: cuishuang
Thanks for the report. We've fixed similar issues in the past -- was this with gopls@v0.20.0?
Nevertheless, we should fix this for the next release.
Thanks.
Comment From: findleyr
@cuishuang sorry, why did you close this? Is it already fixed?
I meant that we should make sure it's fixed in the next release. AFAIK, it's not fixed yet.
Comment From: cuishuang
@cuishuang sorry, why did you close this? Is it already fixed?
I meant that we should make sure it's fixed in the next release. AFAIK, it's not fixed yet.
Sorry for the delayed response.
As I mentioned in CL693879,
I did some testing and found that it was likely because the code I used locally to compile the binary is not the latest version. Sorry for the inconvenience.
Using the latest code should prevent this issue from occurring.
So I think this issue can be closed. Thank you for your response.
Comment From: mvdan
I just ran into this problem as well today, with modernize at version v0.0.0-20250905165647-bd1ee09fe80a, so I don't think the bug is resolved.
See https://review.gerrithub.io/c/cue-lang/cue/+/1222171 at patchset 1 - the change to encoding/json broke the build. This can be reproduced on https://github.com/cue-lang/cue at commit 20531e1837bf21fd9b38f83610d1a47d663fe2fc:
$ go build ./encoding/json; echo ==; modernize -fix -slicescontains ./encoding/json; go build ./encoding/json
==
# cuelang.org/go/encoding/json
encoding/json/json.go:195:27: in call to slices.ContainsFunc, S (type []ast.Expr) does not satisfy ~[]E