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 program for constructors and initializers. | 4 // Dart test program for constructors and initializers. |
5 | 5 |
6 import "package:expect/expect.dart"; | 6 import "package:expect/expect.dart"; |
7 | 7 |
8 // Test 'expression as Type' casts. | 8 // Test 'expression as Type' casts. |
9 | 9 |
10 class C { | 10 class C { |
(...skipping 17 matching lines...) Expand all Loading... |
28 Object on = getNull(); | 28 Object on = getNull(); |
29 Object ol = createList(); | 29 Object ol = createList(); |
30 Object oi = createInt(); | 30 Object oi = createInt(); |
31 Object os = createString(); | 31 Object os = createString(); |
32 | 32 |
33 Expect.equals(42, (oc as C).foo); | 33 Expect.equals(42, (oc as C).foo); |
34 Expect.equals(42, (od as C).foo); | 34 Expect.equals(42, (od as C).foo); |
35 Expect.equals(42, (od as D).foo); | 35 Expect.equals(42, (od as D).foo); |
36 Expect.equals(37, (od as D).bar); | 36 Expect.equals(37, (od as D).bar); |
37 Expect.equals(37, ((od as C) as D).bar); | 37 Expect.equals(37, ((od as C) as D).bar); |
38 (oc as D).foo; /// 01: runtime error | 38 (oc as D).foo; // /// 01: runtime error |
39 (on as D).toString(); | 39 (on as D).toString(); |
40 (on as D).foo; /// 02: runtime error | 40 (on as D).foo; // /// 02: runtime error |
41 (on as C).foo; /// 03: runtime error | 41 (on as C).foo; // /// 03: runtime error |
42 oc.foo; /// 04: static type warning | 42 oc.foo; // /// 04: static type warning |
43 od.foo; /// 05: static type warning | 43 od.foo; // /// 05: static type warning |
44 (on as Object).toString(); | 44 (on as Object).toString(); |
45 (oc as Object).toString(); | 45 (oc as Object).toString(); |
46 (od as Object).toString(); | 46 (od as Object).toString(); |
47 (on as dynamic).toString(); | 47 (on as dynamic).toString(); |
48 (on as dynamic).foo; /// 07: runtime error | 48 (on as dynamic).foo; // /// 07: runtime error |
49 (oc as dynamic).foo; | 49 (oc as dynamic).foo; |
50 (od as dynamic).foo; | 50 (od as dynamic).foo; |
51 (oc as dynamic).bar; /// 08: runtime error | 51 (oc as dynamic).bar; // /// 08: runtime error |
52 (od as dynamic).bar; | 52 (od as dynamic).bar; |
53 C c = oc as C; | 53 C c = oc as C; |
54 c = od as C; | 54 c = od as C; |
55 c = oc; | 55 c = oc; |
56 D d = od as D; | 56 D d = od as D; |
57 d = oc as D; /// 10: runtime error | 57 d = oc as D; // /// 10: runtime error |
58 d = od; | 58 d = od; |
59 | 59 |
60 (ol as List)[0]; | 60 (ol as List)[0]; |
61 (ol as List<int>)[0]; | 61 (ol as List<int>)[0]; |
62 (ol as dynamic)[0]; | 62 (ol as dynamic)[0]; |
63 (ol as String).length; /// 12: runtime error | 63 (ol as String).length; // /// 12: runtime error |
64 int x = (ol as List<int>)[0]; | 64 int x = (ol as List<int>)[0]; |
65 (ol as List<int>)[0] = (oi as int); | 65 (ol as List<int>)[0] = (oi as int); |
66 | 66 |
67 (os as String).length; | 67 (os as String).length; |
68 (os as dynamic).length; | 68 (os as dynamic).length; |
69 (oi as String).length; /// 13: runtime error | 69 (oi as String).length; // /// 13: runtime error |
70 (os as List).length; /// 14: runtime error | 70 (os as List).length; // /// 14: runtime error |
71 | 71 |
72 (oi as int) + 2; | 72 (oi as int) + 2; |
73 (oi as List).length; /// 15: runtime error | 73 (oi as List).length; // /// 15: runtime error |
74 } | 74 } |
75 | 75 |
76 | 76 |
OLD | NEW |