// this level, f.Type appears multiple times at the next
// level.
if f.IsAnonymous && res.mode == invalid {
- next = append(next, embeddedType{deref(f.Type).(*NamedType), e.multiples})
+ // Ignore embedded basic types - only user-defined
+ // named types can have methods or have struct fields.
+ if t, _ := deref(f.Type).(*NamedType); t != nil {
+ next = append(next, embeddedType{t, e.multiples})
+ }
}
}
// Possible optimization: If the embedded type
// is a pointer to the current type we could
// ignore it.
- next = append(next, embeddedType{typ: deref(f.Type).(*NamedType)})
+ // Ignore embedded basic types - only user-defined
+ // named types can have methods or have struct fields.
+ if t, _ := deref(f.Type).(*NamedType); t != nil {
+ next = append(next, embeddedType{typ: t})
+ }
}
}
if len(next) > 0 {
_ = t /* ERROR "no single field or method" */ .X
}
+// Embedded fields can be predeclared types.
+
+func _() {
+ type T0 struct{
+ int
+ float32
+ f int
+ }
+ var x T0
+ _ = x.int
+ _ = x.float32
+ _ = x.f
+
+ type T1 struct{
+ T0
+ }
+ var y T1
+ _ = y.int
+ _ = y.float32
+ _ = y.f
+}
+
// Borrowed from the FieldByName test cases in reflect/all_test.go.
type D1 struct {