]> Cypherpunks repositories - gostls13.git/commit
[dev.typealias] reflect: fix StructOf use of StructField to match StructField docs
authorRuss Cox <rsc@golang.org>
Wed, 25 Jan 2017 14:50:36 +0000 (09:50 -0500)
committerRuss Cox <rsc@golang.org>
Wed, 25 Jan 2017 18:56:51 +0000 (18:56 +0000)
commit43c70943861ce39b44e5bd577a8c3c2ef18538db
tree2a44480a7aaeb4c00eecf97a4c3503683e26e0ef
parent9657e0b0777f3af3b48908cc39e5ab6d06022422
[dev.typealias] reflect: fix StructOf use of StructField to match StructField docs

The runtime internal structField interprets name=="" as meaning anonymous,
but the exported reflect.StructField has always set Name, even for anonymous
fields, and also set Anonymous=true.

The initial implementation of StructOf confused the internal and public
meanings of the StructField, expecting the runtime representation of
anonymous fields instead of the exported reflect API representation.
It also did not document this fact, so that users had no way to know how
to create an anonymous field.

This CL changes StructOf to use the previously documented interpretation
of reflect.StructField instead of an undocumented one.

The implementation of StructOf also, in some cases, allowed creating
structs with unexported fields (if you knew how to ask) but set the
PkgPath incorrectly on those fields. Rather than try to fix that, this CL
changes StructOf to reject attempts to create unexported fields.
(I think that may be the right design choice, not just a temporary limitation.
In any event, it's not the topic for today's work.)

For #17766.
Fixes #18780.

Change-Id: I585a4e324dc5a90551f49d21ae04d2de9ea04b6c
Reviewed-on: https://go-review.googlesource.com/35731
Run-TryBot: Russ Cox <rsc@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
src/reflect/all_test.go
src/reflect/type.go