Skip to content
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

reflect: StructOf of does not allow use of "_" field name more than once #49110

Closed
kortschak opened this issue Oct 22, 2021 · 1 comment
Closed
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.

Comments

@kortschak
Copy link
Contributor

kortschak commented Oct 22, 2021

What version of Go are you using (go version)?

$ go version
go1.17.1

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GO111MODULE="on"
GOARCH="amd64"
GOBIN="/home/user/bin"
GOCACHE="/home/user/.cache/go-build"
GOENV="/home/user/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/user/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/user"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/home/user/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/home/user/go/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.17.1"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/dev/null"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build3606891520=/tmp/go-build -gno-record-gcc-switches"

What did you do?

https://play.golang.org/p/mvNenqW5RdZ

What did you expect to see?

Reflect safely construct a struct equivalent to the struct created by the compiler.

What did you see instead?

panic: reflect.StructOf: duplicate field _

Additional information

I am using this to pad structs to match C structs dynamically, so I can work around this by providing the padding fields with an iota suffix, but it would be nice if this just worked. Looking at reflect.StructOf, making the duplication check here conditional on the Name not being "_" fixes the issue.

@gopherbot
Copy link

Change https://golang.org/cl/357959 mentions this issue: reflect: skip duplicate check in StructOf when the name of a filed is "_"

@seankhliao seankhliao added the NeedsFix The path to resolution is known, but the work has not been done. label Oct 24, 2021
nevkontakte added a commit to nevkontakte/gopherjs that referenced this issue Jul 21, 2022
@golang golang locked and limited conversation to collaborators Oct 27, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

3 participants