]> Cypherpunks repositories - gostls13.git/commitdiff
gc: don't emit pkgpath for error type.
authorDavid Symonds <dsymonds@golang.org>
Thu, 19 Jan 2012 22:26:17 +0000 (09:26 +1100)
committerDavid Symonds <dsymonds@golang.org>
Thu, 19 Jan 2012 22:26:17 +0000 (09:26 +1100)
Fixes #2660.

R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/5557060

src/cmd/gc/reflect.c
src/pkg/reflect/all_test.go
src/pkg/reflect/type.go

index f31053a1bea9a6492341ff4f02e1ed620040e13f..49aca0906c7956d24b37c28265adc3a85e0972a6 100644 (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);
index 2f9f83fbc6160933adf7bb5b0991e362424e382d..63b127d1029e1c9fd7294e16f3372e64dea278a8 100644 (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)
+               }
        }
 }
 
index d522a6a0b279d619e30742caae0215fbfd09f2e9..15b32efe374858b77cfb1263a25eff56f38dc9b2 100644 (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