Closed
Description
The spec as I read is does not tell us whether or not the following program is legal. It depends on whether the implementation of Type overrides operator==()
. The VM and dart2js differ in this regard which is a problem for portability as programs developed on the VM don't work on dart2js (#17207)
It would be helpful to have a ruling on whether this specific combination of features is supposed to work and then have it implemented uniformly.
class A {}
const table = const {
A: 'Apple',
};
main() {
print(table[A]);
}
Wrapping the type to avoid operator== as follows leads to surprising behaviour.
class A {}
class B {}
class Key {
final Type type;
const Key(this.type);
}
const table = const {
const Key(A): 'Apple',
const Key(B): 'Banana',
};
main() {
print(table[const Key(A)]); // Apple
print(table[new Key(B)]); // null
}