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:
Russ Cox 2015-07-15 00:01:54 -04:00
parent bed6326a3c
commit 7feb424928
2 changed files with 17 additions and 3 deletions

View File

@ -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.

View File

@ -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")
}
}