Skip to content

Commit

Permalink
fix: props are not of type Comparable (#149)
Browse files Browse the repository at this point in the history
  • Loading branch information
felangel committed Aug 19, 2022
1 parent cf498ac commit c5f1bbe
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
8 changes: 2 additions & 6 deletions lib/src/equatable_utils.dart
@@ -1,5 +1,3 @@
import 'dart:collection';

import 'package:collection/collection.dart';
import 'package:equatable/equatable.dart';

Expand Down Expand Up @@ -48,10 +46,8 @@ int _combine(int hash, dynamic object) {
});
return hash;
}
if (object is Set && object is! SplayTreeSet) {
// this is needed to have a consistent iteration order so that the produced
// hash is consistent independently of the Set insertion order
object = SplayTreeSet<dynamic>.from(object);
if (object is Set) {
object = object.sorted(((dynamic a, dynamic b) => a.hashCode - b.hashCode));
}
if (object is Iterable) {
for (final value in object) {
Expand Down
11 changes: 11 additions & 0 deletions test/equatable_test.dart
Expand Up @@ -1000,6 +1000,17 @@ void main() {
expect(instanceA != instanceB, true);
expect(instanceA.hashCode != instanceB.hashCode, true);
});

test('should support non-comparable types', () {
final instanceA = SimpleEquatable<Set<Object>>(
Set.from(<Object>[Object()]),
);
final instanceB = SimpleEquatable<Set<Object>>(
Set.from(<Object>[Object()]),
);
expect(instanceA == instanceB, false);
expect(instanceA.hashCode == instanceB.hashCode, false);
});
});
});

Expand Down

0 comments on commit c5f1bbe

Please sign in to comment.