From: Russ Cox Date: Wed, 15 Jul 2015 04:01:54 +0000 (-0400) Subject: cmd/compile: fix PtrTo(t) for unnamed t with embedded fields X-Git-Tag: go1.5beta2~25 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=7feb424928605b51979e0bda3bbad139fcf2bb51;p=gostls13.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 --- diff --git a/src/cmd/compile/internal/gc/reflect.go b/src/cmd/compile/internal/gc/reflect.go index 08343e88ee..fcb9b17eee 100644 --- a/src/cmd/compile/internal/gc/reflect.go +++ b/src/cmd/compile/internal/gc/reflect.go @@ -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. diff --git a/src/reflect/all_test.go b/src/reflect/all_test.go index 3c6fc9a1a8..ee06b4c9f7 100644 --- a/src/reflect/all_test.go +++ b/src/reflect/all_test.go @@ -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") + } +}