mirror of
https://github.com/golang/go
synced 2024-11-12 08:20:22 -07:00
go/types: embedded fields can be predeclared types
R=adonovan, r CC=golang-dev https://golang.org/cl/7376055
This commit is contained in:
parent
d6a057c90e
commit
1caaff6b5a
@ -300,7 +300,11 @@ func lookupFieldBreadthFirst(list []embeddedType, name QualifiedName) (res looku
|
||||
// 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})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -377,7 +381,11 @@ func lookupField(typ Type, name QualifiedName) lookupResult {
|
||||
// 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 {
|
||||
|
22
src/pkg/go/types/testdata/decls3.src
vendored
22
src/pkg/go/types/testdata/decls3.src
vendored
@ -44,6 +44,28 @@ func issue4355() {
|
||||
_ = 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 {
|
||||
|
Loading…
Reference in New Issue
Block a user