-
Notifications
You must be signed in to change notification settings - Fork 18.8k
Description
Go version
go version go1.26.0 darwin/arm64
Output of go env in your module/workspace:
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='on'
GOARCH='arm64'
GOARM64='v8.0'
GOAUTH='netrc'
GOBIN=''
GOCACHE='/Users/.../Library/Caches/go-build'
GOCACHEPROG=''
GODEBUG=''
GOENV='/Users/.../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/6x/kchnflh55jx1tpvvyrqbk6z00000gp/T/go-build2430644522=/tmp/go-build -gno-record-gcc-switches -fno-common'
GOHOSTARCH='arm64'
GOHOSTOS='darwin'
GOINSECURE=''
GOMOD='/Users/.../proj/.../go.mod'
GOMODCACHE='/Users/.../go/pkg/mod'
GONOPROXY='...'
GONOSUMDB='...'
GOOS='darwin'
GOPATH='/Users/.../go'
GOPRIVATE='...'
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/usr/local/go'
GOSUMDB='sum.golang.org'
GOTELEMETRY='local'
GOTELEMETRYDIR='/Users/.../Library/Application Support/go/telemetry'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/usr/local/go/pkg/tool/darwin_arm64'
GOVCS=''
GOVERSION='go1.26.0'
GOWORK=''
PKG_CONFIG='pkg-configWhat did you do?
While running go fmt ./... with go.mod set to go 1.26.0 my old function that serves the same purpose as the new new keyword, doesn't get inlined, but gets marked by go:fix to be inlined.
What did you see happen?
The original function resides in /internal/pkg/utils/pointer_utils.go
package utils
func Ptr[T any](v T) *T {
return &v
}
was modified by the first run of go fix ./... to
package utils
//go:fix inline
func Ptr[T any](v T) *T {
return new(v)
}
a second run of go fix ./... yielded expected results for all other functions that got labeled with //go:fix inline, but all usages of utils.Ptr("a")
Possibly of note, most usages of utils.Ptr, are type alias of string, ex
type Fruit string
const (
Apple = Fruit("apple")
Pear = Fruit("pear")
)
...
SomeStruct{
Fruit: utils.Ptr(Apple)
}
What did you expect to see?
After the final run of go fix ./... I would expect all references to utils.Ptr removed, and then I may manually delete the dead code.
An example of a similar function that is successfully inlined after two runs:
func StringPointer(s string) *string {
return &s
}