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

Bug: different hashcodes for equal generic types, on Android #49672

Closed
Erhannis opened this issue Aug 16, 2022 · 2 comments
Closed

Bug: different hashcodes for equal generic types, on Android #49672

Erhannis opened this issue Aug 16, 2022 · 2 comments
Assignees
Labels
area-vm Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends.

Comments

@Erhannis
Copy link

Under some conditions, the hashcode of a generic type shows up as 0, and non-zero from an equal (but not identical) type. Occurred on Android (10 and 12 but not 6.0.1), but not on Linux native, nor on Chrome. May be related to #45060 - I even discovered the problem under similar circumstances.

Here's code to demonstrate it:

class Foo<T> {
}

class Bar {
}

void bar1<T>() {
  log("Foo<Bar>: ${Foo<Bar>} ${Foo<Bar> == Foo<Bar>} ${(Foo<Bar>).hashCode}");
  log("  Foo<T>: ${Foo<T>} ${Foo<T> == Foo<Bar>} ${(Foo<T>).hashCode}");
}
void bar2<T>() {
  log("Foo<Bar>: ${Foo<Bar>} ${Foo<Bar> == Foo<Bar>} ${(Foo<Bar>).hashCode}");
  log("       T: ${T} ${T == Foo<Bar>} ${(T).hashCode}");
}

void test() {
  bar1<Bar>();
  bar2<Foo<Bar>>();
}

This gives e.g.

[log] Foo<Bar>: Foo<Bar> true 393223570
[log]   Foo<T>: Foo<Bar> true 0
[log] Foo<Bar>: Foo<Bar> true 393223570
[log]        T: Foo<Bar> true 393223570

As you can see, all forms are equal to Foo<Bar>, but Foo<T> (where T is set to Bar) has a different hashcode, namely 0.

Tried this on two computers...actually, now I have one Android phone where it works right and two where it doesn't. Uh, here's a table of things:

Flutter 3.3.0-0.2.pre • channel beta • https://github.com/flutter/flutter.git
Framework • revision 7ac27ac8e6 (13 days ago) • 2022-08-02 14:35:08 -0700
Engine • revision d1e7dc18bf
Tools • Dart 2.18.0 (build 2.18.0-271.4.beta) • DevTools 2.15.0
:
Android 12 - bug
:
:
:
Flutter 3.0.5 • channel stable • https://github.com/flutter/flutter.git
Framework • revision f1875d570e (5 weeks ago) • 2022-07-13 11:24:16 -0700
Engine • revision e85ea0e79c
Tools • Dart 2.17.6 • DevTools 2.12.2
:
Android 10 - bug
Android 12 - bug
Android 6.0.1 - correct
Linux desktop (Ubuntu 20.04.4 64bit) - correct
Chrome 102.0.5005.115 64bit - correct

@srawlins srawlins added the area-vm Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends. label Aug 16, 2022
@Boucaa
Copy link

Boucaa commented May 23, 2023

Ran into this as well today. I created a simplified example below to show the issue

class Foo<T> {
  final brokenType = List<T>;
}

void main() {
  final a = Foo<Object>();
  print(a.brokenType.hashCode);
}

Output on Android (Dart 3, Flutter 3.10)

0

Output on web (dartpad)

680950264

@mraleph
Copy link
Member

mraleph commented May 23, 2023

@alexmarkov could you take a look?

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.
Projects
None yet
Development

No branches or pull requests

5 participants