Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
karamaru-alpha opened this issue Apr 8, 2025 · 2 comments
Labels
BugReport Issues describing a possible bug in the Go implementation. gopls Issues related to the Go language server, gopls. Tools This label describes issues relating to any tools in the x/tools repository.
Milestone

Comments

@karamaru-alpha
Copy link

karamaru-alpha commented Apr 8, 2025

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

@gopherbot gopherbot added Tools This label describes issues relating to any tools in the x/tools repository. gopls Issues related to the Go language server, gopls. labels Apr 8, 2025
@gopherbot gopherbot added this to the Unreleased milestone Apr 8, 2025
@karamaru-alpha karamaru-alpha changed the title x/tools/gopls/internal/analysis/modernize: the conversion of variadic functions to slices.ContainFunc causes type errors x/tools/gopls/internal/analysis/modernize: the conversion of variadic functions to slices.ContainsFunc causes type errors Apr 8, 2025
@gopherbot
Copy link
Contributor

Change https://go.dev/cl/663436 mentions this issue: gopls/internal/analysis/modernize: prevent conversion of variadic functions to slices.ContainsFunc

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
BugReport Issues describing a possible bug in the Go implementation. gopls Issues related to the Go language server, gopls. Tools This label describes issues relating to any tools in the x/tools repository.
Projects
None yet
Development

No branches or pull requests

4 participants