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

Unified Diff: tests/language/void_type_test.dart

Issue 10704216: Fix type checking of void type. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 5 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
« runtime/vm/flow_graph_compiler_ia32.cc ('K') | « tests/language/type_vm_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/void_type_test.dart
===================================================================
--- tests/language/void_type_test.dart (revision 0)
+++ tests/language/void_type_test.dart (revision 0)
@@ -0,0 +1,84 @@
+// 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 for type checks involving the void type.
+
+isCheckedMode() {
+ try {
+ var i = 1;
+ String s = i;
+ return false;
+ } catch(var e) {
+ return true;
+ }
+}
+
+void f() { return; }
+
+void f_null() { return null; }
+
+void f_1() { return 1; }
+
+void f_dyn_null() {
+ var x = null;
+ return x;
+}
+
+void f_dyn_1() {
+ var x = 1;
+ return x;
+}
+
+void f_f() { return f(); }
+
+void test(int n, void func(), bool must_get_error) {
+ // Test as closure call.
+ {
+ bool got_type_error = false;
+ try {
+ var x = func();
+ } catch (TypeError error) {
+ got_type_error = true;
+ }
+ // Never a type error in production mode.
+ if (isCheckedMode()) {
+ Expect.isTrue(got_type_error == must_get_error);
+ } else {
+ Expect.isFalse(got_type_error);
+ }
+ }
+ // Test as direct call.
+ {
+ bool got_type_error = false;
+ try {
+ var x;
+ switch (n) {
+ case 0: x = f(); break;
+ case 1: x = f_null(); break;
+ case 2: x = f_1(); break;
+ case 3: x = f_dyn_null(); break;
+ case 4: x = f_dyn_1(); break;
+ case 5: x = f_f(); break;
+ }
+ } catch (TypeError error) {
+ got_type_error = true;
+ }
+ // Never a type error in production mode.
+ if (isCheckedMode()) {
+ Expect.isTrue(got_type_error == must_get_error);
+ } else {
+ Expect.isFalse(got_type_error);
+ }
+ }
+}
+
+main() {
+ test(0, f, false);
+ test(1, f_null, false);
+ test(2, f_1, true);
+ test(3, f_dyn_null, false);
+ test(4, f_dyn_1, true);
+ test(5, f_f, false);
+}
+
+
« runtime/vm/flow_graph_compiler_ia32.cc ('K') | « tests/language/type_vm_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698