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 class A<T> { | 7 class A<T> { |
8 A() : x = null; | 8 A() : x = null; |
9 | 9 |
10 const A.constant(this.x); | 10 const A.constant(this.x); |
11 | 11 |
12 factory A.factory() { | 12 factory A.factory() { |
13 return new B<Set>(); | 13 return new B<Set>(); |
14 } | 14 } |
15 | 15 |
16 factory A.test01() = T; /// 01: runtime error | 16 factory A.test01() = T; //# 01: runtime error |
17 | 17 |
18 factory A.test02() = dynamic; /// 02: runtime error | 18 factory A.test02() = dynamic; //# 02: runtime error |
19 | 19 |
20 factory A.test03() = Undefined; /// 03: runtime error | 20 factory A.test03() = Undefined; //# 03: runtime error |
21 | 21 |
22 factory A.test04() = C.test04; /// 04: compile-time error | 22 factory A.test04() = C.test04; //# 04: compile-time error |
23 | 23 |
24 final T x; | 24 final T x; |
25 } | 25 } |
26 | 26 |
27 class B<T> extends A<T> { | 27 class B<T> extends A<T> { |
28 B(); | 28 B(); |
29 | 29 |
30 factory B.A() = A<T>; | 30 factory B.A() = A<T>; |
31 | 31 |
32 const factory B.A_constant(T x) = A<T>.constant; | 32 const factory B.A_constant(T x) = A<T>.constant; |
33 | 33 |
34 factory B.A_factory() = A<T>.factory; | 34 factory B.A_factory() = A<T>.factory; |
35 | 35 |
36 factory B.test04() = A.test04; /// 04: continued | 36 factory B.test04() = A.test04; //# 04: continued |
37 | 37 |
38 factory B.test05(int incompatible) = A<T>.factory; /// 05: runtime error | 38 factory B.test05(int incompatible) = A<T>.factory; //# 05: runtime error |
39 | 39 |
40 factory B.test05(int incompatible) = A<T>.factory; /// 06: runtime error | 40 factory B.test05(int incompatible) = A<T>.factory; //# 06: runtime error |
41 } | 41 } |
42 | 42 |
43 class C<K, V> extends B<V> { | 43 class C<K, V> extends B<V> { |
44 C(); | 44 C(); |
45 | 45 |
46 factory C.A() = A<V>; | 46 factory C.A() = A<V>; |
47 | 47 |
48 factory C.A_factory() = A<V>.factory; | 48 factory C.A_factory() = A<V>.factory; |
49 | 49 |
50 const factory C.B_constant(V x) = B<V>.A_constant; | 50 const factory C.B_constant(V x) = B<V>.A_constant; |
51 | 51 |
52 factory C.test04() = B.test04; /// 04: continued | 52 factory C.test04() = B.test04; //# 04: continued |
53 | 53 |
54 factory C.test06(int incompatible) = B<K>.test05; /// 06: continued | 54 factory C.test06(int incompatible) = B<K>.test05; //# 06: continued |
55 | 55 |
56 const factory C.test07(V x) = B<V>.A; /// 07: compile-time error | 56 const factory C.test07(V x) = B<V>.A; //# 07: compile-time error |
57 } | 57 } |
58 | 58 |
59 main() { | 59 main() { |
60 new A<List>.test01(); /// 01: continued | 60 new A<List>.test01(); //# 01: continued |
61 new A<List>.test02(); /// 02: continued | 61 new A<List>.test02(); //# 02: continued |
62 new A<List>.test03(); /// 03: continued | 62 new A<List>.test03(); //# 03: continued |
63 new C.test04(); /// 04: continued | 63 new C.test04(); //# 04: continued |
64 new B.test05(0); /// 05: continued | 64 new B.test05(0); //# 05: continued |
65 new C<int, int>.test06(0); /// 06: continued | 65 new C<int, int>.test06(0); //# 06: continued |
66 new C<int, int>.test07(0); /// 07: continued | 66 new C<int, int>.test07(0); //# 07: continued |
67 Expect.isTrue(new A<List>() is A<List>); | 67 Expect.isTrue(new A<List>() is A<List>); |
68 Expect.isTrue(new A<bool>.constant(true).x); | 68 Expect.isTrue(new A<bool>.constant(true).x); |
69 Expect.isTrue(new A<Set>.factory() is B<Set>); | 69 Expect.isTrue(new A<Set>.factory() is B<Set>); |
70 Expect.isTrue(new B<List>.A() is A<List>); /// 08: dynamic type error | 70 Expect.isTrue(new B<List>.A() is A<List>); //# 08: dynamic type error |
71 Expect.isFalse(new B<List>.A() is A<Set>); /// 09: dynamic type error | 71 Expect.isFalse(new B<List>.A() is A<Set>); //# 09: dynamic type error |
72 Expect.isTrue(new B<bool>.A_constant(true).x); /// 10: dynamic type error | 72 Expect.isTrue(new B<bool>.A_constant(true).x); //# 10: dynamic type error |
73 Expect.isTrue(new B<List>.A_factory() is B<Set>); /// 11: dynamic type error | 73 Expect.isTrue(new B<List>.A_factory() is B<Set>); //# 11: dynamic type error |
74 Expect.isTrue(new C<String, num>.A() is A<num>); /// 12: dynamic type error | 74 Expect.isTrue(new C<String, num>.A() is A<num>); //# 12: dynamic type error |
75 Expect.isTrue(new C<String, num>.A_factory() is B<Set>); /// 13: dynamic type
error | 75 Expect.isTrue(new C<String, num>.A_factory() is B<Set>); //# 13: dynamic type
error |
76 Expect.isTrue(new C<String, bool>.B_constant(true).x); /// 14: dynamic type e
rror | 76 Expect.isTrue(new C<String, bool>.B_constant(true).x); //# 14: dynamic type e
rror |
77 } | 77 } |
OLD | NEW |