Commit 33be0c64 authored by Russ Cox's avatar Russ Cox

nil in DeepEqual

R=r
DELTA=13  (5 added, 6 deleted, 2 changed)
OCL=34337
CL=34343
parent 107d4043
......@@ -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 },
......
......@@ -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;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment