-
-
Notifications
You must be signed in to change notification settings - Fork 379
Update hash-map.dd #4246
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
base: master
Are you sure you want to change the base?
Update hash-map.dd #4246
Conversation
This update is in reference to <dlang#4245>. The spec currently says that for classes to be used as keys in associative arrays, they *must* override toHash and opEquals. This is untrue because the default implementations use the address of the class instance for computing the hash and for comparisons.
Thanks for your pull request and interest in making D better, @fieldvoid! We are looking forward to reviewing it, and you should be hearing from a maintainer soon.
Please see CONTRIBUTING.md for more information. If you have addressed all reviews or aren't sure how to proceed, don't hesitate to ping us with a simple comment. Bugzilla referencesYour PR doesn't reference any Bugzilla issue. If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog. |
spec/hash-map.dd
Outdated
@@ -109,6 +108,8 @@ $(H2 $(LNAME2 using_classes_as_key, Using Classes as the KeyType)) | |||
} | |||
} | |||
--- | |||
The default implementations of $(D toHash) and $(D opEquals) for classes use $(D is) | |||
semantics (the address of the class instance is used to compute the hash, and the address of the class instance is used for comparisons). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
opEquals
uses is
semantics, toHash
doesn't.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The more accurate thing to say is that the default opEquals
compares the addresses of the objects and that toHash
hashes the address of the object (so both ignore the value of the object itself). opEquals
does use is
to do that, but AFAIK, the spec doesn't use the term "is
semantics" anywhere, and is
doesn't need to be explicitly mentioned to make the behavior clear.
Edited based on jmdavis' (https://github.com/jmdavis) input to more accurately reflect what takes place.
I've edited it, thanks |
This update is in reference to #4245.
The spec currently says that for classes to be used as keys in associative arrays, they must override toHash and opEquals. This is untrue because the default implementations use the address of the class instance for computing the hash and for comparisons.