mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
reflect: unnamed interface types have no name
Fixes #15468 Change-Id: I8723171f87774a98d5e80e7832ebb96dd1fbea74 Reviewed-on: https://go-review.googlesource.com/22524 Reviewed-by: Ian Lance Taylor <iant@golang.org> Run-TryBot: David Crawshaw <crawshaw@golang.org>
This commit is contained in:
parent
74a9bad638
commit
217be5b35d
3 changed files with 21 additions and 10 deletions
|
|
@ -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 {
|
||||||
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 {
|
||||||
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 ""
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue