Skip to content
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

Different hashCodes produced for classes with List properties #8

Closed
georgepapas opened this issue Feb 26, 2019 · 5 comments
Closed

Different hashCodes produced for classes with List properties #8

georgepapas opened this issue Feb 26, 2019 · 5 comments
Assignees
Labels
bug
Projects

Comments

@georgepapas
Copy link

@georgepapas georgepapas commented Feb 26, 2019

Describe the bug
When a class extends Equatable and that class has a list property, two different instances, with the exact same properties, produce different hashCode values.

To Reproduce

class Foo extends Equatable {
  String foo;
  String bar;
  List<String> list;

  Foo(this.foo, this.bar, this.list) : super([foo, bar, list]);
}

void main() {
  group("hashCode test", () {
    test("foo", () {
      expect(Foo('aaa', 'bbb', []).hashCode, equals(Foo('aaa', 'bbb', []).hashCode));
    });
  });
}

Expected behavior
expected the same hashCode to be produced

Version
0.2.1

@felangel felangel self-assigned this Feb 26, 2019
@felangel felangel added the bug label Feb 26, 2019
@felangel felangel added this to To do in equatable Feb 26, 2019
@felangel felangel mentioned this issue Feb 26, 2019
3 of 3 tasks complete
@felangel felangel moved this from To do to In progress in equatable Feb 26, 2019
@felangel

This comment has been minimized.

Copy link
Owner

@felangel felangel commented Feb 26, 2019

@georgepapas thanks for reporting this! I'm pushing a fix for it now in #9 👍

@felangel

This comment has been minimized.

Copy link
Owner

@felangel felangel commented Feb 26, 2019

@georgepapas this should now be fixed in equatable v0.2.2. Thanks again for catching and reporting this! 💯

@felangel felangel closed this Feb 26, 2019
@felangel felangel moved this from In progress to Done in equatable Feb 26, 2019
@georgepapas

This comment has been minimized.

Copy link
Author

@georgepapas georgepapas commented Feb 26, 2019

Thanks for that, that was quick!, I'll take a look. Just one thing about the change, I ended up using something like this locally as a temporary workaround

DeepCollectionEquality.unordered().equals(my_list, other.my_list);

Does the fix in the commit introduce potential for stack overflow error if you have a list with items that reference the list?

Cheers

@felangel

This comment has been minimized.

Copy link
Owner

@felangel felangel commented Feb 26, 2019

@georgepapas thanks! Hmm can you provide an example? 🤔

@georgepapas

This comment has been minimized.

Copy link
Author

@georgepapas georgepapas commented Feb 28, 2019

Hey @felangel . Sorry for the late reply... Try this...

class Child extends Equatable {
  Parent parent;
  Child(this.parent) : super([parent]);
}

class Parent extends Equatable {
  List<Child> children;
  Parent(List<Child> children) : super([children]);

  void addChild(Child child) {
    children.add(child);
  }
}

void main() {
  Parent parent;

  setUp(() {
    List<Child> children = [];
    parent = Parent(children);

    children.add(Child(parent));
    children.add(Child(parent));

  });

  test("biderectional relationships cause stack overflow", () {
    parent.hashCode;
  });
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
equatable
  
Done
2 participants
You can’t perform that action at this time.