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

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

Issue 2718513002: Void is not required to be `null` anymore. (Closed)
Patch Set: Update Kernel code. 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(), bool must_get_error) { 44 void test(int n, void func()) {
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 // Never a type error in production mode. 53 Expect.isFalse(got_type_error);
54 if (isCheckedMode()) {
55 Expect.isTrue(got_type_error == must_get_error);
56 } else {
57 Expect.isFalse(got_type_error);
58 }
59 } 54 }
60 // Test as direct call. 55 // Test as direct call.
61 { 56 {
62 bool got_type_error = false; 57 bool got_type_error = false;
63 try { 58 try {
64 var x; 59 var x;
65 switch (n) { 60 switch (n) {
66 case 0: 61 case 0:
67 x = f(); 62 x = f();
68 break; 63 break;
69 case 1: 64 case 1:
70 x = f_null(); 65 x = f_null();
71 break; 66 break;
72 case 2: 67 case 2:
73 x = f_1(); 68 x = f_1();
74 break; 69 break;
75 case 3: 70 case 3:
76 x = f_dyn_null(); 71 x = f_dyn_null();
77 break; 72 break;
78 case 4: 73 case 4:
79 x = f_dyn_1(); 74 x = f_dyn_1();
80 break; 75 break;
81 case 5: 76 case 5:
82 x = f_f(); 77 x = f_f();
83 break; 78 break;
84 } 79 }
85 } on TypeError catch (error) { 80 } on TypeError catch (error) {
86 got_type_error = true; 81 got_type_error = true;
87 } 82 }
88 // Never a type error in production mode. 83 Expect.isFalse(got_type_error);
89 if (isCheckedMode()) {
90 Expect.isTrue(got_type_error == must_get_error);
91 } else {
92 Expect.isFalse(got_type_error);
93 }
94 } 84 }
95 } 85 }
96 86
97 main() { 87 main() {
98 test(0, f, false); 88 test(0, f);
99 test(1, f_null, false); 89 test(1, f_null);
100 test(2, f_1, true); 90 test(2, f_1);
101 test(3, f_dyn_null, false); 91 test(3, f_dyn_null);
102 test(4, f_dyn_1, true); 92 test(4, f_dyn_1);
103 test(5, f_f, false); 93 test(5, f_f);
104 } 94 }
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