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: default avatarIan Lance Taylor <iant@golang.org>
Run-TryBot: David Crawshaw <crawshaw@golang.org>
parent 74a9bad6
......@@ -5659,20 +5659,25 @@ type nameTest struct {
}
var nameTests = []nameTest{
{int32(0), "int32"},
{D1{}, "D1"},
{[]D1{}, ""},
{(chan D1)(nil), ""},
{(func() D1)(nil), ""},
{(<-chan D1)(nil), ""},
{(chan<- D1)(nil), ""},
{TheNameOfThisTypeIsExactly255BytesLongSoWhenTheCompilerPrependsTheReflectTestPackageNameAndExtraStarTheLinkerRuntimeAndReflectPackagesWillHaveToCorrectlyDecodeTheSecondLengthByte0123456789_0123456789_0123456789_0123456789_0123456789_012345678(0), "TheNameOfThisTypeIsExactly255BytesLongSoWhenTheCompilerPrependsTheReflectTestPackageNameAndExtraStarTheLinkerRuntimeAndReflectPackagesWillHaveToCorrectlyDecodeTheSecondLengthByte0123456789_0123456789_0123456789_0123456789_0123456789_012345678"},
{(*int32)(nil), "int32"},
{(*D1)(nil), "D1"},
{(*[]D1)(nil), ""},
{(*chan D1)(nil), ""},
{(*func() D1)(nil), ""},
{(*<-chan D1)(nil), ""},
{(*chan<- D1)(nil), ""},
{(*interface{})(nil), ""},
{(*interface {
F()
})(nil), ""},
{(*TheNameOfThisTypeIsExactly255BytesLongSoWhenTheCompilerPrependsTheReflectTestPackageNameAndExtraStarTheLinkerRuntimeAndReflectPackagesWillHaveToCorrectlyDecodeTheSecondLengthByte0123456789_0123456789_0123456789_0123456789_0123456789_012345678)(nil), "TheNameOfThisTypeIsExactly255BytesLongSoWhenTheCompilerPrependsTheReflectTestPackageNameAndExtraStarTheLinkerRuntimeAndReflectPackagesWillHaveToCorrectlyDecodeTheSecondLengthByte0123456789_0123456789_0123456789_0123456789_0123456789_012345678"},
}
func TestNames(t *testing.T) {
for _, test := range nameTests {
if got := TypeOf(test.v).Name(); got != test.want {
t.Errorf("%T Name()=%q, want %q", test.v, got, test.want)
typ := TypeOf(test.v).Elem()
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 {
if hasPrefix(s, "func(") {
return ""
}
if hasPrefix(s, "interface {") {
return ""
}
switch s[0] {
case '[', '*', '<':
return ""
......
......@@ -132,6 +132,9 @@ func (t *_type) name() string {
if hasPrefix(s, "func(") {
return ""
}
if hasPrefix(s, "interface {") {
return ""
}
switch s[0] {
case '[', '*', '<':
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