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 | 4 |
5 import "package:expect/expect.dart"; | 5 import "package:expect/expect.dart"; |
6 | 6 |
7 // Tests classes with getters and setters that do not have the same type. | 7 // Tests classes with getters and setters that do not have the same type. |
8 | 8 |
9 class A { | 9 class A { |
10 int a() { | 10 int a() { |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 } | 55 } |
56 } | 56 } |
57 | 57 |
58 main() { | 58 main() { |
59 T1 instance1 = new T1(); | 59 T1 instance1 = new T1(); |
60 T2 instance2 = new T2(); //# 01: continued | 60 T2 instance2 = new T2(); //# 01: continued |
61 T3 instance3 = new T3(); | 61 T3 instance3 = new T3(); |
62 | 62 |
63 instance1.field = new B(); | 63 instance1.field = new B(); |
64 A resultA = instance1.field; | 64 A resultA = instance1.field; |
65 instance1.field = new A(); //# 03: dynamic type error | 65 Expect.throwsTypeError(() => instance1.field = new A() as dynamic); |
66 B resultB = instance1.field; | 66 B resultB = instance1.field; |
67 | 67 |
68 int result; | 68 int result; |
69 result = instance1.field.a(); | 69 result = instance1.field.a(); |
70 Expect.equals(37, result); | 70 Expect.equals(37, result); |
71 | 71 |
72 // Type 'A' has no method named 'b' | 72 // Type 'A' has no method named 'b' |
73 instance1.field.b(); //# 02: static type warning | 73 instance1.field.b(); //# 02: compile-time error |
74 | 74 |
75 instance3.field = new B(); | 75 instance3.field = new B(); |
76 result = instance3.field.a(); | 76 result = instance3.field.a(); |
77 Expect.equals(37, result); | 77 Expect.equals(37, result); |
78 result = instance3.field.b(); | 78 result = instance3.field.b(); |
79 Expect.equals(38, result); | 79 Expect.equals(38, result); |
80 } | 80 } |
OLD | NEW |