-
Notifications
You must be signed in to change notification settings - Fork 1.7k
const maps with type entries doesn't work properly #17123
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
Comments
https://codereview.chromium.org/177053004 Set owner to @floitschG. |
Looks like we are going to disallow Types in const maps. https://codereview.chromium.org/179293005/ There might be a discussion if we have to special case Types. |
That's odd - aren't Types consider const symbols too? |
They are. But that doesn't mean that they cannot override their == operator (or hashCode). It's the same reason they cannot be used in case-clauses. |
When I said "disallow in const maps", I meant as keys. They are still fine as values. |
I see, thanks for the clarification, makes sense. I'm obviously not familiar with the implementation details, but I guess I am surprised that Type needs to override ==/hashcode. |
It became necessary to construct types for generic functions. Imagine: class A<T> { main() { new A<int>.foo().foo().foo()... } As you can see the set of runtime-types is not known at compile-time. This means that we have to construct them dynamically when needed. Instead of canonicalizing them at runtime, dart2js overrides the equality operator to ensure that they are equal. |
Regarding #7 - could we canonicalize the types? |
Note that we talk about instances of Do we have evidence that this is a performance bottleneck anywhere? |
It took me a while to figure out a bug related to this. Dart2js currently allows const maps with types as keys, but lookup functions fail.
Here is a simple example that reproduces the problem:
class A {}
var m1 = { A: 1};
const m2 = const {A: 2};
main() {
var t = new A().runtimeType;
print('${m1[A]} ${m2[A]} ${m1[t]} ${m2[t]}');
print(m2.keys.first == t)
}
This program works in the vm, there it prints:
1 2 1 2
true
in dart2js it prints:
1 2 1 null
true
The text was updated successfully, but these errors were encountered: