Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(88)

Unified Diff: tests/language/type_variable_bounds4_test.dart

Issue 48383003: Support checking of malbounded types. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Updated cf. comments Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « tests/language/type_variable_bounds3_test.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/language/type_variable_bounds4_test.dart
diff --git a/tests/language/type_variable_bounds4_test.dart b/tests/language/type_variable_bounds4_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..3581d6f5780234c9143db6b3a646032cece7a3ad
--- /dev/null
+++ b/tests/language/type_variable_bounds4_test.dart
@@ -0,0 +1,69 @@
+// Copyright (c) 2013, 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.
+
+// Test instantiation of object with malbounded types.
+
+class A<T
+ extends num /// 01: static type warning
+ > {}
+class B<T> implements A<T> {}
+class C<T
+ extends num /// 01: continued
+ > implements B<T> {}
+
+class Class<T> {
+ newA() {
+ new A<T>(); /// 01: continued
+ }
+ newB() {
+ new B<T>(); /// 01: continued
+ }
+ newC() {
+ new C<T>(); /// 01: continued
+ }
+}
+
+bool inCheckedMode() {
+ try {
+ var i = 42;
+ String s = i;
+ } on TypeError catch (e) {
+ return true;
+ }
+ return false;
+}
+
+void test(bool expectTypeError, f()) {
+ try {
+ var v = f();
+ if (expectTypeError && inCheckedMode()) {
+ throw 'Missing type error instantiating ${v.runtimeType}';
+ }
+ } on TypeError catch (e) {
+ if (!expectTypeError || !inCheckedMode()) {
+ throw 'Unexpected type error: $e';
+ }
+ }
+}
+
+
+void main() {
+ test(false, () => new A<int>());
+ test(false, () => new B<int>());
+ test(false, () => new C<int>());
+
+ test(true, () => new A<String>()); /// 01: continued
+ test(true, () => new B<String>()); /// 01: continued
+ test(true, () => new C<String>()); /// 01: continued
+
+ var c = new Class<int>();
+ test(false, () => c.newA());
+ test(false, () => c.newB());
+ test(false, () => c.newC());
+
+ c = new Class<String>();
+ test(true, () => c.newA()); /// 01: continued
+ test(true, () => c.newB()); /// 01: continued
+ test(true, () => c.newC()); /// 01: continued
+}
« no previous file with comments | « tests/language/type_variable_bounds3_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698