-
Notifications
You must be signed in to change notification settings - Fork 27.2k
-
Notifications
You must be signed in to change notification settings - Fork 27.2k
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
String.hashCode returns different values with same sequence #20122
Comments
Is the output you provided hypothetical or it is from the real application - meaning that in your application string |
Thank you very much for replying. The actual output is this:
I found that when |
@najeira just to clarify: does you function actually say |
@mraleph No, it's more complicated. My code like this:
|
If debugPrint is inserted after someFunc, there is no problem.
|
I think we might need a reproduction of this to actually figure it out - I reviewed logic for hash computation and it does not seem like there are any bugs there. I have tried to trigger various misoptimizations - but so far I was not successful. |
@mraleph I found the reproduction code, I updated the first comment. The followings are important for this:
|
Thanks for the additional information! Reduction: make(v) => 'x${v}';
void main() {
final x = make('test');
final y = make('test');
identityHashCode(y); // initialize hidden hash field with identity hash.
print(x.hashCode == y.hashCode); // will print false on x64 and ARM64.
} The issue is that I will submit a fix upstream. |
The fix is uploaded upstream: https://dart-review.googlesource.com/c/sdk/+/68042 |
I will update my app so that I do not use identityHashCode: @override
int get hashCode {
return name.hashCode ^ value.hashCode;
} Thank you! |
…shCode On 64-bit platforms we use a field in the header to cache results of Object.get:_identityHashCode. The very same field is also used to cache String.get:hashCode result. Which means that their implementations must be the same. Fixes flutter/flutter#20122 Change-Id: I98eef9eddf833c0d7c4c6f452728fe48e232efdc Reviewed-on: https://dart-review.googlesource.com/68042 Commit-Queue: Vyacheslav Egorov <vegorov@google.com> Reviewed-by: Martin Kustermann <kustermann@google.com>
The fix has landed upstream. Waiting for the roll into Flutter to pick it up. |
Dart with a fix has reached Flutter. Closing. |
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of |
Steps to Reproduce
String.hashCode returns different values with same sequence.
This only happens when the app is running on iOS simulator/device.
Therefore, String can not be used as the key of Map.
Logs
I tested it on v0.4.4, v0.5.1, v0.5.7.
The text was updated successfully, but these errors were encountered: