Commit 7feb4249 authored by Russ Cox's avatar Russ Cox

cmd/compile: fix PtrTo(t) for unnamed t with embedded fields

Fixes #8427.

Change-Id: I826a3bc4519845ad30d6dbaf058fe7ed7bee8db0
Reviewed-on: https://go-review.googlesource.com/12233Reviewed-by: default avatarIan Lance Taylor <iant@golang.org>
parent bed6326a
......@@ -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")
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment