Go version
go version go1.26.1 linux/amd64
Output of go env in your module/workspace:
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=''
GOAMD64='v1'
GOARCH='amd64'
GOAUTH='netrc'
GOBIN=''
GOCACHE='/home/murman/.cache/go-build'
GOCACHEPROG=''
GODEBUG=''
GOENV='/home/murman/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFIPS140='off'
GOFLAGS=''
GOGCCFLAGS='-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build3667478671=/tmp/go-build -gno-record-gcc-switches'
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMOD='/home/murman/[redacted]/go.mod'
GOMODCACHE='/home/murman/go/pkg/mod'
GONOPROXY='github.com/[redacted]'
GONOSUMDB='github.com/[redacted]'
GOOS='linux'
GOPATH='/home/murman/go'
GOPRIVATE='github.com/[redacted]'
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/home/murman/.local/share/mise/installs/go/1.26.1'
GOSUMDB='sum.golang.org'
GOTELEMETRY='local'
GOTELEMETRYDIR='/home/murman/.config/go/telemetry'
GOTMPDIR=''
GOTOOLCHAIN='local'
GOTOOLDIR='/home/murman/.local/share/mise/installs/go/1.26.1/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='go1.26.1'
GOWORK=''
PKG_CONFIG='pkg-config'
What did you do?
I ran go fix -reflecttypefor ./... (originally just go fix ./...). The following code is enough to reproduce the change:
package main
import "reflect"
// In my real scenario, this signature needs to be updated to match code gen.
func helper(a int, b string) {}
func main() {
// go fix -reflecttypefor changes this to reflect.TypeFor[func(a int, b string)]()
// which prevents this check from being dynamic.
_ = reflect.TypeOf(helper)
}
What did you see happen?
Running go fix -reflecttypefor ./... fix replaced
ft := reflect.TypeOf(fillStruct)
with
ft := reflect.TypeFor[func(p *gen.Struct, pA *gen.A, pB *gen.B, pC *gen.C, pD *gen.D, pE *gen.E, pF *gen.F, pG *gen.G, pH *gen.H, pI *gen.I, pJ *gen.J, pK *gen.K, pL *gen.L, pM *gen.M, pN *gen.N, pO *gen.O) *gen.Struct]()
That is, fillStruct is a helper function that takes several arguments corresponding to different fields in a gen.Struct. (The names here are redacted.)
What did you expect to see?
I expected the code to be left as is. I am using this in a test to detect drift between code and a generated struct. While the change is correct at the moment it is applied, it invalidates code's purpose: the code no longer tests the helper's coverage of the struct's fields, and it no longer points to the helper.
Go version
go version go1.26.1 linux/amd64
Output of
go envin your module/workspace:What did you do?
I ran
go fix -reflecttypefor ./...(originally justgo fix ./...). The following code is enough to reproduce the change:What did you see happen?
Running
go fix -reflecttypefor ./...fix replacedwith
That is, fillStruct is a helper function that takes several arguments corresponding to different fields in a gen.Struct. (The names here are redacted.)
What did you expect to see?
I expected the code to be left as is. I am using this in a test to detect drift between code and a generated struct. While the change is correct at the moment it is applied, it invalidates code's purpose: the code no longer tests the helper's coverage of the struct's fields, and it no longer points to the helper.