Skip to content

Commit 14a3069

Browse files
committed
Wrong side checked when handling cyclical detection.
In `visited.add`, `lhs` was checked for an empty map/slice when handling the `rhs` side of the cyclical detection.
1 parent d6460e1 commit 14a3069

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

diff/diff.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ func (v *visited) add(lhs, rhs reflect.Value) error {
190190
}
191191
v.lhs = append(v.lhs, lhs.Pointer())
192192
}
193-
if canAddr(rhs) && !isEmptyMapOrSlice(lhs) {
193+
if canAddr(rhs) && !isEmptyMapOrSlice(rhs) {
194194
if inPointers(v.rhs, rhs) {
195195
return ErrCyclic
196196
}

diff/diff_test.go

+5
Original file line numberDiff line numberDiff line change
@@ -616,6 +616,9 @@ func TestCircular(t *testing.T) {
616616
0: "foo",
617617
},
618618
},
619+
1: []interface{}{
620+
"bar", "baz",
621+
},
619622
}
620623
emptySlice := map[int]interface{}{
621624
0: []interface{}{},
@@ -644,6 +647,8 @@ func TestCircular(t *testing.T) {
644647
{lhs: first, rhs: second, wantError: true},
645648
{lhs: first, rhs: notCyclic, wantError: true},
646649
{lhs: notCyclic, rhs: first, wantError: true},
650+
{lhs: notCyclic, rhs: emptySlice, wantError: false},
651+
{lhs: notCyclic, rhs: emptyMap, wantError: false},
647652
{lhs: notCyclic, rhs: notCyclic},
648653
{lhs: emptySlice, rhs: emptySliceNotRepeating},
649654
{lhs: emptySliceNotRepeating, rhs: emptySlice},

0 commit comments

Comments
 (0)