collection icon indicating copy to clipboard operation
collection copied to clipboard

DeepCollectionEquality is not symmetric most of the time

Open jakemac53 opened this issue 4 years ago • 3 comments

When comparing a List/Set to an Iterable, the order of the arguments will give a different result, making them non-symmetric.

This actually varies on the implementation though - in the case of DeepCollectionEquality.unordered then the results are symmetric, but only when comparing specifically a List and an Iterable 😱 .

Fixing this would be breaking at this point. Some options available to us are:

  • Change the behavior and do a breaking change.
  • Change the behavior but consider it as a bug fix and don't do a breaking change.
  • Deprecate existing constructors, add new ones that behave in a more sane (or at least consistent) manner.
  • Add new constructors that behave consistently, leave old ones in place and don't deprecate.
  • Do nothing.

cc @natebosch @lrhn

jakemac53 avatar Sep 03 '21 18:09 jakemac53

See the tests in the linked pr (https://github.com/dart-lang/collection/pull/209) which demonstrate the behavior.

jakemac53 avatar Sep 03 '21 19:09 jakemac53

I think I would be in favor of writing a symmetric CollectionEquality and deprecating DeepCollectionEquality.

natebosch avatar Sep 07 '21 22:09 natebosch

I am not sure that CollectionEquality implies deep equality though? Unless we wanted to make whether it uses deep equality a configurable thing?

jakemac53 avatar Sep 08 '21 14:09 jakemac53