@@ -41,11 +41,8 @@ func diff(lhs, rhs interface{}, visited *visited) (Differ, error) {
41
41
lhsVal := reflect .ValueOf (lhs )
42
42
rhsVal := reflect .ValueOf (rhs )
43
43
44
- if lhs == nil && rhs == nil {
45
- return scalar {lhs , rhs }, nil
46
- }
47
- if lhs == nil || rhs == nil {
48
- return types {lhs , rhs }, nil
44
+ if d , ok := nilCheck (lhs , rhs ); ok {
45
+ return d , nil
49
46
}
50
47
if err := visited .add (lhsVal , rhsVal ); err != nil {
51
48
return types {lhs , rhs }, ErrCyclic
@@ -56,6 +53,7 @@ func diff(lhs, rhs interface{}, visited *visited) (Differ, error) {
56
53
if lhsVal .Kind () != rhsVal .Kind () {
57
54
return types {lhs , rhs }, nil
58
55
}
56
+
59
57
if lhsVal .Kind () == reflect .Slice {
60
58
return newSlice (lhs , rhs , visited )
61
59
}
@@ -66,6 +64,17 @@ func diff(lhs, rhs interface{}, visited *visited) (Differ, error) {
66
64
return types {lhs , rhs }, & ErrUnsupported {lhsVal .Type (), rhsVal .Type ()}
67
65
}
68
66
67
+ func nilCheck (lhs , rhs interface {}) (Differ , bool ) {
68
+ if lhs == nil && rhs == nil {
69
+ return scalar {lhs , rhs }, true
70
+ }
71
+ if lhs == nil || rhs == nil {
72
+ return types {lhs , rhs }, true
73
+ }
74
+
75
+ return nil , false
76
+ }
77
+
69
78
func (t Type ) String () string {
70
79
switch t {
71
80
case Identical :
0 commit comments