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

Enum hashCode is different when hot reloading #56248

Closed
naamapps opened this issue Jul 16, 2024 · 3 comments
Closed

Enum hashCode is different when hot reloading #56248

naamapps opened this issue Jul 16, 2024 · 3 comments
Assignees
Labels
area-vm Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends. P2 A bug or feature request we're likely to work on triaged Issue has been triaged by sub team type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) vm-hot-reload

Comments

@naamapps
Copy link

Hello,
I have encountered an issue when hot reloading in Flutter and using a simple equality check with an enum and a variable.
It seems that the hashCode of the enum value itself is different somehow.

I didn't have success replicating it outside of my project unfortunately.

This is the enum code:

enum PersistenceGraphFrequency { daily, weekly, monthly, yearly, decade }

When printing to console these lines:

print('frequency: $frequency');
print('frequency: ${frequency.hashCode}');
print('daily: ${PersistenceGraphFrequency.daily.hashCode}');
print('frequency == PersistenceGraphFrequency.daily: ${frequency == PersistenceGraphFrequency.daily}');

The output is:

I/flutter ( 1711): frequency: PersistenceGraphFrequency.daily
I/flutter ( 1711): frequency: 864014486
I/flutter ( 1711): daily: 927735851
I/flutter ( 1711): frequency == PersistenceGraphFrequency.daily: false

After hard reload, the output is:

I/flutter ( 1711): frequency: PersistenceGraphFrequency.daily
I/flutter ( 1711): frequency: 636379493
I/flutter ( 1711): daily: 636379493
I/flutter ( 1711): frequency == PersistenceGraphFrequency.daily: true

Dart version: 3.4.3
Env: MacOS 13.6
Device: Android 14

@dart-github-bot
Copy link
Collaborator

Summary: The hashCode of an enum value changes after hot reloading in Flutter, causing equality checks to fail. This inconsistency occurs only during hot reloading and not after a hard reload.

@dart-github-bot dart-github-bot added area-vm Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends. triage-automation See https://github.com/dart-lang/ecosystem/tree/main/pkgs/sdk_triage_bot. type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) labels Jul 16, 2024
@a-siva a-siva added P2 A bug or feature request we're likely to work on triaged Issue has been triaged by sub team labels Jul 17, 2024
@lrhn lrhn removed the triage-automation See https://github.com/dart-lang/ecosystem/tree/main/pkgs/sdk_triage_bot. label Jul 19, 2024
copybara-service bot pushed a commit that referenced this issue Jul 23, 2024
TEST=vm/cc/IsolateReload_EnumRetainedHash
Bug: #56248
Change-Id: Ie209b9954d6ea3f84e7e1511947ad47e056072de
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/377340
Reviewed-by: Siva Annamalai <asiva@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
@rmacnak-google
Copy link
Contributor

I was not able to reproduce a case where the hash changed.

@mraleph
Copy link
Member

mraleph commented Jul 30, 2024

Likely just a duplicate of #55350 which @rmacnak-google fixed in 3.5 and above

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-vm Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends. P2 A bug or feature request we're likely to work on triaged Issue has been triaged by sub team type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) vm-hot-reload
Projects
None yet
Development

No branches or pull requests

6 participants