Skip to content

Commit 1f4e68d

Browse files
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 <[email protected]>
1 parent a84b18a commit 1f4e68d

File tree

2 files changed

+5
-0
lines changed

2 files changed

+5
-0
lines changed

src/reflect/all_test.go

+2
Original file line numberDiff line numberDiff line change
@@ -2261,6 +2261,8 @@ func TestImportPath(t *testing.T) {
22612261
{TypeOf((*int64)(nil)), ""},
22622262
{TypeOf(map[string]int{}), ""},
22632263
{TypeOf((*error)(nil)).Elem(), ""},
2264+
{TypeOf((*Point)(nil)), ""},
2265+
{TypeOf((*Point)(nil)).Elem(), "reflect_test"},
22642266
}
22652267
for _, test := range tests {
22662268
if path := test.t.PkgPath(); path != test.path {

src/reflect/type.go

+3
Original file line numberDiff line numberDiff line change
@@ -876,6 +876,9 @@ func (t *rtype) MethodByName(name string) (m Method, ok bool) {
876876
}
877877

878878
func (t *rtype) PkgPath() string {
879+
if t.tflag&tflagNamed == 0 {
880+
return ""
881+
}
879882
ut := t.uncommon()
880883
if ut == nil {
881884
return ""

0 commit comments

Comments
 (0)