Files
sdk/tests/language/instanceof4_test.dart
T
regis@google.com 87c144334f Fix bad optimization of instance-of with uninstantiated types (issue 5216).
Fix bad assert when type check elimination is disabled (issue 5217).
Cleanup of type elimination code in optimizing compiler.
Add test.
Review URL: https://codereview.chromium.org//10942006

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@12502 260f80e4-7a28-3924-810f-c04153c831b5
2012-09-18 15:12:43 +00:00

70 lines
1.8 KiB
Dart

// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// Dart test program for testing the instanceof operation.
// Regression test for issue 5216.
class Foo<T> {
bool isT() => "a string" is T;
bool isNotT() => "a string" is! T;
bool isListT() => [0, 1, 2] is List<T>;
bool isNotListT() => [0, 1, 2] is! List<T>;
bool isAlsoListT() => <int>[0, 1, 2] is List<T>;
bool isNeitherListT() => <int>[0, 1, 2] is! List<T>;
}
testFooString() {
var o = new Foo<String>();
Expect.isTrue(o.isT());
Expect.isTrue(!o.isNotT());
Expect.isTrue(o.isListT());
Expect.isTrue(!o.isNotListT());
Expect.isTrue(!o.isAlsoListT());
Expect.isTrue(o.isNeitherListT());
for (var i = 0; i < 4000; i++) {
// Make sure methods are optimized.
o.isT();
o.isNotT();
o.isListT();
o.isNotListT();
o.isAlsoListT();
o.isNeitherListT();
}
Expect.isTrue(o.isT());
Expect.isTrue(!o.isNotT());
Expect.isTrue(o.isListT());
Expect.isTrue(!o.isNotListT());
Expect.isTrue(!o.isAlsoListT());
Expect.isTrue(o.isNeitherListT());
}
testFooInt() {
var o = new Foo<int>();
Expect.isTrue(!o.isT());
Expect.isTrue(o.isNotT());
Expect.isTrue(o.isListT());
Expect.isTrue(!o.isNotListT());
Expect.isTrue(o.isAlsoListT());
Expect.isTrue(!o.isNeitherListT());
for (var i = 0; i < 4000; i++) {
// Make sure methods are optimized.
o.isT();
o.isNotT();
o.isListT();
o.isNotListT();
o.isAlsoListT();
o.isNeitherListT();
}
Expect.isTrue(!o.isT());
Expect.isTrue(o.isNotT());
Expect.isTrue(o.isListT());
Expect.isTrue(!o.isNotListT());
Expect.isTrue(o.isAlsoListT());
Expect.isTrue(!o.isNeitherListT());
}
main() {
testFooString();
testFooInt();
}