mirror of https://github.com/golang/go.git
cmd/compile: fix PtrTo(t) for unnamed t with embedded fields
Fixes #8427. Change-Id: I826a3bc4519845ad30d6dbaf058fe7ed7bee8db0 Reviewed-on: https://go-review.googlesource.com/12233 Reviewed-by: Ian Lance Taylor <iant@golang.org>
This commit is contained in:
parent
bed6326a3c
commit
7feb424928
|
|
@ -760,10 +760,11 @@ func dcommontype(s *Sym, ot int, t *Type) int {
|
|||
}
|
||||
|
||||
var sptr *Sym
|
||||
if t.Sym != nil && !Isptr[t.Etype] {
|
||||
sptr = dtypesym(Ptrto(t))
|
||||
tptr := Ptrto(t)
|
||||
if !Isptr[t.Etype] && (t.Sym != nil || methods(tptr) != nil) {
|
||||
sptr = dtypesym(tptr)
|
||||
} else {
|
||||
sptr = weaktypesym(Ptrto(t))
|
||||
sptr = weaktypesym(tptr)
|
||||
}
|
||||
|
||||
// All (non-reflect-allocated) Types share the same zero object.
|
||||
|
|
|
|||
|
|
@ -4721,3 +4721,16 @@ func TestTypeOfTypeOf(t *testing.T) {
|
|||
check("PtrTo", PtrTo(TypeOf(T{})))
|
||||
check("SliceOf", SliceOf(TypeOf(T{})))
|
||||
}
|
||||
|
||||
type XM struct{}
|
||||
|
||||
func (*XM) String() string { return "" }
|
||||
|
||||
func TestPtrToMethods(t *testing.T) {
|
||||
var y struct{ XM }
|
||||
yp := New(TypeOf(y)).Interface()
|
||||
_, ok := yp.(fmt.Stringer)
|
||||
if !ok {
|
||||
t.Fatal("does not implement Stringer, but should")
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue