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

Duplicated object in Set #14638

Closed
DartBot opened this issue Oct 31, 2013 · 2 comments
Closed

Duplicated object in Set #14638

DartBot opened this issue Oct 31, 2013 · 2 comments
Labels
area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. closed-duplicate Closed in favor of an existing report

Comments

@DartBot
Copy link

DartBot commented Oct 31, 2013

This issue was originally filed by [email protected]


What steps will reproduce the problem?

Set mapSet = new Set();
mapSet.add({'map item': 'First Item'});
mapSet.add({'map item': 'Second Item'});
mapSet.add({'map item': 'Third Item'});
mapSet.add({'map item': 'Third Item'});

What is the expected output? What do you see instead?

Expected mapSet to be {{map item: First Item}, {map item: Second Item}, {map item: Third Item}}
mapSet is instead {{map item: First Item}, {map item: Second Item}, {map item: Third Item}, {map item: Third Item}}

What version of the product are you using? On what operating system?
Dart VM version: 0.8.5.1_r28990 (Tue Oct 22 05:03:51 2013) on "macos_x64"

Additional:
Summary line from http://api.dartlang.org/docs/releases/latest/dart_core/Set.html
"A collection of objects in which each object can occur only once."

@dgrove
Copy link
Contributor

dgrove commented Oct 31, 2013

Added Area-Library, Triaged labels.

@floitschG
Copy link
Contributor

Two different map literals are not the same object. That is:
identical({'map item': 'foo'}, {'map item': 'foo'}); // returns false.
Furthermore sets use identical for their "==operator". This means that:
({'map item': 'foo'}) == ({'map item': 'foo'}); // returns false.

The default implementation of Set uses ==operator for determining if two elements are equal.

If you prefer a different equality you have to provide the equality and hashcode methods:
http://api.dartlang.org/docs/releases/latest/dart_collection/LinkedHashSet.html#

You can also use the collection_helpers package which provides some helpers for deep equality. I'm not sure it is already publicly available, but here is the review: https://codereview.chromium.org/23567044/


Added Duplicate label.
Marked as being merged into #10391.

@DartBot DartBot added Type-Defect area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. closed-duplicate Closed in favor of an existing report labels Oct 31, 2013
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. closed-duplicate Closed in favor of an existing report
Projects
None yet
Development

No branches or pull requests

4 participants