diff --git a/diff.go b/diff.go index 6aa7f74..125e7eb 100644 --- a/diff.go +++ b/diff.go @@ -142,6 +142,10 @@ func (w diffPrinter) diff(av, bv reflect.Value) { w := w.relabel(fmt.Sprintf("[%#v]", k)) w.printf("(missing) != %q", bv.MapIndex(k)) } + if av.IsNil() != bv.IsNil() { + w.printf("%#v != %#v", av, bv) + break + } case reflect.Ptr: switch { case av.IsNil() && !bv.IsNil(): @@ -161,6 +165,10 @@ func (w diffPrinter) diff(av, bv reflect.Value) { for i := 0; i < lenA; i++ { w.relabel(fmt.Sprintf("[%d]", i)).diff(av.Index(i), bv.Index(i)) } + if av.IsNil() != bv.IsNil() { + w.printf("%#v != %#v", av, bv) + break + } case reflect.String: if a, b := av.String(), bv.String(); a != b { w.printf("%q != %q", a, b) diff --git a/diff_test.go b/diff_test.go index a951e4b..7e14798 100644 --- a/diff_test.go +++ b/diff_test.go @@ -40,6 +40,8 @@ var ( f1 = func() {} i0 = 0 i1 = 1 + s0 []int + m0 map[int]int ) var diffs = []difftest{ @@ -126,6 +128,8 @@ var diffs = []difftest{ struct{ x unsafe.Pointer }{unsafe.Pointer(uintptr(1))}, []string{`x: 0x0 != 0x1`}, }, + {[]int{}, s0, []string{"[]int{} != []int(nil)"}}, + {map[int]int{}, m0, []string{"map[int]int{} != map[int]int(nil)"}}, } func TestDiff(t *testing.T) {