]> Cypherpunks repositories - gostls13.git/commitdiff
reflect: unnamed interface types have no name
authorDavid Crawshaw <crawshaw@golang.org>
Wed, 27 Apr 2016 16:49:27 +0000 (12:49 -0400)
committerDavid Crawshaw <crawshaw@golang.org>
Wed, 27 Apr 2016 18:06:20 +0000 (18:06 +0000)
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>

src/reflect/all_test.go
src/reflect/type.go
src/runtime/type.go

index aff8ea253b90cea18069b03b65e3cc1b770b143e..870ccbf521eb7b58bea8f0dd48c36190cb8204da 100644 (file)
@@ -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)
                }
        }
 }
index ff6ff14c836cac0b76cf5e2f4dde9b49a25bbeb7..0213d56e831a23eef7e6a0f9be59cbf755796384 100644 (file)
@@ -867,6 +867,9 @@ func (t *rtype) Name() string {
        if hasPrefix(s, "func(") {
                return ""
        }
+       if hasPrefix(s, "interface {") {
+               return ""
+       }
        switch s[0] {
        case '[', '*', '<':
                return ""
index 9e4c40553a40672982b322888b0dd18d1c87612f..608c601abd2973740aed2dea58a19dfdf21fd25f 100644 (file)
@@ -132,6 +132,9 @@ func (t *_type) name() string {
        if hasPrefix(s, "func(") {
                return ""
        }
+       if hasPrefix(s, "interface {") {
+               return ""
+       }
        switch s[0] {
        case '[', '*', '<':
                return ""