OLD | NEW |
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 a function with a malformed result type. | 4 // Dart test for a function with a malformed result type. |
5 | 5 |
6 class C<T, U> {} | 6 class C<T, U> {} |
7 | 7 |
8 isCheckedMode() { | 8 isCheckedMode() { |
9 try { | 9 try { |
10 var i = 1; | 10 var i = 1; |
11 String s = i; | 11 String s = i; |
12 return false; | 12 return false; |
13 } catch(var e) { | 13 } catch (e) { |
14 return true; | 14 return true; |
15 } | 15 } |
16 } | 16 } |
17 | 17 |
18 main() { | 18 main() { |
19 { | 19 { |
20 C<int> f() => null; | 20 C<int> f() => null; |
21 bool got_type_error = false; | 21 bool got_type_error = false; |
22 try { | 22 try { |
23 f(); | 23 f(); |
24 } catch (TypeError error) { | 24 } on TypeError catch (error) { |
25 got_type_error = true; | 25 got_type_error = true; |
26 } | 26 } |
27 // No type error expected, since returned null is not type checked. | 27 // No type error expected, since returned null is not type checked. |
28 Expect.isFalse(got_type_error); | 28 Expect.isFalse(got_type_error); |
29 } | 29 } |
30 { | 30 { |
31 C<int> f() => new C<int, String>(); | 31 C<int> f() => new C<int, String>(); |
32 bool got_type_error = false; | 32 bool got_type_error = false; |
33 try { | 33 try { |
34 f(); | 34 f(); |
35 } catch (TypeError error) { | 35 } on TypeError catch (error) { |
36 got_type_error = true; | 36 got_type_error = true; |
37 } | 37 } |
38 // Type error expected in checked mode only. | 38 // Type error expected in checked mode only. |
39 Expect.isTrue(got_type_error == isCheckedMode()); | 39 Expect.isTrue(got_type_error == isCheckedMode()); |
40 } | 40 } |
41 } | 41 } |
OLD | NEW |