]> Cypherpunks repositories - gostls13.git/commitdiff
[release-branch.go1] reflect: document and test TypeOf(nil)
authorRob Pike <r@golang.org>
Mon, 23 Apr 2012 02:07:02 +0000 (12:07 +1000)
committerRob Pike <r@golang.org>
Mon, 23 Apr 2012 02:07:02 +0000 (12:07 +1000)
««« backport 82aaf0925029
reflect: document and test TypeOf(nil)
Fixes #3549.

R=golang-dev, dsymonds
CC=golang-dev
https://golang.org/cl/6107047
»»»

src/pkg/reflect/all_test.go
src/pkg/reflect/type.go

index 6bb061398148f9f89841a1b8721ee081d6ca0b9f..e331405635a7f5d4ab6724f1079fbae67fe7cd83 100644 (file)
@@ -638,6 +638,7 @@ var (
 
 var deepEqualTests = []DeepEqualTest{
        // Equalities
+       {nil, nil, true},
        {1, 1, true},
        {int32(1), int32(1), true},
        {0.5, 0.5, true},
@@ -696,6 +697,10 @@ func TestDeepEqual(t *testing.T) {
 }
 
 func TestTypeOf(t *testing.T) {
+       // Special case for nil
+       if typ := TypeOf(nil); typ != nil {
+               t.Errorf("expected nil type for nil value; got %v", typ)
+       }
        for _, test := range deepEqualTests {
                v := ValueOf(test.a)
                if !v.IsValid() {
index 64550b8f6c6a52af8add0ab65f7dfa4ec9ff0b84..060bde3aff7de138f61f0c3c03cbdb341e34913b 100644 (file)
@@ -940,6 +940,7 @@ func toType(p *runtimeType) Type {
 }
 
 // TypeOf returns the reflection Type of the value in the interface{}.
+// TypeOf(nil) returns nil.
 func TypeOf(i interface{}) Type {
        eface := *(*emptyInterface)(unsafe.Pointer(&i))
        return toType(eface.typ)