Skip to content

Commit

Permalink
Make DefaultEquality<Null> work at runtime (flutter#73)
Browse files Browse the repository at this point in the history
Works around dart-lang/sdk#32415
  • Loading branch information
a-siva authored and nex3 committed Mar 6, 2018
1 parent 5943e16 commit 6ff408a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
## 1.14.6

* Make `DefaultEquality`'s `equals()` and `hash()` methods take any `Object`
rather than objects of type `E`. This makes `const DefaultEquality<Null>()`
usable as `Equality<E>` for any `E`, which means it can be used in a const
context which expects `Equality<E>`.

This makes the default arguments of various other const equality constructors
work in strong mode.

## 1.14.5

* Fix issue with `EmptyUnmodifiableSet`'s stubs that were introduced in 1.14.4.
Expand Down
8 changes: 6 additions & 2 deletions lib/src/equality.dart
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,14 @@ class EqualityBy<E, F> implements Equality<E> {
///
/// This equality uses the objects' own [Object.==] and [Object.hashCode] for
/// the equality.
///
/// Note that [equals] and [hash] take `Object`s rather than `E`s. This allows
/// `E` to be inferred as `Null` in const contexts where `E` wouldn't be a
/// compile-time constant, while still allowing the class to be used at runtime.
class DefaultEquality<E> implements Equality<E> {
const DefaultEquality();
bool equals(E e1, E e2) => e1 == e2;
int hash(E e) => e.hashCode;
bool equals(Object e1, Object e2) => e1 == e2;
int hash(Object e) => e.hashCode;
bool isValidKey(Object o) => true;
}

Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: collection
version: 1.14.5
version: 1.14.6
author: Dart Team <[email protected]>
description: Collections and utilities functions and classes related to collections.
homepage: https://www.github.com/dart-lang/collection
Expand Down

0 comments on commit 6ff408a

Please sign in to comment.