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 allows fields with inconsistent export information #45277

Open
dsnet opened this issue Mar 29, 2021 · 1 comment
Open

reflect: StructOf allows fields with inconsistent export information #45277

dsnet opened this issue Mar 29, 2021 · 1 comment
Labels
NeedsInvestigation
Milestone

Comments

@dsnet
Copy link
Member

@dsnet dsnet commented Mar 29, 2021

The StructField.PkgPath field should only be populated if the field is unexported. Currently in Go, this can only occur if the first character is an uppercase letter. Thus, an exported Name should not be allowed with PkgPath also being specified. However, this is currently permitted:

t := reflect.StructOf([]reflect.StructField{{
	Name:    "Field",                   // exported field
	PkgPath: "some.bogus/package/path", // should only be specified for unexported fields
	Type:    reflect.TypeOf(0),
}})                                         // expect this to panic, but it doesn't
f := t.Field(0)
fmt.Printf("%q.%s\n", f.PkgPath, f.Name)    // "some.bogus/package/path".Field

I expect the snippet above to panic.

@dsnet dsnet changed the title reflect: StructOf allows creation fields with inconsistent exported information reflect: StructOf allows fields with inconsistent exported information Mar 29, 2021
@dsnet dsnet changed the title reflect: StructOf allows fields with inconsistent exported information reflect: StructOf allows fields with inconsistent export information Mar 29, 2021
@cagedmantis cagedmantis added the NeedsInvestigation label Mar 31, 2021
@cagedmantis cagedmantis added this to the Backlog milestone Mar 31, 2021
@cagedmantis
Copy link
Contributor

@cagedmantis cagedmantis commented Mar 31, 2021

/cc @rsc @ianlancetaylor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NeedsInvestigation
Projects
None yet
Development

No branches or pull requests

2 participants