diff --git a/src/reflect/type.go b/src/reflect/type.go index 54a5e349..db09fb43 100644 --- a/src/reflect/type.go +++ b/src/reflect/type.go @@ -502,7 +502,13 @@ func pointerTo(t *rawType) *rawType { func (t *rawType) String() string { if t.isNamed() { - return t.PkgPath() + "." + t.Name() + path := t.PkgPath() + slash := len(path) - 1 + for slash >= 0 && path[slash] != '/' { + slash-- + } + shortened := path[slash+1:] + return shortened + "." + t.Name() } switch t.Kind() { diff --git a/src/reflect/value_test.go b/src/reflect/value_test.go index 05b0139b..1231a790 100644 --- a/src/reflect/value_test.go +++ b/src/reflect/value_test.go @@ -1,6 +1,7 @@ package reflect_test import ( + "encoding/base64" . "reflect" "sort" "testing" @@ -264,6 +265,11 @@ func TestNamedTypes(t *testing.T) { if got, want := ValueOf(m).String(), ""; got != want { t.Errorf("Value.String()=%v, want %v", got, want) } + + if got, want := TypeOf(base64.Encoding{}).String(), "base64.Encoding"; got != want { + t.Errorf("Type.String(base64.Encoding{})=%v, want %v", got, want) + } + } func TestStruct(t *testing.T) {