-
Notifications
You must be signed in to change notification settings - Fork 18.5k
Closed
Labels
DocumentationIssues describing a change to documentation.Issues describing a change to documentation.FrozenDueToAge
Milestone
Description
Exported field names inhabit a global namespace but unexported (lower case) field names belong to the namespace of the package in which they lexically appear. The "reflect" API doesn't mention this, which can lead to surprising results when searching for a lowercase field by name. func (v Value) FieldByName(name string) Value FieldByName returns the struct field with the given name. It returns the zero Value if no field was found. It panics if v's Kind is not struct. In the example below, a struct has two fields, both called r, but belonging to different namespaces. The "reflect" algorithm, when searching for "r", finds both, and assumes there's a conflict when in reality there isn't. Without changing the existing API, that's the best we can do, but it would be useful to document this because otherwise the choice of unexported field names inside one package can have subtle effects on another package using reflection. http://play.golang.org/p/WTj5d06CQ3 (gri: I know you know all this already.)
Metadata
Metadata
Assignees
Labels
DocumentationIssues describing a change to documentation.Issues describing a change to documentation.FrozenDueToAge