Commit 217be5b3 authored by David Crawshaw's avatar David Crawshaw

reflect: unnamed interface types have no name

Fixes #15468

Change-Id: I8723171f87774a98d5e80e7832ebb96dd1fbea74
Reviewed-on: https://go-review.googlesource.com/22524Reviewed-by: 's avatarIan Lance Taylor <iant@golang.org>
Run-TryBot: David Crawshaw <crawshaw@golang.org>
parent 74a9bad6
...@@ -5659,20 +5659,25 @@ type nameTest struct { ...@@ -5659,20 +5659,25 @@ type nameTest struct {
} }
var nameTests = []nameTest{ var nameTests = []nameTest{
{int32(0), "int32"}, {(*int32)(nil), "int32"},
{D1{}, "D1"}, {(*D1)(nil), "D1"},
{[]D1{}, ""}, {(*[]D1)(nil), ""},
{(chan D1)(nil), ""}, {(*chan D1)(nil), ""},
{(func() D1)(nil), ""}, {(*func() D1)(nil), ""},
{(<-chan D1)(nil), ""}, {(*<-chan D1)(nil), ""},
{(chan<- D1)(nil), ""}, {(*chan<- D1)(nil), ""},
{TheNameOfThisTypeIsExactly255BytesLongSoWhenTheCompilerPrependsTheReflectTestPackageNameAndExtraStarTheLinkerRuntimeAndReflectPackagesWillHaveToCorrectlyDecodeTheSecondLengthByte0123456789_0123456789_0123456789_0123456789_0123456789_012345678(0), "TheNameOfThisTypeIsExactly255BytesLongSoWhenTheCompilerPrependsTheReflectTestPackageNameAndExtraStarTheLinkerRuntimeAndReflectPackagesWillHaveToCorrectlyDecodeTheSecondLengthByte0123456789_0123456789_0123456789_0123456789_0123456789_012345678"}, {(*interface{})(nil), ""},
{(*interface {
F()
})(nil), ""},
{(*TheNameOfThisTypeIsExactly255BytesLongSoWhenTheCompilerPrependsTheReflectTestPackageNameAndExtraStarTheLinkerRuntimeAndReflectPackagesWillHaveToCorrectlyDecodeTheSecondLengthByte0123456789_0123456789_0123456789_0123456789_0123456789_012345678)(nil), "TheNameOfThisTypeIsExactly255BytesLongSoWhenTheCompilerPrependsTheReflectTestPackageNameAndExtraStarTheLinkerRuntimeAndReflectPackagesWillHaveToCorrectlyDecodeTheSecondLengthByte0123456789_0123456789_0123456789_0123456789_0123456789_012345678"},
} }
func TestNames(t *testing.T) { func TestNames(t *testing.T) {
for _, test := range nameTests { for _, test := range nameTests {
if got := TypeOf(test.v).Name(); got != test.want { typ := TypeOf(test.v).Elem()
t.Errorf("%T Name()=%q, want %q", test.v, got, test.want) if got := typ.Name(); got != test.want {
t.Errorf("%v Name()=%q, want %q", typ, got, test.want)
} }
} }
} }
......
...@@ -867,6 +867,9 @@ func (t *rtype) Name() string { ...@@ -867,6 +867,9 @@ func (t *rtype) Name() string {
if hasPrefix(s, "func(") { if hasPrefix(s, "func(") {
return "" return ""
} }
if hasPrefix(s, "interface {") {
return ""
}
switch s[0] { switch s[0] {
case '[', '*', '<': case '[', '*', '<':
return "" return ""
......
...@@ -132,6 +132,9 @@ func (t *_type) name() string { ...@@ -132,6 +132,9 @@ func (t *_type) name() string {
if hasPrefix(s, "func(") { if hasPrefix(s, "func(") {
return "" return ""
} }
if hasPrefix(s, "interface {") {
return ""
}
switch s[0] { switch s[0] {
case '[', '*', '<': case '[', '*', '<':
return "" return ""
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment