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
Equality subclasses unnecessarily allow null arguments #214
Comments
We could also keep the nullable arguments but leave the implemented interface as non-nullable and exclusively fix the generics of This is the least likely to break anything and does make some potential usage a bit better I think. I'll check how much it breaks internally to get an idea of the feasibility. |
Closes #214 The nullable `T` in `Equality<T>` changes the assignability and introduces a difference between the other collection equality implementations and the unordered implementations. Prior to this change `SetEquality<T>` could not be statically assigned to a `Equality<Set<T>>`, instead it had to be assigned to `Equality<Set<T>?>`, while `ListEquality<T>` was assignable to `Equality<List<T>>`. Now both are assignable.
Towards #214 The nullable `T` in `Equality<T>` changes the assignability and introduces a difference between the other collection equality implementations and the unordered implementations. Prior to this change `SetEquality<T>` could not be statically assigned to a `Equality<Set<T>>`, instead it had to be assigned to `Equality<Set<T>?>`, while `ListEquality<T>` was assignable to `Equality<List<T>>`. Now both are assignable.
Keeping this open to consider whether we should remove the nullable argument types. |
When we migrated to null safety we introduced a discrepancy and unnecessarily expanded the argument types for
equals
andhash
.We declare most of the classes to
implements Equality<T>
, but allow aT?
forequals
andhash
, so when they are used directly they allownull
arguments, but when used as anEquality
the functionality is unnecessary.For
_UnorderedEquality
this came from makingT
unnecessarily nullable, and in other subclasses the class level generics are fine but the method arguments are still expanded to allownull
.This entire test should be static errors in my opinion:
collection/test/equality_test.dart
Lines 243 to 267 in cd46e19
Changing the arguments to non-nullable (with some extra handling of the nulls that flow from libraries that have not migrated to null safety) is a better design, but the impact of the breaking change is likely higher.
Changing the implements to
implements Equality<T?>
gives a more accurate interface and expands the places these classes can be used, but is still breaking.See #161 (comment)
The text was updated successfully, but these errors were encountered: