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

Side by Side Diff: tests/language/void_type_test.dart

Issue 2718513002: Void is not required to be `null` anymore. (Closed)
Patch Set: Fix more places in the VM. Created 3 years, 9 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 // Dart test for type checks involving the void type. 4 // Dart test for type checks involving the void type.
5 5
6 import "package:expect/expect.dart"; 6 import "package:expect/expect.dart";
7 7
8 isCheckedMode() { 8 isCheckedMode() {
9 try { 9 try {
10 var i = 1; 10 var i = 1;
(...skipping 15 matching lines...) Expand all
26 return x; 26 return x;
27 } 27 }
28 28
29 void f_dyn_1() { 29 void f_dyn_1() {
30 var x = 1; 30 var x = 1;
31 return x; 31 return x;
32 } 32 }
33 33
34 void f_f() { return f(); } 34 void f_f() { return f(); }
35 35
36 void test(int n, void func(), bool must_get_error) { 36 void test(int n, void func()) {
37 // Test as closure call. 37 // Test as closure call.
38 { 38 {
39 bool got_type_error = false; 39 bool got_type_error = false;
40 try { 40 try {
41 var x = func(); 41 var x = func();
42 } on TypeError catch (error) { 42 } on TypeError catch (error) {
43 got_type_error = true; 43 got_type_error = true;
44 } 44 }
45 // Never a type error in production mode. 45 Expect.isFalse(got_type_error);
46 if (isCheckedMode()) {
47 Expect.isTrue(got_type_error == must_get_error);
48 } else {
49 Expect.isFalse(got_type_error);
50 }
51 } 46 }
52 // Test as direct call. 47 // Test as direct call.
53 { 48 {
54 bool got_type_error = false; 49 bool got_type_error = false;
55 try { 50 try {
56 var x; 51 var x;
57 switch (n) { 52 switch (n) {
58 case 0: x = f(); break; 53 case 0: x = f(); break;
59 case 1: x = f_null(); break; 54 case 1: x = f_null(); break;
60 case 2: x = f_1(); break; 55 case 2: x = f_1(); break;
61 case 3: x = f_dyn_null(); break; 56 case 3: x = f_dyn_null(); break;
62 case 4: x = f_dyn_1(); break; 57 case 4: x = f_dyn_1(); break;
63 case 5: x = f_f(); break; 58 case 5: x = f_f(); break;
64 } 59 }
65 } on TypeError catch (error) { 60 } on TypeError catch (error) {
66 got_type_error = true; 61 got_type_error = true;
67 } 62 }
68 // Never a type error in production mode. 63 Expect.isFalse(got_type_error);
69 if (isCheckedMode()) {
70 Expect.isTrue(got_type_error == must_get_error);
71 } else {
72 Expect.isFalse(got_type_error);
73 }
74 } 64 }
75 } 65 }
76 66
77 main() { 67 main() {
78 test(0, f, false); 68 test(0, f);
79 test(1, f_null, false); 69 test(1, f_null);
80 test(2, f_1, true); 70 test(2, f_1);
81 test(3, f_dyn_null, false); 71 test(3, f_dyn_null);
82 test(4, f_dyn_1, true); 72 test(4, f_dyn_1);
83 test(5, f_f, false); 73 test(5, f_f);
84 } 74 }
85 75
86 76
OLDNEW
« tests/language/void_check_test.dart ('K') | « tests/language/void_check_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698