-
-
Notifications
You must be signed in to change notification settings - Fork 237
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support deep collection equality in records #953
Comments
operator ==
is not correct when using dart 3 records containing List (checks reference instead of list content)
Not really a bug, so editing this a bit That's consistent with how Freezed works when dealing with objects: class Result<T> {
Result(this.value);
final T value;
}
@freezed
class SampleClass with _$SampleClass {
const SampleClass._();
const factory SampleClass({
required Result<List<int>> obj,
}) = _SampleClass;
} We could support explicitly typed records. @freezed
class SampleClass with _$SampleClass {
const SampleClass._();
const factory SampleClass(Object obj) = _SampleClass;
}
// Will be false, and there's no way to support this any other way.
SampleClass(([1],)) == SampleClass(([1],) In the end, the issue is that records aren't introspectable. So I'm not sure that's desirable. |
Hmm, I see your perspective. I still think from a user point of view it would make more sense for records to check equality based on content. Otherwise I guess the whole equality becomes pointless as it will likely almost always return false. At the very least I'd suggest adding warnings when records are used in freezed classes. P.S. Never checked / not sure how code analyzer/gen works in dart. I hope it can detect dart records. |
The main issue is that like mentioned, whenever a record is assigned to Object, equality as you desire would stop working. I feel like it would be very confusing if sometimes deep equality in records worked, and sometimes it didn't. Supporting it would also require significant work, as DeepCollectionEquality wouldn't work anymore. I'd suggest making a custom List which overrides == |
Describe the bug
operator ==
is not correct when using dart 3 records containing List (checks reference instead of list content)Test Class:
Failing Test:
Generated (wrong) equality function:
<Please add a small sample to that can be executed to reproduce the problem. As a general rule, 100 lines is the maximum>
Expected behavior
The test should pass.
The text was updated successfully, but these errors were encountered: