felangel / equatable

A Dart package that helps to implement value based equality without needing to explicitly override == and hashCode.

Home Page:https://pub.dev/packages/equatable

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

`Foo(1) == Foo(1.0)` is false

Mike278 opened this issue · comments

commented
class Foo with EquatableMixin {
  final num bar;
  Foo(this.bar);

  @override
  List<Object?> get props => [bar];
}

int anInt = 1;
double aDouble = 1.0;
print(anInt == aDouble); // true
print(Foo(anInt) == Foo(aDouble)); // false

I understand why comparing runtimeTypes is useful in general, but I wonder if there should be a special case for num - especially considering Dart's support for assigning integer literals to doubles.

Making an exception for num could lead to unexpected behavior for users who rely on strict type equality. Can you override the equality check in your own classes to suit your needs?

Agreed with @wednesdei closing for now as this is working as expected.