]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: fix PtrTo(t) for unnamed t with embedded fields
authorRuss Cox <rsc@golang.org>
Wed, 15 Jul 2015 04:01:54 +0000 (00:01 -0400)
committerRuss Cox <rsc@golang.org>
Wed, 15 Jul 2015 05:36:27 +0000 (05:36 +0000)
Fixes #8427.

Change-Id: I826a3bc4519845ad30d6dbaf058fe7ed7bee8db0
Reviewed-on: https://go-review.googlesource.com/12233
Reviewed-by: Ian Lance Taylor <iant@golang.org>
src/cmd/compile/internal/gc/reflect.go
src/reflect/all_test.go

index 08343e88ee65a64eb77659313bb5b90d181d57cb..fcb9b17eee1f6f1dd15dab0b7d652ae76b857a34 100644 (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.
index 3c6fc9a1a8ebda6277a22dd61541b651ba21ea6d..ee06b4c9f7e718b63473fed5bfb51a1c7aab0bb1 100644 (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")
+       }
+}