mustPanic: true,
},
{
- field: StructField{Name: "s2", Type: TypeOf(int(0)), PkgPath: "other/pkg"},
- mustPanic: true,
+ field: StructField{Name: "s2", Type: TypeOf(int(0)), PkgPath: "other/pkg"},
},
{
- field: StructField{Name: "s2", Type: TypeOf(int(0)), PkgPath: "other/pkg"},
- mustPanic: true,
+ field: StructField{Name: "s2", Type: TypeOf(int(0)), PkgPath: "other/pkg"},
},
{
- field: StructField{Name: "S", Type: TypeOf(S1{})},
- mustPanic: false,
- exported: true,
+ field: StructField{Name: "S", Type: TypeOf(S1{})},
+ exported: true,
},
{
field: StructField{Name: "S", Type: TypeOf((*S1)(nil))},
mustPanic: true,
},
{
- field: StructField{Name: "s", Type: TypeOf(S1{}), PkgPath: "other/pkg"},
- mustPanic: true, // TODO(sbinet): creating a name with a package path
+ field: StructField{Name: "s", Type: TypeOf(S1{}), PkgPath: "other/pkg"},
},
{
- field: StructField{Name: "s", Type: TypeOf((*S1)(nil)), PkgPath: "other/pkg"},
- mustPanic: true, // TODO(sbinet): creating a name with a package path
+ field: StructField{Name: "s", Type: TypeOf((*S1)(nil)), PkgPath: "other/pkg"},
},
{
- field: StructField{Name: "s", Type: TypeOf(s2{}), PkgPath: "other/pkg"},
- mustPanic: true, // TODO(sbinet): creating a name with a package path
+ field: StructField{Name: "s", Type: TypeOf(s2{}), PkgPath: "other/pkg"},
},
{
- field: StructField{Name: "s", Type: TypeOf((*s2)(nil)), PkgPath: "other/pkg"},
- mustPanic: true, // TODO(sbinet): creating a name with a package path
+ field: StructField{Name: "s", Type: TypeOf((*s2)(nil)), PkgPath: "other/pkg"},
},
{
field: StructField{Name: "", Type: TypeOf(ΦType{})},
}
func runtimeStructField(field StructField) structField {
- if field.PkgPath != "" {
- panic("reflect.StructOf: StructOf does not allow unexported fields")
+ if field.Anonymous && field.PkgPath != "" {
+ panic("reflect.StructOf: field \"" + field.Name + "\" is anonymous but has PkgPath set")
}
- // Best-effort check for misuse.
- // Since PkgPath is empty, not much harm done if Unicode lowercase slips through.
- c := field.Name[0]
- if 'a' <= c && c <= 'z' || c == '_' {
- panic("reflect.StructOf: field \"" + field.Name + "\" is unexported but missing PkgPath")
+ exported := field.PkgPath == ""
+ if exported {
+ // Best-effort check for misuse.
+ // Since this field will be treated as exported, not much harm done if Unicode lowercase slips through.
+ c := field.Name[0]
+ if 'a' <= c && c <= 'z' || c == '_' {
+ panic("reflect.StructOf: field \"" + field.Name + "\" is unexported but missing PkgPath")
+ }
}
offsetEmbed := uintptr(0)
resolveReflectType(field.Type.common()) // install in runtime
return structField{
- name: newName(field.Name, string(field.Tag), true),
+ name: newName(field.Name, string(field.Tag), exported),
typ: field.Type.common(),
offsetEmbed: offsetEmbed,
}