Skip to content

x/tools/gopls/internal/analysis/modernize: the conversion of variadic functions to slices.ContainsFunc causes type errors #73269

Closed
@karamaru-alpha

Description

@karamaru-alpha

Go version

go version devel go1.25-559b5d814f Tue Apr 8 08:25:47 2025 -0700 darwin/arm64

Output of go env in your module/workspace:

go env
AR='ar'
CC='clang'
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_ENABLED='1'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
CXX='clang++'
GCCGO='gccgo'
GO111MODULE=''
GOARCH='arm64'
GOARM64='v8.0'
GOAUTH='netrc'
GOBIN=''
GOCACHE='/Users/foo/Library/Caches/go-build'
GOCACHEPROG=''
GODEBUG=''
GOENV='/Users/foo/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/6j/7k819wz12zgg0b53lr9x6qgmt4y905/T/go-build1756321600=/tmp/go-build -gno-record-gcc-switches -fno-common'
GOHOSTARCH='arm64'
GOHOSTOS='darwin'
GOINSECURE=''
GOMOD='/Users/foo/Project/oss/tools/go.mod'
GOMODCACHE='/Users/foo/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='darwin'
GOPATH='/Users/foo/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/Users/foo/Project/oss/go'
GOSUMDB='sum.golang.org'
GOTELEMETRY='local'
GOTELEMETRYDIR='/Users/foo/Library/Application Support/go/telemetry'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/Users/foo/Project/oss/go/pkg/tool/darwin_arm64'
GOVCS=''
GOVERSION='devel go1.25-559b5d814f Tue Apr 8 08:25:47 2025 -0700'
GOWORK=''
PKG_CONFIG='pkg-config'

What did you do?

go run golang.org/x/tools/gopls/internal/analysis/modernize/cmd/[email protected] -fix ./...

What did you see happen?

modernize's conversion of variadic functions to slices.ContainsFunc causes type errors.

func check() bool {
	nums := []int{1, 2, 3}
-	for _, num := range nums {
-		if isEven(num) {
-			return true
-		}
-	}
-	return false
+	return slices.ContainsFunc(nums, isEven) // Error: in call to slices.ContainsFunc, type func(num int, opt ...any) bool of isEven does not match func(E) bool
}

func isEven(num int, opt ...any) bool {
	return num/2 == 0
}

What did you expect to see?

Variadic functions should not be converted to slices.ContainsFunc.
cf. CL 663436

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugReportIssues describing a possible bug in the Go implementation.ToolsThis label describes issues relating to any tools in the x/tools repository.goplsIssues related to the Go language server, gopls.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions