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 // Test overriding of fields. | 4 // Test overriding of fields. |
5 | 5 |
6 import "package:expect/expect.dart"; | 6 import "package:expect/expect.dart"; |
7 | 7 |
8 | 8 |
9 class A {} | 9 class A {} |
10 class B1 extends A {} | 10 class B1 extends A {} |
11 class B2 extends A {} | 11 class B2 extends A {} |
12 | 12 |
13 class Super { | 13 class Super { |
14 Super() : super(); | 14 Super() : super(); |
15 | 15 |
16 B1 field; | 16 B1 field; |
17 } | 17 } |
18 | 18 |
19 class Sub extends Super { | 19 class Sub extends Super { |
20 Sub() : super(); | 20 Sub() : super(); |
21 | 21 |
22 A field; | 22 A field; |
23 } | 23 } |
24 | 24 |
25 class SubSub extends Super { | 25 class SubSub extends Super { |
26 SubSub() : super(); | 26 SubSub() : super(); |
27 | 27 |
28 // B2 not assignable to B1 | 28 // B2 not assignable to B1 |
29 B2 field; /// 01: static type warning | 29 B2 field; //# 01: static type warning |
30 } | 30 } |
31 | 31 |
32 main() { | 32 main() { |
33 SubSub val1 = new SubSub(); | 33 SubSub val1 = new SubSub(); |
34 val1.field = new B2(); /// 02: static type warning, dynamic type error | 34 val1.field = new B2(); //# 02: static type warning, dynamic type error |
35 Expect.equals(true, val1.field is B2); /// 02: continued | 35 Expect.equals(true, val1.field is B2); //# 02: continued |
36 | 36 |
37 Sub val2 = new Sub(); | 37 Sub val2 = new Sub(); |
38 val2.field = new A(); | 38 val2.field = new A(); |
39 Expect.equals(true, val2.field is A); | 39 Expect.equals(true, val2.field is A); |
40 Expect.equals(false, val2.field is B1); | 40 Expect.equals(false, val2.field is B1); |
41 Expect.equals(false, val2.field is B2); | 41 Expect.equals(false, val2.field is B2); |
42 | 42 |
43 Super val3 = new Super(); | 43 Super val3 = new Super(); |
44 val3.field = new B1(); | 44 val3.field = new B1(); |
45 Expect.equals(true, val3.field is B1); | 45 Expect.equals(true, val3.field is B1); |
46 Expect.equals(false, val3.field is B2); | 46 Expect.equals(false, val3.field is B2); |
47 } | 47 } |
OLD | NEW |