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

Unified Diff: tests/language/src/TypeChecksInFactoryMethodTest.dart

Issue 8956047: This adds a unit test to show the type checking functionality missing in dartc (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Updated test, $chk() can sneak in another way Created 9 years 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/language-leg.status ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/language/src/TypeChecksInFactoryMethodTest.dart
diff --git a/tests/language/src/TypeChecksInFactoryMethodTest.dart b/tests/language/src/TypeChecksInFactoryMethodTest.dart
new file mode 100644
index 0000000000000000000000000000000000000000..d865d6d886ab453c9d7e72cb2d2daa68da077a75
--- /dev/null
+++ b/tests/language/src/TypeChecksInFactoryMethodTest.dart
@@ -0,0 +1,34 @@
+// Copyright (c) 2011, 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.
+// VMOptions=--enable_type_checks --enable_asserts
+// Tests the type checking when passing code into closure from inside a factory method
+
+interface Foo<T> default Bar {
+ Foo.from();
+}
+
+class Bar<T> implements Foo<T> {
+ Bar() {}
+
+ factory Bar.from() {
+ var func = (T arg) { T foo = arg; print(arg); };
+ // If T is not a string, runtime type checks should fail
codefu 2011/12/22 16:13:50 And instance-of check should also fail.
+ func("Hello World!");
+ return new Bar<T>();
+ }
+}
+
+main() {
+ Foo value;
+ value = new Foo<String>.from();
+
+ bool gotError = false;
+
+ try {
+ value = new Foo<int>.from();
+ } catch (TypeError e) {
+ gotError = true;
+ }
+ Expect.equals(true, gotError);
+}
« no previous file with comments | « tests/language/language-leg.status ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698