mirror of
https://github.com/golang/go
synced 2024-11-20 03:34:40 -07:00
reflect: empty slice/map is not DeepEqual to nil
R=golang-dev, bradfitz CC=golang-dev https://golang.org/cl/5373095
This commit is contained in:
parent
a7f1e10d24
commit
4e65478cbd
@ -651,6 +651,14 @@ var deepEqualTests = []DeepEqualTest{
|
||||
{nil, 1, false},
|
||||
{1, nil, false},
|
||||
|
||||
// Nil vs empty: not the same.
|
||||
{[]int{}, []int(nil), false},
|
||||
{[]int{}, []int{}, true},
|
||||
{[]int(nil), []int(nil), true},
|
||||
{map[int]int{}, map[int]int(nil), false},
|
||||
{map[int]int{}, map[int]int{}, true},
|
||||
{map[int]int(nil), map[int]int(nil), true},
|
||||
|
||||
// Mismatched types
|
||||
{1, 1.0, false},
|
||||
{int32(1), int64(1), false},
|
||||
|
@ -69,6 +69,9 @@ func deepValueEqual(v1, v2 Value, visited map[uintptr]*visit, depth int) (b bool
|
||||
}
|
||||
return true
|
||||
case Slice:
|
||||
if v1.IsNil() != v2.IsNil() {
|
||||
return false
|
||||
}
|
||||
if v1.Len() != v2.Len() {
|
||||
return false
|
||||
}
|
||||
@ -93,6 +96,9 @@ func deepValueEqual(v1, v2 Value, visited map[uintptr]*visit, depth int) (b bool
|
||||
}
|
||||
return true
|
||||
case Map:
|
||||
if v1.IsNil() != v2.IsNil() {
|
||||
return false
|
||||
}
|
||||
if v1.Len() != v2.Len() {
|
||||
return false
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user