equatable icon indicating copy to clipboard operation
equatable copied to clipboard

Equality and Hashcode differ for Sets with different order

Open devmil opened this issue 1 year ago • 0 comments

Describe the bug For properties of type Set the result of hashCode is unexpected. Equality works like expected (order of Set elements doesn't have an impact) but hashCode produces different values depending on the order in the Set.

To Reproduce Steps to reproduce the behavior:

import 'package:equatable/equatable.dart';

class EquatableWithSet extends Equatable {
  final Set<int> intSet;

  EquatableWithSet(this.intSet);

  @override
  List<Object?> get props => [
        intSet,
      ];
}

void main(List<String> arguments) {
  final obj1 = EquatableWithSet({1,2,3});
  final obj2 = EquatableWithSet({3,1,2});

  assert(obj1 == obj2, 'Are not equal!');
  assert(obj1.hashCode == obj2.hashCode, 'Don\'t have the same hashcode!');
}

Expected behavior Two objects that are equal also have the same hashCode (independent of the order in the Set)

Screenshots If applicable, add screenshots to help explain your problem.

Version Dart SDK version: 2.17.5 (stable) (Tue Jun 21 11:05:10 2022 +0200) on "macos_x64"

Additional context Add any other context about the problem here.

devmil avatar Jul 28 '22 06:07 devmil