Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(262)

Side by Side Diff: tests/compiler/dart2js/subtype_test.dart

Issue 2345083003: dart2js: run dartfmt on tests (Closed)
Patch Set: revert another multipart test Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 library subtype_test; 5 library subtype_test;
6 6
7 import 'package:expect/expect.dart'; 7 import 'package:expect/expect.dart';
8 import "package:async_helper/async_helper.dart"; 8 import "package:async_helper/async_helper.dart";
9 import 'type_test_helper.dart'; 9 import 'type_test_helper.dart';
10 import 'package:compiler/src/dart_types.dart'; 10 import 'package:compiler/src/dart_types.dart';
11 import "package:compiler/src/elements/elements.dart" 11 import "package:compiler/src/elements/elements.dart" show Element, ClassElement;
12 show Element, ClassElement;
13 12
14 void main() { 13 void main() {
15 testInterfaceSubtype(); 14 testInterfaceSubtype();
16 testCallableSubtype(); 15 testCallableSubtype();
17 testFunctionSubtyping(); 16 testFunctionSubtyping();
18 testTypedefSubtyping(); 17 testTypedefSubtyping();
19 testFunctionSubtypingOptional(); 18 testFunctionSubtypingOptional();
20 testTypedefSubtypingOptional(); 19 testTypedefSubtypingOptional();
21 testFunctionSubtypingNamed(); 20 testFunctionSubtypingNamed();
22 testTypedefSubtypingNamed(); 21 testTypedefSubtypingNamed();
23 testTypeVariableSubtype(); 22 testTypeVariableSubtype();
24 } 23 }
25 24
26 void testTypes(TypeEnvironment env, DartType subtype, DartType supertype, 25 void testTypes(TypeEnvironment env, DartType subtype, DartType supertype,
27 bool expectSubtype, bool expectMoreSpecific) { 26 bool expectSubtype, bool expectMoreSpecific) {
28 if (expectMoreSpecific == null) expectMoreSpecific = expectSubtype; 27 if (expectMoreSpecific == null) expectMoreSpecific = expectSubtype;
29 Expect.equals(expectSubtype, env.isSubtype(subtype, supertype), 28 Expect.equals(expectSubtype, env.isSubtype(subtype, supertype),
30 '$subtype <: $supertype'); 29 '$subtype <: $supertype');
31 Expect.equals(expectMoreSpecific, env.isMoreSpecific(subtype, supertype), 30 Expect.equals(expectMoreSpecific, env.isMoreSpecific(subtype, supertype),
32 '$subtype << $supertype'); 31 '$subtype << $supertype');
33 } 32 }
34 33
35 void testElementTypes(TypeEnvironment env, String subname, String supername, 34 void testElementTypes(TypeEnvironment env, String subname, String supername,
36 bool expectSubtype, bool expectMoreSpecific) { 35 bool expectSubtype, bool expectMoreSpecific) {
37 DartType subtype = env.getElementType(subname); 36 DartType subtype = env.getElementType(subname);
38 DartType supertype = env.getElementType(supername); 37 DartType supertype = env.getElementType(supername);
39 testTypes(env, subtype, supertype, expectSubtype, expectMoreSpecific); 38 testTypes(env, subtype, supertype, expectSubtype, expectMoreSpecific);
40 } 39 }
41 40
42
43 void testInterfaceSubtype() { 41 void testInterfaceSubtype() {
44 asyncTest(() => TypeEnvironment.create(r""" 42 asyncTest(() => TypeEnvironment.create(r"""
45 class A<T> {} 43 class A<T> {}
46 class B<T1, T2> extends A<T1> {} 44 class B<T1, T2> extends A<T1> {}
47 // TODO(johnniwinther): Inheritance with different type arguments is 45 // TODO(johnniwinther): Inheritance with different type arguments is
48 // currently not supported by the implementation. 46 // currently not supported by the implementation.
49 class C<T1, T2> extends B<T2, T1> /*implements A<A<T1>>*/ {} 47 class C<T1, T2> extends B<T2, T1> /*implements A<A<T1>>*/ {}
50 """).then((env) { 48 """).then((env) {
51 49 void expect(bool expectSubtype, DartType T, DartType S,
52 void expect(bool expectSubtype, DartType T, DartType S, 50 {bool expectMoreSpecific}) {
53 {bool expectMoreSpecific}) { 51 testTypes(env, T, S, expectSubtype, expectMoreSpecific);
54 testTypes(env, T, S, expectSubtype, expectMoreSpecific); 52 }
55 } 53
56 54 ClassElement A = env.getElement('A');
57 ClassElement A = env.getElement('A'); 55 ClassElement B = env.getElement('B');
58 ClassElement B = env.getElement('B'); 56 ClassElement C = env.getElement('C');
59 ClassElement C = env.getElement('C'); 57 DartType Object_ = env['Object'];
60 DartType Object_ = env['Object']; 58 DartType num_ = env['num'];
61 DartType num_ = env['num']; 59 DartType int_ = env['int'];
62 DartType int_ = env['int']; 60 DartType String_ = env['String'];
63 DartType String_ = env['String']; 61 DartType dynamic_ = env['dynamic'];
64 DartType dynamic_ = env['dynamic']; 62 DartType void_ = env['void'];
65 DartType void_ = env['void']; 63
66 64 expect(true, void_, void_);
67 expect(true, void_, void_); 65 expect(true, void_, dynamic_);
68 expect(true, void_, dynamic_); 66 // Unsure about the next one, see dartbug.com/14933.
69 // Unsure about the next one, see dartbug.com/14933. 67 expect(true, dynamic_, void_, expectMoreSpecific: false);
70 expect(true, dynamic_, void_, expectMoreSpecific: false); 68 expect(false, void_, Object_);
71 expect(false, void_, Object_); 69 expect(false, Object_, void_);
72 expect(false, Object_, void_); 70
73 71 expect(true, Object_, Object_);
74 expect(true, Object_, Object_); 72 expect(true, num_, Object_);
75 expect(true, num_, Object_); 73 expect(true, int_, Object_);
76 expect(true, int_, Object_); 74 expect(true, String_, Object_);
77 expect(true, String_, Object_); 75 expect(true, dynamic_, Object_, expectMoreSpecific: false);
78 expect(true, dynamic_, Object_, expectMoreSpecific: false); 76
79 77 expect(false, Object_, num_);
80 expect(false, Object_, num_); 78 expect(true, num_, num_);
81 expect(true, num_, num_); 79 expect(true, int_, num_);
82 expect(true, int_, num_); 80 expect(false, String_, num_);
83 expect(false, String_, num_); 81 expect(true, dynamic_, num_, expectMoreSpecific: false);
84 expect(true, dynamic_, num_, expectMoreSpecific: false); 82
85 83 expect(false, Object_, int_);
86 expect(false, Object_, int_); 84 expect(false, num_, int_);
87 expect(false, num_, int_); 85 expect(true, int_, int_);
88 expect(true, int_, int_); 86 expect(false, String_, int_);
89 expect(false, String_, int_); 87 expect(true, dynamic_, int_, expectMoreSpecific: false);
90 expect(true, dynamic_, int_, expectMoreSpecific: false); 88
91 89 expect(false, Object_, String_);
92 expect(false, Object_, String_); 90 expect(false, num_, String_);
93 expect(false, num_, String_); 91 expect(false, int_, String_);
94 expect(false, int_, String_); 92 expect(true, String_, String_);
95 expect(true, String_, String_); 93 expect(true, dynamic_, String_, expectMoreSpecific: false);
96 expect(true, dynamic_, String_, expectMoreSpecific: false); 94
97 95 expect(true, Object_, dynamic_);
98 expect(true, Object_, dynamic_); 96 expect(true, num_, dynamic_);
99 expect(true, num_, dynamic_); 97 expect(true, int_, dynamic_);
100 expect(true, int_, dynamic_); 98 expect(true, String_, dynamic_);
101 expect(true, String_, dynamic_); 99 expect(true, dynamic_, dynamic_);
102 expect(true, dynamic_, dynamic_); 100
103 101 DartType A_Object = instantiate(A, [Object_]);
104 DartType A_Object = instantiate(A, [Object_]); 102 DartType A_num = instantiate(A, [num_]);
105 DartType A_num = instantiate(A, [num_]); 103 DartType A_int = instantiate(A, [int_]);
106 DartType A_int = instantiate(A, [int_]); 104 DartType A_String = instantiate(A, [String_]);
107 DartType A_String = instantiate(A, [String_]); 105 DartType A_dynamic = instantiate(A, [dynamic_]);
108 DartType A_dynamic = instantiate(A, [dynamic_]); 106
109 107 expect(true, A_Object, Object_);
110 expect(true, A_Object, Object_); 108 expect(false, A_Object, num_);
111 expect(false, A_Object, num_); 109 expect(false, A_Object, int_);
112 expect(false, A_Object, int_); 110 expect(false, A_Object, String_);
113 expect(false, A_Object, String_); 111 expect(true, A_Object, dynamic_);
114 expect(true, A_Object, dynamic_); 112
115 113 expect(true, A_Object, A_Object);
116 expect(true, A_Object, A_Object); 114 expect(true, A_num, A_Object);
117 expect(true, A_num, A_Object); 115 expect(true, A_int, A_Object);
118 expect(true, A_int, A_Object); 116 expect(true, A_String, A_Object);
119 expect(true, A_String, A_Object); 117 expect(true, A_dynamic, A_Object, expectMoreSpecific: false);
120 expect(true, A_dynamic, A_Object, expectMoreSpecific: false); 118
121 119 expect(false, A_Object, A_num);
122 expect(false, A_Object, A_num); 120 expect(true, A_num, A_num);
123 expect(true, A_num, A_num); 121 expect(true, A_int, A_num);
124 expect(true, A_int, A_num); 122 expect(false, A_String, A_num);
125 expect(false, A_String, A_num); 123 expect(true, A_dynamic, A_num, expectMoreSpecific: false);
126 expect(true, A_dynamic, A_num, expectMoreSpecific: false); 124
127 125 expect(false, A_Object, A_int);
128 expect(false, A_Object, A_int); 126 expect(false, A_num, A_int);
129 expect(false, A_num, A_int); 127 expect(true, A_int, A_int);
130 expect(true, A_int, A_int); 128 expect(false, A_String, A_int);
131 expect(false, A_String, A_int); 129 expect(true, A_dynamic, A_int, expectMoreSpecific: false);
132 expect(true, A_dynamic, A_int, expectMoreSpecific: false); 130
133 131 expect(false, A_Object, A_String);
134 expect(false, A_Object, A_String); 132 expect(false, A_num, A_String);
135 expect(false, A_num, A_String); 133 expect(false, A_int, A_String);
136 expect(false, A_int, A_String); 134 expect(true, A_String, A_String);
137 expect(true, A_String, A_String); 135 expect(true, A_dynamic, A_String, expectMoreSpecific: false);
138 expect(true, A_dynamic, A_String, expectMoreSpecific: false); 136
139 137 expect(true, A_Object, A_dynamic);
140 expect(true, A_Object, A_dynamic); 138 expect(true, A_num, A_dynamic);
141 expect(true, A_num, A_dynamic); 139 expect(true, A_int, A_dynamic);
142 expect(true, A_int, A_dynamic); 140 expect(true, A_String, A_dynamic);
143 expect(true, A_String, A_dynamic); 141 expect(true, A_dynamic, A_dynamic);
144 expect(true, A_dynamic, A_dynamic); 142
145 143 DartType B_Object_Object = instantiate(B, [Object_, Object_]);
146 DartType B_Object_Object = instantiate(B, [Object_, Object_]); 144 DartType B_num_num = instantiate(B, [num_, num_]);
147 DartType B_num_num = instantiate(B, [num_, num_]); 145 DartType B_int_num = instantiate(B, [int_, num_]);
148 DartType B_int_num = instantiate(B, [int_, num_]); 146 DartType B_dynamic_dynamic = instantiate(B, [dynamic_, dynamic_]);
149 DartType B_dynamic_dynamic = instantiate(B, [dynamic_, dynamic_]); 147 DartType B_String_dynamic = instantiate(B, [String_, dynamic_]);
150 DartType B_String_dynamic = instantiate(B, [String_, dynamic_]); 148
151 149 expect(true, B_Object_Object, Object_);
152 expect(true, B_Object_Object, Object_); 150 expect(true, B_Object_Object, A_Object);
153 expect(true, B_Object_Object, A_Object); 151 expect(false, B_Object_Object, A_num);
154 expect(false, B_Object_Object, A_num); 152 expect(false, B_Object_Object, A_int);
155 expect(false, B_Object_Object, A_int); 153 expect(false, B_Object_Object, A_String);
156 expect(false, B_Object_Object, A_String); 154 expect(true, B_Object_Object, A_dynamic);
157 expect(true, B_Object_Object, A_dynamic); 155
158 156 expect(true, B_num_num, Object_);
159 expect(true, B_num_num, Object_); 157 expect(true, B_num_num, A_Object);
160 expect(true, B_num_num, A_Object); 158 expect(true, B_num_num, A_num);
161 expect(true, B_num_num, A_num); 159 expect(false, B_num_num, A_int);
162 expect(false, B_num_num, A_int); 160 expect(false, B_num_num, A_String);
163 expect(false, B_num_num, A_String); 161 expect(true, B_num_num, A_dynamic);
164 expect(true, B_num_num, A_dynamic); 162
165 163 expect(true, B_int_num, Object_);
166 expect(true, B_int_num, Object_); 164 expect(true, B_int_num, A_Object);
167 expect(true, B_int_num, A_Object); 165 expect(true, B_int_num, A_num);
168 expect(true, B_int_num, A_num); 166 expect(true, B_int_num, A_int);
169 expect(true, B_int_num, A_int); 167 expect(false, B_int_num, A_String);
170 expect(false, B_int_num, A_String); 168 expect(true, B_int_num, A_dynamic);
171 expect(true, B_int_num, A_dynamic); 169
172 170 expect(true, B_dynamic_dynamic, Object_);
173 expect(true, B_dynamic_dynamic, Object_); 171 expect(true, B_dynamic_dynamic, A_Object, expectMoreSpecific: false);
174 expect(true, B_dynamic_dynamic, A_Object, expectMoreSpecific: false); 172 expect(true, B_dynamic_dynamic, A_num, expectMoreSpecific: false);
175 expect(true, B_dynamic_dynamic, A_num, expectMoreSpecific: false); 173 expect(true, B_dynamic_dynamic, A_int, expectMoreSpecific: false);
176 expect(true, B_dynamic_dynamic, A_int, expectMoreSpecific: false); 174 expect(true, B_dynamic_dynamic, A_String, expectMoreSpecific: false);
177 expect(true, B_dynamic_dynamic, A_String, expectMoreSpecific: false); 175 expect(true, B_dynamic_dynamic, A_dynamic);
178 expect(true, B_dynamic_dynamic, A_dynamic); 176
179 177 expect(true, B_String_dynamic, Object_);
180 expect(true, B_String_dynamic, Object_); 178 expect(true, B_String_dynamic, A_Object);
181 expect(true, B_String_dynamic, A_Object); 179 expect(false, B_String_dynamic, A_num);
182 expect(false, B_String_dynamic, A_num); 180 expect(false, B_String_dynamic, A_int);
183 expect(false, B_String_dynamic, A_int); 181 expect(true, B_String_dynamic, A_String);
184 expect(true, B_String_dynamic, A_String); 182 expect(true, B_String_dynamic, A_dynamic);
185 expect(true, B_String_dynamic, A_dynamic); 183
186 184 expect(true, B_Object_Object, B_Object_Object);
187 expect(true, B_Object_Object, B_Object_Object); 185 expect(true, B_num_num, B_Object_Object);
188 expect(true, B_num_num, B_Object_Object); 186 expect(true, B_int_num, B_Object_Object);
189 expect(true, B_int_num, B_Object_Object); 187 expect(true, B_dynamic_dynamic, B_Object_Object,
190 expect(true, B_dynamic_dynamic, B_Object_Object, expectMoreSpecific: false); 188 expectMoreSpecific: false);
191 expect(true, B_String_dynamic, B_Object_Object, expectMoreSpecific: false); 189 expect(true, B_String_dynamic, B_Object_Object,
192 190 expectMoreSpecific: false);
193 expect(false, B_Object_Object, B_num_num); 191
194 expect(true, B_num_num, B_num_num); 192 expect(false, B_Object_Object, B_num_num);
195 expect(true, B_int_num, B_num_num); 193 expect(true, B_num_num, B_num_num);
196 expect(true, B_dynamic_dynamic, B_num_num, expectMoreSpecific: false); 194 expect(true, B_int_num, B_num_num);
197 expect(false, B_String_dynamic, B_num_num); 195 expect(true, B_dynamic_dynamic, B_num_num, expectMoreSpecific: false);
198 196 expect(false, B_String_dynamic, B_num_num);
199 expect(false, B_Object_Object, B_int_num); 197
200 expect(false, B_num_num, B_int_num); 198 expect(false, B_Object_Object, B_int_num);
201 expect(true, B_int_num, B_int_num); 199 expect(false, B_num_num, B_int_num);
202 expect(true, B_dynamic_dynamic, B_int_num, expectMoreSpecific: false); 200 expect(true, B_int_num, B_int_num);
203 expect(false, B_String_dynamic, B_int_num); 201 expect(true, B_dynamic_dynamic, B_int_num, expectMoreSpecific: false);
204 202 expect(false, B_String_dynamic, B_int_num);
205 expect(true, B_Object_Object, B_dynamic_dynamic); 203
206 expect(true, B_num_num, B_dynamic_dynamic); 204 expect(true, B_Object_Object, B_dynamic_dynamic);
207 expect(true, B_int_num, B_dynamic_dynamic); 205 expect(true, B_num_num, B_dynamic_dynamic);
208 expect(true, B_dynamic_dynamic, B_dynamic_dynamic); 206 expect(true, B_int_num, B_dynamic_dynamic);
209 expect(true, B_String_dynamic, B_dynamic_dynamic); 207 expect(true, B_dynamic_dynamic, B_dynamic_dynamic);
210 208 expect(true, B_String_dynamic, B_dynamic_dynamic);
211 expect(false, B_Object_Object, B_String_dynamic); 209
212 expect(false, B_num_num, B_String_dynamic); 210 expect(false, B_Object_Object, B_String_dynamic);
213 expect(false, B_int_num, B_String_dynamic); 211 expect(false, B_num_num, B_String_dynamic);
214 expect(true, B_dynamic_dynamic, B_String_dynamic, 212 expect(false, B_int_num, B_String_dynamic);
215 expectMoreSpecific: false); 213 expect(true, B_dynamic_dynamic, B_String_dynamic,
216 expect(true, B_String_dynamic, B_String_dynamic); 214 expectMoreSpecific: false);
217 215 expect(true, B_String_dynamic, B_String_dynamic);
218 DartType C_Object_Object = instantiate(C, [Object_, Object_]); 216
219 DartType C_num_num = instantiate(C, [num_, num_]); 217 DartType C_Object_Object = instantiate(C, [Object_, Object_]);
220 DartType C_int_String = instantiate(C, [int_, String_]); 218 DartType C_num_num = instantiate(C, [num_, num_]);
221 DartType C_dynamic_dynamic = instantiate(C, [dynamic_, dynamic_]); 219 DartType C_int_String = instantiate(C, [int_, String_]);
222 220 DartType C_dynamic_dynamic = instantiate(C, [dynamic_, dynamic_]);
223 expect(true, C_Object_Object, B_Object_Object); 221
224 expect(false, C_Object_Object, B_num_num); 222 expect(true, C_Object_Object, B_Object_Object);
225 expect(false, C_Object_Object, B_int_num); 223 expect(false, C_Object_Object, B_num_num);
226 expect(true, C_Object_Object, B_dynamic_dynamic); 224 expect(false, C_Object_Object, B_int_num);
227 expect(false, C_Object_Object, B_String_dynamic); 225 expect(true, C_Object_Object, B_dynamic_dynamic);
228 226 expect(false, C_Object_Object, B_String_dynamic);
229 expect(true, C_num_num, B_Object_Object); 227
230 expect(true, C_num_num, B_num_num); 228 expect(true, C_num_num, B_Object_Object);
231 expect(false, C_num_num, B_int_num); 229 expect(true, C_num_num, B_num_num);
232 expect(true, C_num_num, B_dynamic_dynamic); 230 expect(false, C_num_num, B_int_num);
233 expect(false, C_num_num, B_String_dynamic); 231 expect(true, C_num_num, B_dynamic_dynamic);
234 232 expect(false, C_num_num, B_String_dynamic);
235 expect(true, C_int_String, B_Object_Object); 233
236 expect(false, C_int_String, B_num_num); 234 expect(true, C_int_String, B_Object_Object);
237 expect(false, C_int_String, B_int_num); 235 expect(false, C_int_String, B_num_num);
238 expect(true, C_int_String, B_dynamic_dynamic); 236 expect(false, C_int_String, B_int_num);
239 expect(true, C_int_String, B_String_dynamic); 237 expect(true, C_int_String, B_dynamic_dynamic);
240 238 expect(true, C_int_String, B_String_dynamic);
241 expect(true, C_dynamic_dynamic, B_Object_Object, expectMoreSpecific: false); 239
242 expect(true, C_dynamic_dynamic, B_num_num, expectMoreSpecific: false); 240 expect(true, C_dynamic_dynamic, B_Object_Object,
243 expect(true, C_dynamic_dynamic, B_int_num, expectMoreSpecific: false); 241 expectMoreSpecific: false);
244 expect(true, C_dynamic_dynamic, B_dynamic_dynamic); 242 expect(true, C_dynamic_dynamic, B_num_num, expectMoreSpecific: false);
245 expect(true, C_dynamic_dynamic, B_String_dynamic, 243 expect(true, C_dynamic_dynamic, B_int_num, expectMoreSpecific: false);
246 expectMoreSpecific: false); 244 expect(true, C_dynamic_dynamic, B_dynamic_dynamic);
247 245 expect(true, C_dynamic_dynamic, B_String_dynamic,
248 expect(false, C_int_String, A_int); 246 expectMoreSpecific: false);
249 expect(true, C_int_String, A_String); 247
250 // TODO(johnniwinther): Inheritance with different type arguments is 248 expect(false, C_int_String, A_int);
251 // currently not supported by the implementation. 249 expect(true, C_int_String, A_String);
252 //expect(true, C_int_String, instantiate(A, [A_int])); 250 // TODO(johnniwinther): Inheritance with different type arguments is
253 expect(false, C_int_String, instantiate(A, [A_String])); 251 // currently not supported by the implementation.
254 })); 252 //expect(true, C_int_String, instantiate(A, [A_int]));
253 expect(false, C_int_String, instantiate(A, [A_String]));
254 }));
255 } 255 }
256 256
257 void testCallableSubtype() { 257 void testCallableSubtype() {
258 asyncTest(() => TypeEnvironment.create(r""" 258 asyncTest(() => TypeEnvironment.create(r"""
259 class U {} 259 class U {}
260 class V extends U {} 260 class V extends U {}
261 class W extends V {} 261 class W extends V {}
262 class A { 262 class A {
263 int call(V v, int i); 263 int call(V v, int i);
264 264
265 int m1(U u, int i); 265 int m1(U u, int i);
266 int m2(W w, num n); 266 int m2(W w, num n);
267 U m3(V v, int i); 267 U m3(V v, int i);
268 int m4(V v, U u); 268 int m4(V v, U u);
269 void m5(V v, int i); 269 void m5(V v, int i);
270 } 270 }
271 """).then((env) { 271 """).then((env) {
272 void expect(bool expectSubtype, DartType T, DartType S, 272 void expect(bool expectSubtype, DartType T, DartType S,
273 {bool expectMoreSpecific}) { 273 {bool expectMoreSpecific}) {
274 testTypes(env, T, S, expectSubtype, expectMoreSpecific); 274 testTypes(env, T, S, expectSubtype, expectMoreSpecific);
275 } 275 }
276 276
277 ClassElement classA = env.getElement('A'); 277 ClassElement classA = env.getElement('A');
278 DartType A = classA.rawType; 278 DartType A = classA.rawType;
279 DartType function = env['Function']; 279 DartType function = env['Function'];
280 DartType call = env.getMemberType(classA, 'call'); 280 DartType call = env.getMemberType(classA, 'call');
281 DartType m1 = env.getMemberType(classA, 'm1'); 281 DartType m1 = env.getMemberType(classA, 'm1');
282 DartType m2 = env.getMemberType(classA, 'm2'); 282 DartType m2 = env.getMemberType(classA, 'm2');
283 DartType m3 = env.getMemberType(classA, 'm3'); 283 DartType m3 = env.getMemberType(classA, 'm3');
284 DartType m4 = env.getMemberType(classA, 'm4'); 284 DartType m4 = env.getMemberType(classA, 'm4');
285 DartType m5 = env.getMemberType(classA, 'm5'); 285 DartType m5 = env.getMemberType(classA, 'm5');
286 286
287 expect(true, A, function); 287 expect(true, A, function);
288 expect(true, A, call); 288 expect(true, A, call);
289 expect(true, call, m1); 289 expect(true, call, m1);
290 expect(true, A, m1); 290 expect(true, A, m1);
291 expect(true, A, m2, expectMoreSpecific: false); 291 expect(true, A, m2, expectMoreSpecific: false);
292 expect(false, A, m3); 292 expect(false, A, m3);
293 expect(false, A, m4); 293 expect(false, A, m4);
294 expect(true, A, m5); 294 expect(true, A, m5);
295 })); 295 }));
296 } 296 }
297 297
298 testFunctionSubtyping() { 298 testFunctionSubtyping() {
299 asyncTest(() => TypeEnvironment.create(r""" 299 asyncTest(() => TypeEnvironment.create(r"""
300 _() => null; 300 _() => null;
301 void void_() {} 301 void void_() {}
302 void void_2() {} 302 void void_2() {}
303 int int_() => 0; 303 int int_() => 0;
304 int int_2() => 0; 304 int int_2() => 0;
305 Object Object_() => null; 305 Object Object_() => null;
(...skipping 26 matching lines...) Expand all
332 typedef Object Object__int(int i); 332 typedef Object Object__int(int i);
333 typedef int int__double(double d); 333 typedef int int__double(double d);
334 typedef int int__int_int(int i1, int i2); 334 typedef int int__int_int(int i1, int i2);
335 typedef void inline_void_(void f()); 335 typedef void inline_void_(void f());
336 typedef void inline_void__int(void f(int i)); 336 typedef void inline_void__int(void f(int i));
337 """).then(functionSubtypingHelper)); 337 """).then(functionSubtypingHelper));
338 } 338 }
339 339
340 functionSubtypingHelper(TypeEnvironment env) { 340 functionSubtypingHelper(TypeEnvironment env) {
341 void expect(bool expectSubtype, String sub, String sup, 341 void expect(bool expectSubtype, String sub, String sup,
342 {bool expectMoreSpecific}) { 342 {bool expectMoreSpecific}) {
343 testElementTypes(env, sub, sup, expectSubtype, expectMoreSpecific); 343 testElementTypes(env, sub, sup, expectSubtype, expectMoreSpecific);
344 } 344 }
345 345
346 // () -> int <: Function 346 // () -> int <: Function
347 expect(true, 'int_', 'Function'); 347 expect(true, 'int_', 'Function');
348 // Function <: () -> int 348 // Function <: () -> int
349 expect(false, 'Function', 'int_'); 349 expect(false, 'Function', 'int_');
350 350
351 // () -> dynamic <: () -> dynamic 351 // () -> dynamic <: () -> dynamic
352 expect(true, '_', '_'); 352 expect(true, '_', '_');
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
420 typedef void void__int__int_int(int i1, [int i2, int i3]); 420 typedef void void__int__int_int(int i1, [int i2, int i3]);
421 typedef void void___double(double d); 421 typedef void void___double(double d);
422 typedef void void___int_int([int i1, int i2]); 422 typedef void void___int_int([int i1, int i2]);
423 typedef void void___int_int_int([int i1, int i2, int i3]); 423 typedef void void___int_int_int([int i1, int i2, int i3]);
424 typedef void void___Object_int([Object o, int i]); 424 typedef void void___Object_int([Object o, int i]);
425 """).then(functionSubtypingOptionalHelper)); 425 """).then(functionSubtypingOptionalHelper));
426 } 426 }
427 427
428 functionSubtypingOptionalHelper(TypeEnvironment env) { 428 functionSubtypingOptionalHelper(TypeEnvironment env) {
429 void expect(bool expectSubtype, String sub, String sup, 429 void expect(bool expectSubtype, String sub, String sup,
430 {bool expectMoreSpecific}) { 430 {bool expectMoreSpecific}) {
431 testElementTypes(env, sub, sup, expectSubtype, expectMoreSpecific); 431 testElementTypes(env, sub, sup, expectSubtype, expectMoreSpecific);
432 } 432 }
433 433
434 // Test ([int])->void <: ()->void. 434 // Test ([int])->void <: ()->void.
435 expect(true, 'void___int', 'void_'); 435 expect(true, 'void___int', 'void_');
436 // Test ([int])->void <: (int)->void. 436 // Test ([int])->void <: (int)->void.
437 expect(true, 'void___int', 'void__int'); 437 expect(true, 'void___int', 'void__int');
438 // Test (int)->void <: ([int])->void. 438 // Test (int)->void <: ([int])->void.
439 expect(false, 'void__int', 'void___int'); 439 expect(false, 'void__int', 'void___int');
440 // Test ([int])->void <: ([int])->void. 440 // Test ([int])->void <: ([int])->void.
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
500 typedef void void___a_int_b_int({int a, int b}); 500 typedef void void___a_int_b_int({int a, int b});
501 typedef void void___a_int_b_int_c_int({int a, int b, int c}); 501 typedef void void___a_int_b_int_c_int({int a, int b, int c});
502 typedef void void___a_int_c_int({int a, int c}); 502 typedef void void___a_int_c_int({int a, int c});
503 typedef void void___b_int_c_int({int b, int c}); 503 typedef void void___b_int_c_int({int b, int c});
504 typedef void void___c_int({int c}); 504 typedef void void___c_int({int c});
505 """).then(functionSubtypingNamedHelper)); 505 """).then(functionSubtypingNamedHelper));
506 } 506 }
507 507
508 functionSubtypingNamedHelper(TypeEnvironment env) { 508 functionSubtypingNamedHelper(TypeEnvironment env) {
509 expect(bool expectSubtype, String sub, String sup, 509 expect(bool expectSubtype, String sub, String sup,
510 {bool expectMoreSpecific}) { 510 {bool expectMoreSpecific}) {
511 testElementTypes(env, sub, sup, expectSubtype, expectMoreSpecific); 511 testElementTypes(env, sub, sup, expectSubtype, expectMoreSpecific);
512 } 512 }
513 513
514 // Test ({int a})->void <: ()->void. 514 // Test ({int a})->void <: ()->void.
515 expect(true, 'void___a_int', 'void_'); 515 expect(true, 'void___a_int', 'void_');
516 // Test ({int a})->void <: (int)->void. 516 // Test ({int a})->void <: (int)->void.
517 expect(false, 'void___a_int', 'void__int'); 517 expect(false, 'void___a_int', 'void__int');
518 // Test (int)->void <: ({int a})->void. 518 // Test (int)->void <: ({int a})->void.
519 expect(false, 'void__int', 'void___a_int'); 519 expect(false, 'void__int', 'void___a_int');
520 // Test ({int a})->void <: ({int a})->void. 520 // Test ({int a})->void <: ({int a})->void.
(...skipping 26 matching lines...) Expand all
547 class B<T extends Object> {} 547 class B<T extends Object> {}
548 class C<T extends num> {} 548 class C<T extends num> {}
549 class D<T extends int> {} 549 class D<T extends int> {}
550 class E<T extends S, S extends num> {} 550 class E<T extends S, S extends num> {}
551 class F<T extends num, S extends T> {} 551 class F<T extends num, S extends T> {}
552 class G<T extends T> {} 552 class G<T extends T> {}
553 class H<T extends S, S extends T> {} 553 class H<T extends S, S extends T> {}
554 class I<T extends S, S extends U, U extends T> {} 554 class I<T extends S, S extends U, U extends T> {}
555 class J<T extends S, S extends U, U extends S> {} 555 class J<T extends S, S extends U, U extends S> {}
556 """).then((env) { 556 """).then((env) {
557 void expect(bool expectSubtype, DartType T, DartType S, 557 void expect(bool expectSubtype, DartType T, DartType S,
558 {bool expectMoreSpecific}) { 558 {bool expectMoreSpecific}) {
559 testTypes(env, T, S, expectSubtype, expectMoreSpecific); 559 testTypes(env, T, S, expectSubtype, expectMoreSpecific);
560 } 560 }
561 561
562 ClassElement A = env.getElement('A'); 562 ClassElement A = env.getElement('A');
563 TypeVariableType A_T = A.thisType.typeArguments[0]; 563 TypeVariableType A_T = A.thisType.typeArguments[0];
564 ClassElement B = env.getElement('B'); 564 ClassElement B = env.getElement('B');
565 TypeVariableType B_T = B.thisType.typeArguments[0]; 565 TypeVariableType B_T = B.thisType.typeArguments[0];
566 ClassElement C = env.getElement('C'); 566 ClassElement C = env.getElement('C');
567 TypeVariableType C_T = C.thisType.typeArguments[0]; 567 TypeVariableType C_T = C.thisType.typeArguments[0];
568 ClassElement D = env.getElement('D'); 568 ClassElement D = env.getElement('D');
569 TypeVariableType D_T = D.thisType.typeArguments[0]; 569 TypeVariableType D_T = D.thisType.typeArguments[0];
570 ClassElement E = env.getElement('E'); 570 ClassElement E = env.getElement('E');
571 TypeVariableType E_T = E.thisType.typeArguments[0]; 571 TypeVariableType E_T = E.thisType.typeArguments[0];
572 TypeVariableType E_S = E.thisType.typeArguments[1]; 572 TypeVariableType E_S = E.thisType.typeArguments[1];
573 ClassElement F = env.getElement('F'); 573 ClassElement F = env.getElement('F');
574 TypeVariableType F_T = F.thisType.typeArguments[0]; 574 TypeVariableType F_T = F.thisType.typeArguments[0];
575 TypeVariableType F_S = F.thisType.typeArguments[1]; 575 TypeVariableType F_S = F.thisType.typeArguments[1];
576 ClassElement G = env.getElement('G'); 576 ClassElement G = env.getElement('G');
577 TypeVariableType G_T = G.thisType.typeArguments[0]; 577 TypeVariableType G_T = G.thisType.typeArguments[0];
578 ClassElement H = env.getElement('H'); 578 ClassElement H = env.getElement('H');
579 TypeVariableType H_T = H.thisType.typeArguments[0]; 579 TypeVariableType H_T = H.thisType.typeArguments[0];
580 TypeVariableType H_S = H.thisType.typeArguments[1]; 580 TypeVariableType H_S = H.thisType.typeArguments[1];
581 ClassElement I = env.getElement('I'); 581 ClassElement I = env.getElement('I');
582 TypeVariableType I_T = I.thisType.typeArguments[0]; 582 TypeVariableType I_T = I.thisType.typeArguments[0];
583 TypeVariableType I_S = I.thisType.typeArguments[1]; 583 TypeVariableType I_S = I.thisType.typeArguments[1];
584 TypeVariableType I_U = I.thisType.typeArguments[2]; 584 TypeVariableType I_U = I.thisType.typeArguments[2];
585 ClassElement J = env.getElement('J'); 585 ClassElement J = env.getElement('J');
586 TypeVariableType J_T = J.thisType.typeArguments[0]; 586 TypeVariableType J_T = J.thisType.typeArguments[0];
587 TypeVariableType J_S = J.thisType.typeArguments[1]; 587 TypeVariableType J_S = J.thisType.typeArguments[1];
588 TypeVariableType J_U = J.thisType.typeArguments[2]; 588 TypeVariableType J_U = J.thisType.typeArguments[2];
589 589
590 DartType Object_ = env['Object']; 590 DartType Object_ = env['Object'];
591 DartType num_ = env['num']; 591 DartType num_ = env['num'];
592 DartType int_ = env['int']; 592 DartType int_ = env['int'];
593 DartType String_ = env['String']; 593 DartType String_ = env['String'];
594 DartType dynamic_ = env['dynamic']; 594 DartType dynamic_ = env['dynamic'];
595 595
596 // class A<T> {} 596 // class A<T> {}
597 expect(true, A_T, Object_); 597 expect(true, A_T, Object_);
598 expect(false, A_T, num_); 598 expect(false, A_T, num_);
599 expect(false, A_T, int_); 599 expect(false, A_T, int_);
600 expect(false, A_T, String_); 600 expect(false, A_T, String_);
601 expect(true, A_T, dynamic_); 601 expect(true, A_T, dynamic_);
602 expect(true, A_T, A_T); 602 expect(true, A_T, A_T);
603 expect(false, A_T, B_T); 603 expect(false, A_T, B_T);
604 604
605 // class B<T extends Object> {} 605 // class B<T extends Object> {}
606 expect(true, B_T, Object_); 606 expect(true, B_T, Object_);
607 expect(false, B_T, num_); 607 expect(false, B_T, num_);
608 expect(false, B_T, int_); 608 expect(false, B_T, int_);
609 expect(false, B_T, String_); 609 expect(false, B_T, String_);
610 expect(true, B_T, dynamic_); 610 expect(true, B_T, dynamic_);
611 expect(true, B_T, B_T); 611 expect(true, B_T, B_T);
612 expect(false, B_T, A_T); 612 expect(false, B_T, A_T);
613 613
614 // class C<T extends num> {} 614 // class C<T extends num> {}
615 expect(true, C_T, Object_); 615 expect(true, C_T, Object_);
616 expect(true, C_T, num_); 616 expect(true, C_T, num_);
617 expect(false, C_T, int_); 617 expect(false, C_T, int_);
618 expect(false, C_T, String_); 618 expect(false, C_T, String_);
619 expect(true, C_T, dynamic_); 619 expect(true, C_T, dynamic_);
620 expect(true, C_T, C_T); 620 expect(true, C_T, C_T);
621 expect(false, C_T, A_T); 621 expect(false, C_T, A_T);
622 622
623 // class D<T extends int> {} 623 // class D<T extends int> {}
624 expect(true, D_T, Object_); 624 expect(true, D_T, Object_);
625 expect(true, D_T, num_); 625 expect(true, D_T, num_);
626 expect(true, D_T, int_); 626 expect(true, D_T, int_);
627 expect(false, D_T, String_); 627 expect(false, D_T, String_);
628 expect(true, D_T, dynamic_); 628 expect(true, D_T, dynamic_);
629 expect(true, D_T, D_T); 629 expect(true, D_T, D_T);
630 expect(false, D_T, A_T); 630 expect(false, D_T, A_T);
631 631
632 // class E<T extends S, S extends num> {} 632 // class E<T extends S, S extends num> {}
633 expect(true, E_T, Object_); 633 expect(true, E_T, Object_);
634 expect(true, E_T, num_); 634 expect(true, E_T, num_);
635 expect(false, E_T, int_); 635 expect(false, E_T, int_);
636 expect(false, E_T, String_); 636 expect(false, E_T, String_);
637 expect(true, E_T, dynamic_); 637 expect(true, E_T, dynamic_);
638 expect(true, E_T, E_T); 638 expect(true, E_T, E_T);
639 expect(true, E_T, E_S); 639 expect(true, E_T, E_S);
640 expect(false, E_T, A_T); 640 expect(false, E_T, A_T);
641 641
642 expect(true, E_S, Object_); 642 expect(true, E_S, Object_);
643 expect(true, E_S, num_); 643 expect(true, E_S, num_);
644 expect(false, E_S, int_); 644 expect(false, E_S, int_);
645 expect(false, E_S, String_); 645 expect(false, E_S, String_);
646 expect(true, E_S, dynamic_); 646 expect(true, E_S, dynamic_);
647 expect(false, E_S, E_T); 647 expect(false, E_S, E_T);
648 expect(true, E_S, E_S); 648 expect(true, E_S, E_S);
649 expect(false, E_S, A_T); 649 expect(false, E_S, A_T);
650 650
651 // class F<T extends num, S extends T> {} 651 // class F<T extends num, S extends T> {}
652 expect(true, F_T, Object_); 652 expect(true, F_T, Object_);
653 expect(true, F_T, num_); 653 expect(true, F_T, num_);
654 expect(false, F_T, int_); 654 expect(false, F_T, int_);
655 expect(false, F_T, String_); 655 expect(false, F_T, String_);
656 expect(true, F_T, dynamic_); 656 expect(true, F_T, dynamic_);
657 expect(false, F_T, F_S); 657 expect(false, F_T, F_S);
658 expect(true, F_T, F_T); 658 expect(true, F_T, F_T);
659 expect(false, F_T, A_T); 659 expect(false, F_T, A_T);
660 660
661 expect(true, F_S, Object_); 661 expect(true, F_S, Object_);
662 expect(true, F_S, num_); 662 expect(true, F_S, num_);
663 expect(false, F_S, int_); 663 expect(false, F_S, int_);
664 expect(false, F_S, String_); 664 expect(false, F_S, String_);
665 expect(true, F_S, dynamic_); 665 expect(true, F_S, dynamic_);
666 expect(true, F_S, F_S); 666 expect(true, F_S, F_S);
667 expect(true, F_S, F_T); 667 expect(true, F_S, F_T);
668 expect(false, F_S, A_T); 668 expect(false, F_S, A_T);
669 669
670 // class G<T extends T> {} 670 // class G<T extends T> {}
671 expect(true, G_T, Object_); 671 expect(true, G_T, Object_);
672 expect(false, G_T, num_); 672 expect(false, G_T, num_);
673 expect(false, G_T, int_); 673 expect(false, G_T, int_);
674 expect(false, G_T, String_); 674 expect(false, G_T, String_);
675 expect(true, G_T, dynamic_); 675 expect(true, G_T, dynamic_);
676 expect(true, G_T, G_T); 676 expect(true, G_T, G_T);
677 expect(false, G_T, A_T); 677 expect(false, G_T, A_T);
678 678
679 // class H<T extends S, S extends T> {} 679 // class H<T extends S, S extends T> {}
680 expect(true, H_T, Object_); 680 expect(true, H_T, Object_);
681 expect(false, H_T, num_); 681 expect(false, H_T, num_);
682 expect(false, H_T, int_); 682 expect(false, H_T, int_);
683 expect(false, H_T, String_); 683 expect(false, H_T, String_);
684 expect(true, H_T, dynamic_); 684 expect(true, H_T, dynamic_);
685 expect(true, H_T, H_T); 685 expect(true, H_T, H_T);
686 expect(true, H_T, H_S); 686 expect(true, H_T, H_S);
687 expect(false, H_T, A_T); 687 expect(false, H_T, A_T);
688 688
689 expect(true, H_S, Object_); 689 expect(true, H_S, Object_);
690 expect(false, H_S, num_); 690 expect(false, H_S, num_);
691 expect(false, H_S, int_); 691 expect(false, H_S, int_);
692 expect(false, H_S, String_); 692 expect(false, H_S, String_);
693 expect(true, H_S, dynamic_); 693 expect(true, H_S, dynamic_);
694 expect(true, H_S, H_T); 694 expect(true, H_S, H_T);
695 expect(true, H_S, H_S); 695 expect(true, H_S, H_S);
696 expect(false, H_S, A_T); 696 expect(false, H_S, A_T);
697 697
698 // class I<T extends S, S extends U, U extends T> {} 698 // class I<T extends S, S extends U, U extends T> {}
699 expect(true, I_T, Object_); 699 expect(true, I_T, Object_);
700 expect(false, I_T, num_); 700 expect(false, I_T, num_);
701 expect(false, I_T, int_); 701 expect(false, I_T, int_);
702 expect(false, I_T, String_); 702 expect(false, I_T, String_);
703 expect(true, I_T, dynamic_); 703 expect(true, I_T, dynamic_);
704 expect(true, I_T, I_T); 704 expect(true, I_T, I_T);
705 expect(true, I_T, I_S); 705 expect(true, I_T, I_S);
706 expect(true, I_T, I_U); 706 expect(true, I_T, I_U);
707 expect(false, I_T, A_T); 707 expect(false, I_T, A_T);
708 708
709 expect(true, I_S, Object_); 709 expect(true, I_S, Object_);
710 expect(false, I_S, num_); 710 expect(false, I_S, num_);
711 expect(false, I_S, int_); 711 expect(false, I_S, int_);
712 expect(false, I_S, String_); 712 expect(false, I_S, String_);
713 expect(true, I_S, dynamic_); 713 expect(true, I_S, dynamic_);
714 expect(true, I_S, I_T); 714 expect(true, I_S, I_T);
715 expect(true, I_S, I_S); 715 expect(true, I_S, I_S);
716 expect(true, I_S, I_U); 716 expect(true, I_S, I_U);
717 expect(false, I_S, A_T); 717 expect(false, I_S, A_T);
718 718
719 expect(true, I_U, Object_); 719 expect(true, I_U, Object_);
720 expect(false, I_U, num_); 720 expect(false, I_U, num_);
721 expect(false, I_U, int_); 721 expect(false, I_U, int_);
722 expect(false, I_U, String_); 722 expect(false, I_U, String_);
723 expect(true, I_U, dynamic_); 723 expect(true, I_U, dynamic_);
724 expect(true, I_U, I_T); 724 expect(true, I_U, I_T);
725 expect(true, I_U, I_S); 725 expect(true, I_U, I_S);
726 expect(true, I_U, I_U); 726 expect(true, I_U, I_U);
727 expect(false, I_U, A_T); 727 expect(false, I_U, A_T);
728 728
729 // class J<T extends S, S extends U, U extends S> {} 729 // class J<T extends S, S extends U, U extends S> {}
730 expect(true, J_T, Object_); 730 expect(true, J_T, Object_);
731 expect(false, J_T, num_); 731 expect(false, J_T, num_);
732 expect(false, J_T, int_); 732 expect(false, J_T, int_);
733 expect(false, J_T, String_); 733 expect(false, J_T, String_);
734 expect(true, J_T, dynamic_); 734 expect(true, J_T, dynamic_);
735 expect(true, J_T, J_T); 735 expect(true, J_T, J_T);
736 expect(true, J_T, J_S); 736 expect(true, J_T, J_S);
737 expect(true, J_T, J_U); 737 expect(true, J_T, J_U);
738 expect(false, J_T, A_T); 738 expect(false, J_T, A_T);
739 739
740 expect(true, J_S, Object_); 740 expect(true, J_S, Object_);
741 expect(false, J_S, num_); 741 expect(false, J_S, num_);
742 expect(false, J_S, int_); 742 expect(false, J_S, int_);
743 expect(false, J_S, String_); 743 expect(false, J_S, String_);
744 expect(true, J_S, dynamic_); 744 expect(true, J_S, dynamic_);
745 expect(false, J_S, J_T); 745 expect(false, J_S, J_T);
746 expect(true, J_S, J_S); 746 expect(true, J_S, J_S);
747 expect(true, J_S, J_U); 747 expect(true, J_S, J_U);
748 expect(false, J_S, A_T); 748 expect(false, J_S, A_T);
749 749
750 expect(true, J_U, Object_); 750 expect(true, J_U, Object_);
751 expect(false, J_U, num_); 751 expect(false, J_U, num_);
752 expect(false, J_U, int_); 752 expect(false, J_U, int_);
753 expect(false, J_U, String_); 753 expect(false, J_U, String_);
754 expect(true, J_U, dynamic_); 754 expect(true, J_U, dynamic_);
755 expect(false, J_U, J_T); 755 expect(false, J_U, J_T);
756 expect(true, J_U, J_S); 756 expect(true, J_U, J_S);
757 expect(true, J_U, J_U); 757 expect(true, J_U, J_U);
758 expect(false, J_U, A_T); 758 expect(false, J_U, A_T);
759 })); 759 }));
760 } 760 }
OLDNEW
« no previous file with comments | « tests/compiler/dart2js/string_interpolation_test.dart ('k') | tests/compiler/dart2js/subtypeset_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698