fix: don't test for runtimeType equality for object comparison - #188
fix: don't test for runtimeType equality for object comparison#188devmil wants to merge 1 commit into
Conversation
as this breaks type hierarchies like `num`
|
I’ll take a look shortly! Sorry for the inconvenience and thanks for the PR 💙 |
|
This isn't quite correct. I merged #189 which should fix this specifically. |
|
This should be fixed in v2.0.7 🎉 |
|
Thanks! But why is the runtime type check needed at all? Is there a use case that would yield a false positive in that case? |
|
@felangel after thinking more about it I came to the conclusion to even strongly disagree 😁 |
|
addition: I already found one case in our code base. |
|
@devmil take the following case: class Dog extends Equatable {
Dog(this.name);
final String name;
@override
List<Object> get props => [name];
}
class Cat extends Equatable {
Cat(this.name);
final String name;
@override
List<Object> get props => [name];
}
void main() {
final fluffyDog = Dog(“fluffy”);
final fluffyCat = Cat(“fluffy”);
print(fluffyDog == fluffyCat);
}An instance of Dog and an instance of Cat should not be considered equal even if they have the same name. Apologies for code/format I wrote this on my phone 😅. |
Not bad for typing that on a phone 😅 I think this case is covered already as the initial check for the runtimeType stays ( equatable/lib/src/equatable.dart Line 48 in 834d167 equatable/lib/src/equatable_mixin.dart Line 24 in 834d167 This check is only removed when bridging over to non-Equatable territory So it is the responsibility of the equals operator implementation to decide if this check is needed, or not |
I’ll take a closer look shortly. Feel free to reopen the PR and make sure the above test case is included 👍 |
Status
READY
Breaking Changes
NO
Description
This PR fixes an issue introduced with 2.0.6 that int and double num values are no longer treated as equal (like 0 != 0.0)
Todos
Steps to Test or Reproduce
Have an equatable class with a num field.
Create two instances, set the num field to
0on the first instance and to0.0on the second instance.Test equality.
Impact to Remaining Code Base
Should be fine