OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 // Test least upper bound through type checking of conditionals. | 5 // Test least upper bound through type checking of conditionals. |
6 | 6 |
7 class N<T> { | 7 class N<T> { |
8 T get n => null; | 8 T get n => null; |
9 } | 9 } |
10 | 10 |
(...skipping 22 matching lines...) Expand all Loading... |
33 */ | 33 */ |
34 void testC1(bool z, C1<int> a, N<C1<String>> b) { | 34 void testC1(bool z, C1<int> a, N<C1<String>> b) { |
35 if (z) { | 35 if (z) { |
36 // The least upper bound of C1<int> and N<C1<String>> is Object since the | 36 // The least upper bound of C1<int> and N<C1<String>> is Object since the |
37 // supertypes are | 37 // supertypes are |
38 // {C1<int>, N<N<C1<int>>>, Object} for C1<int> and | 38 // {C1<int>, N<N<C1<int>>>, Object} for C1<int> and |
39 // {N<C1<String>>, Object} for N<C1<String>> and | 39 // {N<C1<String>>, Object} for N<C1<String>> and |
40 // Object is the most specific type in the intersection of the supertypes. | 40 // Object is the most specific type in the intersection of the supertypes. |
41 | 41 |
42 // Is least upper bound dynamic? | 42 // Is least upper bound dynamic? |
43 (z ? a : b).z; /// 01: static type warning | 43 (z ? a : b).z; //# 01: static type warning |
44 // Is least upper bound N<...> ? | 44 // Is least upper bound N<...> ? |
45 (z ? a : b).n; /// 02: static type warning | 45 (z ? a : b).n; //# 02: static type warning |
46 // Is least upper bound C1<...> ? | 46 // Is least upper bound C1<...> ? |
47 (z ? a : b).c1; /// 03: static type warning | 47 (z ? a : b).c1; //# 03: static type warning |
48 // Is least upper bound N<dynamic> ? | 48 // Is least upper bound N<dynamic> ? |
49 (z ? a : b).n.z; /// 04: static type warning | 49 (z ? a : b).n.z; //# 04: static type warning |
50 // Is least upper bound N<N<...>> ? | 50 // Is least upper bound N<N<...>> ? |
51 (z ? a : b).n.n; /// 05: static type warning | 51 (z ? a : b).n.n; //# 05: static type warning |
52 // Is least upper bound N<C1<...>> ? | 52 // Is least upper bound N<C1<...>> ? |
53 (z ? a : b).n.c1; /// 06: static type warning | 53 (z ? a : b).n.c1; //# 06: static type warning |
54 } | 54 } |
55 } | 55 } |
56 | 56 |
57 /** | 57 /** |
58 * Test that we don't try to find the least upper bound by applying the | 58 * Test that we don't try to find the least upper bound by applying the |
59 * algorithm for finding the most specific common declaration recursively on | 59 * algorithm for finding the most specific common declaration recursively on |
60 * type arguments. | 60 * type arguments. |
61 * | 61 * |
62 * For C1<int> and N<C1<String>> this would result in this infinite and | 62 * For C1<int> and N<C1<String>> this would result in this infinite and |
63 * expanding chain of computations: | 63 * expanding chain of computations: |
(...skipping 10 matching lines...) Expand all Loading... |
74 | 74 |
75 void testC2(bool z, C2<int> a, N<C2<String>> b) { | 75 void testC2(bool z, C2<int> a, N<C2<String>> b) { |
76 if (z) { | 76 if (z) { |
77 // The least upper bound of C2<int> and N<C2<String>> is Object since the | 77 // The least upper bound of C2<int> and N<C2<String>> is Object since the |
78 // supertypes are | 78 // supertypes are |
79 // {C2<int>, N<N<C2<N<C2<int>>>>>, Object} for C1<int> and | 79 // {C2<int>, N<N<C2<N<C2<int>>>>>, Object} for C1<int> and |
80 // {N<C2<String>>, Object} for N<C1<String>> and | 80 // {N<C2<String>>, Object} for N<C1<String>> and |
81 // Object is the most specific type in the intersection of the supertypes. | 81 // Object is the most specific type in the intersection of the supertypes. |
82 | 82 |
83 // Is least upper bound dynamic? | 83 // Is least upper bound dynamic? |
84 (z ? a : b).z; /// 07: static type warning | 84 (z ? a : b).z; //# 07: static type warning |
85 // Is least upper bound N<...> ? | 85 // Is least upper bound N<...> ? |
86 (z ? a : b).n; /// 08: static type warning | 86 (z ? a : b).n; //# 08: static type warning |
87 // Is least upper bound C2<...> ? | 87 // Is least upper bound C2<...> ? |
88 (z ? a : b).c2; /// 09: static type warning | 88 (z ? a : b).c2; //# 09: static type warning |
89 // Is least upper bound N<dynamic> ? | 89 // Is least upper bound N<dynamic> ? |
90 (z ? a : b).n.z; /// 10: static type warning | 90 (z ? a : b).n.z; //# 10: static type warning |
91 // Is least upper bound N<N<...>> ? | 91 // Is least upper bound N<N<...>> ? |
92 (z ? a : b).n.n; /// 11: static type warning | 92 (z ? a : b).n.n; //# 11: static type warning |
93 // Is least upper bound N<C2<...>> ? | 93 // Is least upper bound N<C2<...>> ? |
94 (z ? a : b).n.c2; /// 12: static type warning | 94 (z ? a : b).n.c2; //# 12: static type warning |
95 } | 95 } |
96 } | 96 } |
97 | 97 |
98 void main() { | 98 void main() { |
99 testC1(false, null, null); | 99 testC1(false, null, null); |
100 testC2(false, null, null); | 100 testC2(false, null, null); |
101 } | 101 } |
OLD | NEW |