#49: Fixed issue with empty lists (#53)
diff --git a/lib/src/equatable_utils.dart b/lib/src/equatable_utils.dart
index 9fd3539..d22a77f 100644
--- a/lib/src/equatable_utils.dart
+++ b/lib/src/equatable_utils.dart
@@ -35,8 +35,9 @@
});
return hash;
}
- if (object is Iterable) return mapPropsToHashCode(object);
- hash = 0x1fffffff & (hash + object.hashCode);
+ final objectHashCode =
+ object is Iterable ? mapPropsToHashCode(object) : object.hashCode;
+ hash = 0x1fffffff & (hash + objectHashCode);
hash = 0x1fffffff & (hash + ((0x0007ffff & hash) << 10));
return hash ^ (hash >> 6);
}
diff --git a/test/equatable_mixin_test.dart b/test/equatable_mixin_test.dart
index 7defdbf..4454f68 100644
--- a/test/equatable_mixin_test.dart
+++ b/test/equatable_mixin_test.dart
@@ -434,6 +434,22 @@
);
expect(instanceA == instanceB, false);
});
+
+ test('should return different hashCode even for empty list', () {
+ final instance = ComplexEquatable(
+ name: 'Joe',
+ age: 40,
+ hairColor: Color.black,
+ children: [],
+ );
+ final instance2 = ComplexEquatable(
+ name: 'John',
+ age: 40,
+ hairColor: Color.black,
+ children: [],
+ );
+ expect(instance.hashCode != instance2.hashCode, true);
+ });
});
group('Json Equatable', () {