Skip to content

Instantly share code, notes, and snippets.

@iapicca
Created August 2, 2022 11:24
Show Gist options
  • Select an option

  • Save iapicca/94b8a1223d48a5dd7cb43e9e2cee50cb to your computer and use it in GitHub Desktop.

Select an option

Save iapicca/94b8a1223d48a5dd7cb43e9e2cee50cb to your computer and use it in GitHub Desktop.
weird equality issue
List<int> integersUntil(int limit) => [for (var i = 0; i < limit; i++) i];
class Foo {
final List<int> bar;
final List<int> baz;
const Foo(this.bar, this.baz);
@override
bool operator ==(Object other) => other is Foo && other.hashCode == hashCode;
@override
int get hashCode => Object.hash(bar, baz);
}
void main() {
final foo1 = Foo(
integersUntil(10),
integersUntil(100),
);
final foo2 = Foo(
integersUntil(10),
integersUntil(100),
);
print(foo1 == foo2);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment