diff options
| author | David Crawshaw <crawshaw@golang.org> | 2016-04-27 12:49:27 -0400 |
|---|---|---|
| committer | David Crawshaw <crawshaw@golang.org> | 2016-04-27 18:06:20 +0000 |
| commit | 217be5b35d8fb0f812ca59bf7dec3aa0fb850c46 (patch) | |
| tree | 3dd27fea75b9d98f173ee1fc21c2fe78bec30998 /src | |
| parent | 74a9bad63899ffb02b747678c2c181ffb13983b9 (diff) | |
| download | go-217be5b35d8fb0f812ca59bf7dec3aa0fb850c46.tar.xz | |
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>
Diffstat (limited to 'src')
| -rw-r--r-- | src/reflect/all_test.go | 25 | ||||
| -rw-r--r-- | src/reflect/type.go | 3 | ||||
| -rw-r--r-- | src/runtime/type.go | 3 |
3 files changed, 21 insertions, 10 deletions
diff --git a/src/reflect/all_test.go b/src/reflect/all_test.go index aff8ea253b..870ccbf521 100644 --- a/src/reflect/all_test.go +++ b/src/reflect/all_test.go @@ -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) } } } diff --git a/src/reflect/type.go b/src/reflect/type.go index ff6ff14c83..0213d56e83 100644 --- a/src/reflect/type.go +++ b/src/reflect/type.go @@ -867,6 +867,9 @@ func (t *rtype) Name() string { if hasPrefix(s, "func(") { return "" } + if hasPrefix(s, "interface {") { + return "" + } switch s[0] { case '[', '*', '<': return "" diff --git a/src/runtime/type.go b/src/runtime/type.go index 9e4c40553a..608c601abd 100644 --- a/src/runtime/type.go +++ b/src/runtime/type.go @@ -132,6 +132,9 @@ func (t *_type) name() string { if hasPrefix(s, "func(") { return "" } + if hasPrefix(s, "interface {") { + return "" + } switch s[0] { case '[', '*', '<': return "" |
