mirror of
https://github.com/dart-lang/sdk
synced 2024-09-15 22:51:29 +00:00
Make hashcode override test throw instead of looping indefinitely.
This achieves the same thing (test that `hashCode` is not called), but avoids a costly timeout on failure. This drastically cuts down the total testing time for the language and corelib suites for dart2wasm (which intends not to implement a special case here, since it is going to be illegal in the future anyway). Change-Id: I040925ebd8271a5816c81bc16484c0a96626857d Cq-Include-Trybots: luci.dart.try:vm-kernel-precomp-linux-debug-x64-try Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/244061 Commit-Queue: Aske Simon Christensen <askesc@google.com> Reviewed-by: Daco Harkes <dacoharkes@google.com> Reviewed-by: Lasse Nielsen <lrn@google.com>
This commit is contained in:
parent
aa9b83eefc
commit
de3cec3a47
|
@ -23,11 +23,14 @@ class Nasty {
|
||||||
const Nasty(this.n);
|
const Nasty(this.n);
|
||||||
|
|
||||||
int get hashCode {
|
int get hashCode {
|
||||||
while (true) {}
|
throw "Evil hashCode";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
main() {
|
main() {
|
||||||
|
// Test that when using an instance of a custom class as a key in a const Map,
|
||||||
|
// its hash code is computed as its identity hash, and even if the class
|
||||||
|
// overrides `hashCode`, that `hashCode` implementation is not called.
|
||||||
final map = const {1: 42, 'foo': 499, 2: 'bar', Nasty(1): 'baz'};
|
final map = const {1: 42, 'foo': 499, 2: 'bar', Nasty(1): 'baz'};
|
||||||
Expect.equals(42, map[getValueNonOptimized(1.0)]);
|
Expect.equals(42, map[getValueNonOptimized(1.0)]);
|
||||||
Expect.equals(
|
Expect.equals(
|
||||||
|
|
|
@ -25,11 +25,14 @@ class Nasty {
|
||||||
const Nasty(this.n);
|
const Nasty(this.n);
|
||||||
|
|
||||||
int get hashCode {
|
int get hashCode {
|
||||||
while (true) {}
|
throw "Evil hashCode";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
main() {
|
main() {
|
||||||
|
// Test that when using an instance of a custom class as a key in a const Map,
|
||||||
|
// its hash code is computed as its identity hash, and even if the class
|
||||||
|
// overrides `hashCode`, that `hashCode` implementation is not called.
|
||||||
final map = const {1: 42, 'foo': 499, 2: 'bar', Nasty(1): 'baz'};
|
final map = const {1: 42, 'foo': 499, 2: 'bar', Nasty(1): 'baz'};
|
||||||
Expect.equals(42, map[getValueNonOptimized(1.0)]);
|
Expect.equals(42, map[getValueNonOptimized(1.0)]);
|
||||||
Expect.equals(
|
Expect.equals(
|
||||||
|
|
Loading…
Reference in a new issue