mirror of
https://github.com/golang/go
synced 2024-11-20 04:14:49 -07:00
reflect: document and test TypeOf(nil)
Fixes #3549. R=golang-dev, dsymonds CC=golang-dev https://golang.org/cl/6107047
This commit is contained in:
parent
0cc8ee9808
commit
53372903c7
@ -638,6 +638,7 @@ var (
|
|||||||
|
|
||||||
var deepEqualTests = []DeepEqualTest{
|
var deepEqualTests = []DeepEqualTest{
|
||||||
// Equalities
|
// Equalities
|
||||||
|
{nil, nil, true},
|
||||||
{1, 1, true},
|
{1, 1, true},
|
||||||
{int32(1), int32(1), true},
|
{int32(1), int32(1), true},
|
||||||
{0.5, 0.5, true},
|
{0.5, 0.5, true},
|
||||||
@ -696,6 +697,10 @@ func TestDeepEqual(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestTypeOf(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 {
|
for _, test := range deepEqualTests {
|
||||||
v := ValueOf(test.a)
|
v := ValueOf(test.a)
|
||||||
if !v.IsValid() {
|
if !v.IsValid() {
|
||||||
|
@ -940,6 +940,7 @@ func toType(p *runtimeType) Type {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// TypeOf returns the reflection Type of the value in the interface{}.
|
// TypeOf returns the reflection Type of the value in the interface{}.
|
||||||
|
// TypeOf(nil) returns nil.
|
||||||
func TypeOf(i interface{}) Type {
|
func TypeOf(i interface{}) Type {
|
||||||
eface := *(*emptyInterface)(unsafe.Pointer(&i))
|
eface := *(*emptyInterface)(unsafe.Pointer(&i))
|
||||||
return toType(eface.typ)
|
return toType(eface.typ)
|
||||||
|
Loading…
Reference in New Issue
Block a user