]> Cypherpunks repositories - gostls13.git/commitdiff
reflect: an unnamed type has no PkgPath
authorIan Lance Taylor <iant@golang.org>
Tue, 12 Jul 2016 05:34:30 +0000 (22:34 -0700)
committerIan Lance Taylor <iant@golang.org>
Tue, 12 Jul 2016 12:43:48 +0000 (12:43 +0000)
The reflect package was returning a non-empty PkgPath for an unnamed
type with methods, such as a type whose methods have a pointer
receiver.

Fixes #16328.

Change-Id: I733e93981ebb5c5c108ef9b03bf5494930b93cf3
Reviewed-on: https://go-review.googlesource.com/24862
Reviewed-by: David Crawshaw <crawshaw@golang.org>
src/reflect/all_test.go
src/reflect/type.go

index adde5829dc60aec7b81625993e0dc35f90ae8b9b..bbb098f3eb6134884a3218734ce89dad4124749d 100644 (file)
@@ -2261,6 +2261,8 @@ func TestImportPath(t *testing.T) {
                {TypeOf((*int64)(nil)), ""},
                {TypeOf(map[string]int{}), ""},
                {TypeOf((*error)(nil)).Elem(), ""},
+               {TypeOf((*Point)(nil)), ""},
+               {TypeOf((*Point)(nil)).Elem(), "reflect_test"},
        }
        for _, test := range tests {
                if path := test.t.PkgPath(); path != test.path {
index bedfba45b11578fbbc0c9d4e7dfc3735523b451c..de6e05fb6dc47e36b26029222f13e56d3b73342e 100644 (file)
@@ -876,6 +876,9 @@ func (t *rtype) MethodByName(name string) (m Method, ok bool) {
 }
 
 func (t *rtype) PkgPath() string {
+       if t.tflag&tflagNamed == 0 {
+               return ""
+       }
        ut := t.uncommon()
        if ut == nil {
                return ""