mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
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>
This commit is contained in:
parent
a84b18ac86
commit
1f4e68d92b
2 changed files with 5 additions and 0 deletions
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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 ""
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue