diff --git a/src/cmd/gc/reflect.c b/src/cmd/gc/reflect.c index f31053a1bea..49aca0906c7 100644 --- a/src/cmd/gc/reflect.c +++ b/src/cmd/gc/reflect.c @@ -357,7 +357,7 @@ dextratype(Sym *sym, int off, Type *t, int ptroff) s = sym; if(t->sym) { ot = dgostringptr(s, ot, t->sym->name); - if(t != types[t->etype]) + if(t != types[t->etype] && t != errortype) ot = dgopkgpath(s, ot, t->sym->pkg); else ot = dgostringptr(s, ot, nil); diff --git a/src/pkg/reflect/all_test.go b/src/pkg/reflect/all_test.go index 2f9f83fbc61..63b127d1029 100644 --- a/src/pkg/reflect/all_test.go +++ b/src/pkg/reflect/all_test.go @@ -1364,8 +1364,19 @@ func TestFieldByName(t *testing.T) { } func TestImportPath(t *testing.T) { - if path := TypeOf(&base64.Encoding{}).Elem().PkgPath(); path != "encoding/base64" { - t.Errorf(`TypeOf(&base64.Encoding{}).Elem().PkgPath() = %q, want "encoding/base64"`, path) + tests := []struct { + t Type + path string + }{ + {TypeOf(&base64.Encoding{}).Elem(), "encoding/base64"}, + {TypeOf(uint(0)), ""}, + {TypeOf(map[string]int{}), ""}, + {TypeOf((*error)(nil)).Elem(), ""}, + } + for _, test := range tests { + if path := test.t.PkgPath(); path != test.path { + t.Errorf("%v.PkgPath() = %q, want %q", test.t, path, test.path) + } } } diff --git a/src/pkg/reflect/type.go b/src/pkg/reflect/type.go index d522a6a0b27..15b32efe374 100644 --- a/src/pkg/reflect/type.go +++ b/src/pkg/reflect/type.go @@ -69,7 +69,7 @@ type Type interface { // PkgPath returns the type's package path. // The package path is a full package import path like "encoding/base64". - // PkgPath returns an empty string for unnamed types. + // PkgPath returns an empty string for unnamed or predeclared types. PkgPath() string // Size returns the number of bytes needed to store