1
0
mirror of https://github.com/golang/go synced 2024-11-22 13:45:00 -07:00

nil in DeepEqual

R=r
DELTA=13  (5 added, 6 deleted, 2 changed)
OCL=34337
CL=34343
This commit is contained in:
Russ Cox 2009-09-03 15:45:43 -07:00
parent 107d404378
commit 33be0c6465
2 changed files with 7 additions and 8 deletions

View File

@ -378,6 +378,8 @@ var deepEqualTests = []DeepEqualTest {
DeepEqualTest{ map[int]string{ 1:"one", 2:"txo" }, map[int]string{ 2:"two", 1:"one" }, false },
DeepEqualTest{ map[int]string{ 1:"one", }, map[int]string{ 2:"two", 1:"one" }, false },
DeepEqualTest{ map[int]string{ 2:"two", 1:"one" }, map[int]string{ 1:"one", }, false },
DeepEqualTest{ nil, 1, false },
DeepEqualTest{ 1, nil, false },
// Mismatched types
DeepEqualTest{ 1, 1.0, false },

View File

@ -22,11 +22,8 @@ type visit struct {
// comparisons that have already been seen, which allows short circuiting on
// recursive types.
func deepValueEqual(v1, v2 Value, visited map[uintptr]*visit, depth int) bool {
if v1 == nil {
return v2 == nil
}
if v2 == nil {
return false
if v1 == nil || v2 == nil {
return v1 == v2
}
if v1.Type() != v2.Type() {
return false;
@ -126,11 +123,11 @@ func deepValueEqual(v1, v2 Value, visited map[uintptr]*visit, depth int) bool {
// but will scan members of arrays, slices, and fields of structs. It correctly
// handles recursive types.
func DeepEqual(a1, a2 interface{}) bool {
if a1 == nil || a2 == nil {
return a1 == a2;
}
v1 := NewValue(a1);
v2 := NewValue(a2);
if v1 == nil {
return v1 == v2;
}
if v1.Type() != v2.Type() {
return false;
}