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

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

Issue 2865603003: Revert "Void is not required to be `null` anymore." (Closed)
Patch Set: Created 3 years, 7 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
« no previous file with comments | « tests/language/void_check_test.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 23 matching lines...) Expand all
34 34
35 void f_dyn_1() { 35 void f_dyn_1() {
36 var x = 1; 36 var x = 1;
37 return x; 37 return x;
38 } 38 }
39 39
40 void f_f() { 40 void f_f() {
41 return f(); 41 return f();
42 } 42 }
43 43
44 void test(int n, void func()) { 44 void test(int n, void func(), bool must_get_error) {
45 // Test as closure call. 45 // Test as closure call.
46 { 46 {
47 bool got_type_error = false; 47 bool got_type_error = false;
48 try { 48 try {
49 var x = func(); 49 var x = func();
50 } on TypeError catch (error) { 50 } on TypeError catch (error) {
51 got_type_error = true; 51 got_type_error = true;
52 } 52 }
53 Expect.isFalse(got_type_error); 53 // Never a type error in production mode.
54 if (isCheckedMode()) {
55 Expect.isTrue(got_type_error == must_get_error);
56 } else {
57 Expect.isFalse(got_type_error);
58 }
54 } 59 }
55 // Test as direct call. 60 // Test as direct call.
56 { 61 {
57 bool got_type_error = false; 62 bool got_type_error = false;
58 try { 63 try {
59 var x; 64 var x;
60 switch (n) { 65 switch (n) {
61 case 0: 66 case 0:
62 x = f(); 67 x = f();
63 break; 68 break;
64 case 1: 69 case 1:
65 x = f_null(); 70 x = f_null();
66 break; 71 break;
67 case 2: 72 case 2:
68 x = f_1(); 73 x = f_1();
69 break; 74 break;
70 case 3: 75 case 3:
71 x = f_dyn_null(); 76 x = f_dyn_null();
72 break; 77 break;
73 case 4: 78 case 4:
74 x = f_dyn_1(); 79 x = f_dyn_1();
75 break; 80 break;
76 case 5: 81 case 5:
77 x = f_f(); 82 x = f_f();
78 break; 83 break;
79 } 84 }
80 } on TypeError catch (error) { 85 } on TypeError catch (error) {
81 got_type_error = true; 86 got_type_error = true;
82 } 87 }
83 Expect.isFalse(got_type_error); 88 // Never a type error in production mode.
89 if (isCheckedMode()) {
90 Expect.isTrue(got_type_error == must_get_error);
91 } else {
92 Expect.isFalse(got_type_error);
93 }
84 } 94 }
85 } 95 }
86 96
87 main() { 97 main() {
88 test(0, f); 98 test(0, f, false);
89 test(1, f_null); 99 test(1, f_null, false);
90 test(2, f_1); 100 test(2, f_1, true);
91 test(3, f_dyn_null); 101 test(3, f_dyn_null, false);
92 test(4, f_dyn_1); 102 test(4, f_dyn_1, true);
93 test(5, f_f); 103 test(5, f_f, false);
94 } 104 }
OLDNEW
« no previous file with comments | « tests/language/void_check_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698