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:
Aske Simon Christensen 2022-05-11 11:48:26 +00:00 committed by Commit Bot
parent aa9b83eefc
commit de3cec3a47
2 changed files with 8 additions and 2 deletions

View file

@ -23,11 +23,14 @@ class Nasty {
const Nasty(this.n);
int get hashCode {
while (true) {}
throw "Evil hashCode";
}
}
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'};
Expect.equals(42, map[getValueNonOptimized(1.0)]);
Expect.equals(

View file

@ -25,11 +25,14 @@ class Nasty {
const Nasty(this.n);
int get hashCode {
while (true) {}
throw "Evil hashCode";
}
}
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'};
Expect.equals(42, map[getValueNonOptimized(1.0)]);
Expect.equals(