Closed as duplicate of#72035
Closed as duplicate of#72035
Description
Go version
go 1.24.2
Output of go env
in your module/workspace:
AR='ar'
CC='clang'
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_ENABLED='0'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
CXX='clang++'
GCCGO='gccgo'
GO111MODULE='auto'
GOARCH='arm64'
GOARM64='v8.0'
GOAUTH='netrc'
GOBIN=''
GOCACHE='/Users/xxx/Library/Caches/go-build'
GOCACHEPROG=''
GODEBUG=''
GOENV='/Users/xxx/Library/Application Support/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFIPS140='off'
GOFLAGS=''
GOGCCFLAGS='-fPIC -arch arm64 -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -ffile-prefix-map=/var/folders/9t/839s3jmj73bcgyp5x_xh3gw00000gn/T/go-build2973783802=/tmp/go-build -gno-record-gcc-switches -fno-common'
GOHOSTARCH='arm64'
GOHOSTOS='darwin'
GOINSECURE=''
GOMOD='/Users/xxxx/20250428/tools/gopls/go.mod'
GOMODCACHE='/Users/xxx/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='darwin'
GOPATH='/Users/xxx/go'
GOPRIVATE=''
GOPROXY='https://goproxy.cn,direct'
GOROOT='/usr/local/go'
GOSUMDB='off'
GOTELEMETRY='local'
GOTELEMETRYDIR='/Users/xxx/Library/Application Support/go/telemetry'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/usr/local/go/pkg/tool/darwin_arm64'
GOVCS=''
GOVERSION='go1.24.2'
GOWORK=''
PKG_CONFIG='pkg-config'
What did you do?
package main
import (
"fmt"
"sort"
)
func main() {
a := []uint32{3, 1, 4, 1, 5, 9}
Uint32Sort(a)
fmt.Println(a)
}
func Uint32Sort(arr []uint32) {
sort.Slice(arr, func(i, j int) bool { return arr[i] < arr[j] })
}
Output:
[1 1 3 4 5 9]
What did you see happen?
After executing modernize -fix -test ./...
, it will become.
package main
import (
"fmt"
"slices"
"sort"
)
func main() {
a := []uint32{3, 1, 4, 1, 5, 9}
Uint32Sort(a)
fmt.Println(a)
}
func Uint32Sort(arr []uint32) {
slices.Sort(arr)
}
Output:
# command-line-arguments
./main.go:6:2: "sort" imported and not used
What did you expect to see?
The sort package should be handled correctly; if there are other places in this file using methods from the sort package, they should be retained. Otherwise, they should be removed.