1
0
mirror of https://github.com/golang/go synced 2024-11-25 01:08:02 -07:00

gc: don't emit pkgpath for error type.

Fixes #2660.

R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/5557060
This commit is contained in:
David Symonds 2012-01-20 09:26:17 +11:00
parent bb7eca177a
commit ee09a8cd9f
3 changed files with 15 additions and 4 deletions

View File

@ -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);

View File

@ -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)
}
}
}

View File

@ -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