-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
All objects should be Hashable #3369
Comments
Added Area-Language, Triaged labels. |
Recategorizing as a request for a universal hash function. Set owner to @gbracha. |
We expect to add a hashCode method to Object. Added this to the M1 milestone. |
When we do this, can we also add |
Your in charge of libraries :-) I don't see why not. But other's mileage may vary. |
This comment was originally written by @seaneagan Regarding the identical and identityHash top-level methods, these already exist as instance methods on Object (== and hashCode respectively), there is just no way to get at them. It might be nice to have a syntax to extract such instance methods from classes, whose "this" parameter would be passed as the first parameter. A syntax for this might be: ClassName#methodName Also, it may already possible to extract instance methods from classes via mirrors ? (but you do lose type information doing it that way). |
Issue #3218 has been merged into this issue. cc @dgrove. |
Issue #167 has been merged into this issue. |
Added Done label. |
Changes: ``` > git log --format="%C(auto) %h %s" a3a102a..a949b32 https://dart.googlesource.com/pub.git/+/a949b329 Fix handling of 'git@github.com:dart-lang/pub.git' style urls in git source (#3381) https://dart.googlesource.com/pub.git/+/c6cd3758 Always use forward slash for relative paths in lockfile (#3379) https://dart.googlesource.com/pub.git/+/7d48f902 Remove unused function (#3370) https://dart.googlesource.com/pub.git/+/b1373d4c Fix import prefix (#3369) ``` Diff: https://dart.googlesource.com/pub.git/+/a3a102a549388a6dbfecc9252fabb618f9a2f5f7~..a949b329b1b51f5f3973a790e0a0a45897d837de/ A bunch of bugfixes. Change-Id: I1f791cad27194359091f489f36dcc3ad2b78bb31 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/240052 Reviewed-by: Jonas Jensen <jonasfj@google.com> Commit-Queue: Sigurd Meldgaard <sigurdm@google.com>
Changes: ``` > git log --format="%C(auto) %h %s" a3a102a..a949b32 https://dart.googlesource.com/pub.git/+/a949b329 Fix handling of 'git@github.com:dart-lang/pub.git' style urls in git source (#3381) https://dart.googlesource.com/pub.git/+/c6cd3758 Always use forward slash for relative paths in lockfile (#3379) https://dart.googlesource.com/pub.git/+/7d48f902 Remove unused function (#3370) https://dart.googlesource.com/pub.git/+/b1373d4c Fix import prefix (#3369) ``` Diff: https://dart.googlesource.com/pub.git/+/a3a102a549388a6dbfecc9252fabb618f9a2f5f7~..a949b329b1b51f5f3973a790e0a0a45897d837de/ A bunch of bugfixes. Change-Id: I1f791cad27194359091f489f36dcc3ad2b78bb31 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/240052 Reviewed-by: Jonas Jensen <jonasfj@google.com> Commit-Queue: Sigurd Meldgaard <sigurdm@google.com>
This issue was originally filed by renggl...@gmail.com
What steps will reproduce the problem?
Commonly the following rule is known regarding the implementation of == and hashChode:
This is kind of tricky to achieve in Dart (please correct me if I am wrong), because Object implements only ==. To make it possible to put an object into a Set/Map based on its identity it needs to implement Hashable. I figured out the following code:
class A implements Hashable {
// kind of complicated code to make an object hashable by its identity
static int _nextHashCode = 0;
final int _hashCode;
A() : _hashCode = _nextHashCode++;
int hashCode() => _hashCode;
// already implemented in superclass, duplicated for consistency
operator == (other) => this === other;
}
What is the expected output? What do you see instead?
What version of the product are you using? On what operating system?
Dart SDK version 7904
The text was updated successfully, but these errors were encountered: