diff options
author | Ian Lance Taylor <iant@golang.org> | 2016-07-11 22:34:30 -0700 |
---|---|---|
committer | Ian Lance Taylor <iant@golang.org> | 2016-07-12 12:43:48 +0000 |
commit | 1f4e68d92b33a668f2afa2ab5f8114c1a4bee682 (patch) | |
tree | cc02e87af73227c2efa55a7d0b92b0cae38a7cc4 | |
parent | a84b18ac865257c50d8812e39d244b57809fc8c8 (diff) | |
download | go-1f4e68d92b33a668f2afa2ab5f8114c1a4bee682.tar.gz go-1f4e68d92b33a668f2afa2ab5f8114c1a4bee682.zip |
reflect: an unnamed type has no PkgPath
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>
-rw-r--r-- | src/reflect/all_test.go | 2 | ||||
-rw-r--r-- | src/reflect/type.go | 3 |
2 files changed, 5 insertions, 0 deletions
diff --git a/src/reflect/all_test.go b/src/reflect/all_test.go index adde5829dc..bbb098f3eb 100644 --- a/src/reflect/all_test.go +++ b/src/reflect/all_test.go @@ -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 { diff --git a/src/reflect/type.go b/src/reflect/type.go index bedfba45b1..de6e05fb6d 100644 --- a/src/reflect/type.go +++ b/src/reflect/type.go @@ -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 "" |