| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 // Dart test for type checks involving the void type. | |
| 5 | |
| 6 isCheckedMode() { | |
| 7 try { | |
| 8 var i = 1; | |
| 9 String s = i; | |
| 10 return false; | |
| 11 } catch(var e) { | |
| 12 return true; | |
| 13 } | |
| 14 } | |
| 15 | |
| 16 void f() { return; } | |
| 17 | |
| 18 void f_null() { return null; } | |
| 19 | |
| 20 void f_1() { return 1; } | |
| 21 | |
| 22 void f_dyn_null() { | |
| 23 var x = null; | |
| 24 return x; | |
| 25 } | |
| 26 | |
| 27 void f_dyn_1() { | |
| 28 var x = 1; | |
| 29 return x; | |
| 30 } | |
| 31 | |
| 32 void f_f() { return f(); } | |
| 33 | |
| 34 void test(int n, void func(), bool must_get_error) { | |
| 35 // Test as closure call. | |
| 36 { | |
| 37 bool got_type_error = false; | |
| 38 try { | |
| 39 var x = func(); | |
| 40 } catch (TypeError error) { | |
| 41 got_type_error = true; | |
| 42 } | |
| 43 // Never a type error in production mode. | |
| 44 if (isCheckedMode()) { | |
| 45 Expect.isTrue(got_type_error == must_get_error); | |
| 46 } else { | |
| 47 Expect.isFalse(got_type_error); | |
| 48 } | |
| 49 } | |
| 50 // Test as direct call. | |
| 51 { | |
| 52 bool got_type_error = false; | |
| 53 try { | |
| 54 var x; | |
| 55 switch (n) { | |
| 56 case 0: x = f(); break; | |
| 57 case 1: x = f_null(); break; | |
| 58 case 2: x = f_1(); break; | |
| 59 case 3: x = f_dyn_null(); break; | |
| 60 case 4: x = f_dyn_1(); break; | |
| 61 case 5: x = f_f(); break; | |
| 62 } | |
| 63 } catch (TypeError error) { | |
| 64 got_type_error = true; | |
| 65 } | |
| 66 // Never a type error in production mode. | |
| 67 if (isCheckedMode()) { | |
| 68 Expect.isTrue(got_type_error == must_get_error); | |
| 69 } else { | |
| 70 Expect.isFalse(got_type_error); | |
| 71 } | |
| 72 } | |
| 73 } | |
| 74 | |
| 75 main() { | |
| 76 test(0, f, false); | |
| 77 test(1, f_null, false); | |
| 78 test(2, f_1, true); | |
| 79 test(3, f_dyn_null, false); | |
| 80 test(4, f_dyn_1, true); | |
| 81 test(5, f_f, false); | |
| 82 } | |
| 83 | |
| 84 | |
| OLD | NEW |