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