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.
The
StructField.PkgPathfield 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 exportedNameshould not be allowed withPkgPathalso being specified. However, this is currently permitted:I expect the snippet above to panic.