OLD | NEW |
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 // VMOptions=--enable_type_checks | 4 // VMOptions=--enable_type_checks |
5 // | 5 // |
6 // Dart test program testing type checks in list literals. | 6 // Dart test program testing type checks in list literals. |
7 | 7 |
8 import "package:expect/expect.dart"; | 8 import "package:expect/expect.dart"; |
9 | 9 |
10 class ListLiteral4Test<T> { | 10 class ListLiteral4Test<T> { |
11 test() { | 11 test() { |
12 int result = 0; | 12 int result = 0; |
13 try { | 13 try { |
14 var m = <String>[0, 1]; // 0 is not a String. | 14 var m = <String>[0, 1]; // 0 is not a String. |
15 } on TypeError catch (error) { | 15 } on TypeError catch (error) { |
16 result += 1; | 16 result += 1; |
17 } | 17 } |
18 try { | 18 try { |
19 var m = <int>[0, 1]; | 19 var m = <int>[0, 1]; |
20 m["0"] = 1; // "0" is not an int. | 20 m["0"] = 1; // "0" is not an int. |
21 } on TypeError catch (error) { | 21 } on TypeError catch (error) { |
22 result += 10; | 22 result += 10; |
23 } | 23 } |
24 try { | 24 try { |
25 var m = <T>["a", "b"]; // "b" is not an int. | 25 var m = <T>["a", "b"]; // "b" is not an int. |
26 } on TypeError catch (error) { | 26 } on TypeError catch (error) { |
27 result += 100; | 27 result += 100; |
28 } | 28 } |
29 try { | 29 try { |
30 var m = <T>[0, 1]; // OK. | 30 var m = <T>[0, 1]; // OK. |
31 } on TypeError catch (error) { | 31 } on TypeError catch (error) { |
32 result += 1000; | 32 result += 1000; |
33 } | 33 } |
34 try { | 34 try { |
35 var m = <T>[0, 1]; | 35 var m = <T>[0, 1]; |
36 m["0"] = 1; // "0" is not an int. | 36 m["0"] = 1; // "0" is not an int. |
37 } on TypeError catch (error) { | 37 } on TypeError catch (error) { |
38 result += 10000; | 38 result += 10000; |
39 } | 39 } |
40 try { | 40 try { |
41 var m = const <int>[0, 1]; | 41 var m = const <int>[0, 1]; |
42 m["0"] = 1; // "0" is not an int. | 42 m["0"] = 1; // "0" is not an int. |
43 } on TypeError catch (error) { | 43 } on TypeError catch (error) { |
44 result += 100000; | 44 result += 100000; |
45 } | 45 } |
46 try { | 46 try { |
47 var m = <T>[0, 1]; // OK. Tested above. | 47 var m = <T>[0, 1]; // OK. Tested above. |
48 List<String> ls = m; // m is a List<int>, not a List<String>. | 48 List<String> ls = m; // m is a List<int>, not a List<String>. |
49 } on TypeError catch (error) { | 49 } on TypeError catch (error) { |
50 result += 1000000; | 50 result += 1000000; |
51 } | 51 } |
52 | 52 |
53 return result; | 53 return result; |
54 } | 54 } |
55 } | 55 } |
56 | 56 |
57 main() { | 57 main() { |
58 var t = new ListLiteral4Test<int>(); | 58 var t = new ListLiteral4Test<int>(); |
59 Expect.equals(1110111, t.test()); | 59 Expect.equals(1110111, t.test()); |
60 } | 60 } |
61 | |
62 | |
OLD | NEW |