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 forbids anonymous fields without name #24781

Open
Merovius opened this issue Apr 9, 2018 · 3 comments
Open

reflect: StructOf forbids anonymous fields without name #24781

Merovius opened this issue Apr 9, 2018 · 3 comments
Labels
early-in-cycle NeedsInvestigation
Milestone

Comments

@Merovius
Copy link

@Merovius Merovius commented Apr 9, 2018

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

go version go1.10.1 linux/amd64

Does this issue reproduce with the latest release?

Yes.

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

GOARCH="amd64"
GOBIN=""
GOCACHE="/home/mero/.cache/go-build"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/mero"
GORACE=""
GOROOT="/home/mero/go"
GOTMPDIR=""
GOTOOLDIR="/home/mero/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
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-build786947304=/tmp/go-build -gno-record-gcc-switches"

What did you do?

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

What did you expect to see?

true
true

What did you see instead?

true
false
interface conversion: interface {} is struct { X main.X }, not struct { main.X }


I believe A() and B() should behave the same, but they don't. StructOf seemingly creates a named field, even though Anonymous is set to true. It is not possible, not to pass a name either, though, because then StructOf panics:

true
panic: reflect.StructOf: field 0 has no name

goroutine 1 [running]:
reflect.StructOf(0x1052ff5c, 0x1, 0x1, 0x1e5e20, 0x0, 0x0)
/usr/local/go/src/reflect/type.go:2404 +0x3fa0
main.B(0x122660, 0x1052ffa4)
/tmp/sandbox310635867/main.go:22 +0xc0
main.main()
/tmp/sandbox310635867/main.go:14 +0x60

@bcmills bcmills added the NeedsInvestigation label Apr 9, 2018
@bcmills bcmills added this to the Go1.11 milestone Apr 9, 2018
@bcmills
Copy link
Member

@bcmills bcmills commented Apr 9, 2018

(CC: @griesemer @mdempsky @dsnet)

@griesemer
Copy link
Contributor

@griesemer griesemer commented Apr 9, 2018

Possibly related to #24721.

@jimmyfrasche
Copy link
Member

@jimmyfrasche jimmyfrasche commented Jun 22, 2018

I just ran into this: https://play.golang.org/p/rv5GDx0s02w

There seem to be three things going on

  1. If you create an anonymous field with no name, it should use the type name (feature request)
  2. Whether you give a name, it's not treating the field as anonymous (prints field name and type instead of just field name derived from type)
  3. #24721 as @griesemer said above

@ianlancetaylor ianlancetaylor removed this from the Go1.11 milestone Jun 27, 2018
@ianlancetaylor ianlancetaylor added this to the Go1.12 milestone Jun 27, 2018
@ianlancetaylor ianlancetaylor removed this from the Go1.12 milestone Dec 21, 2018
@ianlancetaylor ianlancetaylor added this to the Go1.13 milestone Dec 21, 2018
@ianlancetaylor ianlancetaylor added the early-in-cycle label Dec 21, 2018
@andybons andybons removed this from the Go1.13 milestone Jul 8, 2019
@andybons andybons added this to the Go1.14 milestone Jul 8, 2019
@rsc rsc removed this from the Go1.14 milestone Oct 9, 2019
@rsc rsc added this to the Backlog milestone Oct 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
early-in-cycle NeedsInvestigation
Projects
None yet
Development

No branches or pull requests

7 participants