felangel / equatable

A Dart package that helps to implement value based equality without needing to explicitly override == and hashCode.
https://pub.dev/packages/equatable
MIT License
901 stars 100 forks source link

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

Closed Mike278 closed 9 months ago

Mike278 commented 10 months ago
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.

ghost commented 9 months ago

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?

felangel commented 9 months ago

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