Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
G
golang
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
golang
Commits
4e65478c
Commit
4e65478c
authored
Nov 14, 2011
by
Russ Cox
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
reflect: empty slice/map is not DeepEqual to nil
R=golang-dev, bradfitz CC=golang-dev
https://golang.org/cl/5373095
parent
a7f1e10d
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
14 additions
and
0 deletions
+14
-0
all_test.go
src/pkg/reflect/all_test.go
+8
-0
deepequal.go
src/pkg/reflect/deepequal.go
+6
-0
No files found.
src/pkg/reflect/all_test.go
View file @
4e65478c
...
...
@@ -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
},
...
...
src/pkg/reflect/deepequal.go
View file @
4e65478c
...
...
@@ -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
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment