8000 x/tools/gopls/internal/analysis/modernize: rangeint generates correct but not idiomatic transformation · Issue #71725 · golang/go · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

x/tools/gopls/internal/analysis/modernize: rangeint generates correct but not idiomatic transformation #71725

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
spencerschrock opened this issue Feb 13, 2025 · 3 comments
Assignees
Labels
BugReport Issues describing a possible bug in the Go implementation. gopls/analysis Issues related to running analysis in gopls gopls Issues related to the Go language server, gopls. Refactoring Issues related to refactoring tools Tools This label describes issues relating to any tools in the x/tools repository.
Milestone

Comments

@spencerschrock
Copy link
spencerschrock commented Feb 13, 2025

gopls version

Currently at HEAD (44b61a1d174cc06329b20f5de60c2b0c800741a4):

gopls -v version
Build info
----------
golang.org/x/tools/gopls v0.30.1-0.20250213173512-44b61a1d174c+dirty
    golang.org/x/tools/gopls@v0.30.1-0.20250213173512-44b61a1d174c+dirty
    github.com/BurntSushi/toml@v1.4.1-0.20240526193622-a339e1f7089c h1:pxW6RcqyfI9/kWtOwnv/G+AzdKuy2ZrqINhenH4HyNs=
    github.com/google/go-cmp@v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
    golang.org/x/exp/typeparams@v0.0.0-20241210194714-1829a127f884 h1:1xaZTydL5Gsg78QharTwKfA9FY9CZ1VQj6D/AZEvHR0=
    golang.org/x/mod@v0.23.0 h1:Zb7khfcRGKk+kqfxFaP5tZqCnDZMjC5VtUBs87Hr6QM=
    golang.org/x/sync@v0.11.0 h1:GGz8+XQP4FvTTrjZPzNKTMFtSXH80RAzG+5ghFPgK9w=
    golang.org/x/telemetry@v0.0.0-20241220003058-cc96b6e0d3d9 h1:L2k9GUV2TpQKVRGMjN94qfUMgUwOFimSQ6gipyJIjKw=
    golang.org/x/text@v0.22.0 h1:bofq7m3/HAFvbF51jz3Q9wLg3jkvSPuiZu/pD1XwgtM=
    golang.org/x/tools@v0.28.0 => ../
    golang.org/x/vuln@v1.1.3 h1:NPGnvPOTgnjBc9HTaUx+nj+EaUYxl5SJOWqaDYGaFYw=
    honnef.co/go/tools@v0.5.1 h1:4bH5o3b5ZULQ4UrBmP+63W9r7qIkqJClEA9ko5YKx+I=
    mvdan.cc/gofumpt@v0.7.0 h1:bg91ttqXmi9y2xawvkuMXyvAA/1ZGJqYAEGjXuP0JXU=
    mvdan.cc/xurls/v2@v2.5.0 h1:lyBNOm8Wo71UknhUs4QTFUNNMyxy2JEIaKKo0RWOh+8=
go: go1.24.0

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='on'
GOAMD64='v1'
GOARCH='amd64'
GOAUTH='netrc'
GOBIN=''
GOCACHE='~/.cache/go-build'
GOCACHEPROG=''
GODEBUG=''
GOENV='~/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFIPS140='off'
GOFLAGS='-mod=mod'
GOGCCFLAGS='-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build3074086083=/tmp/go-build -gno-record-gcc-switches'
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMOD='/tmp/modernize/go.mod'
GOMODCACHE='~/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='linux'
GOPATH='~/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='~/sdk/go1.24.0'
GOSUMDB='sum.golang.org'
GOTELEMETRY='local'
GOTELEMETRYDIR='~/.config/go/telemetry'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='~/sdk/go1.24.0/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='go1.24.0'
GOWORK=''
PKG_CONFIG='pkg-config'

What did you do?

package main

import "fmt"

func main() {
	x := []int{5, 4, 3, 2, 1}
	for i := 0; i < len(x); i++ {
		fmt.Print(x[i])
	}
}

What did you see happen?

The suggested fix was:

package main

import "fmt"

func main() {
	x := []int{5, 4, 3, 2, 1}
	for i := range len(x) {
		fmt.Print(x[i])
	}
}

What did you expect to see?

package main

import "fmt"

func main() {
	x := []int{5, 4, 3, 2, 1}
	for i := range x {
		fmt.Print(x[i])
	}
}

Editor and settings

No response

Logs

No response

@spencerschrock spencerschrock added gopls Issues related to the Go language server, gopls. Tools This label describes issues relating to any tools in the x/tools repository. labels Feb 13, 2025
@spencerschrock
8000 Copy link
Author

one more @adonovan , though not an invalid transformation in this case, just was odd to see when ranging over a slice

@gabyhelp gabyhelp added the BugReport Issues describing a possible bug in the Go implementation. label Feb 13, 2025
@adonovan adonovan self-assigned this Feb 13, 2025
@adonovan adonovan added Refactoring Issues related to refactoring tools gopls/analysis Issues related to running analysis in gopls labels Feb 13, 2025
@adonovan adonovan added this to the gopls/v0.18.0 milestone Feb 13, 2025
@gopherbot
Copy link
Contributor

Change https://go.dev/cl/649356 mentions this issue: gopls/internal/analysis/modernize: improve rangeint transformation

@seankhliao seankhliao changed the title gopls/internal/analysis/modernize: rangeint generates correct but not idiomatic transformation x/tools/gopls/internal/analysis/modernize: rangeint generates correct but not idiomatic transformation Feb 13, 2025
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/analysis Issues related to running analysis in gopls gopls Issues related to the Go language server, gopls. Refactoring Issues related to refactoring tools 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
0