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

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

Issue 2603263002: Prefix resolution_types with Resolution. (Closed)
Patch Set: Rebased Created 3 years, 11 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/elements/resolution_types.dart'; 10 import 'package:compiler/src/elements/resolution_types.dart';
11 import "package:compiler/src/elements/elements.dart" show Element, ClassElement; 11 import "package:compiler/src/elements/elements.dart" show Element, ClassElement;
12 12
13 void main() { 13 void main() {
14 testInterfaceSubtype(); 14 testInterfaceSubtype();
15 testCallableSubtype(); 15 testCallableSubtype();
16 testFunctionSubtyping(); 16 testFunctionSubtyping();
17 testTypedefSubtyping(); 17 testTypedefSubtyping();
18 testFunctionSubtypingOptional(); 18 testFunctionSubtypingOptional();
19 testTypedefSubtypingOptional(); 19 testTypedefSubtypingOptional();
20 testFunctionSubtypingNamed(); 20 testFunctionSubtypingNamed();
21 testTypedefSubtypingNamed(); 21 testTypedefSubtypingNamed();
22 testTypeVariableSubtype(); 22 testTypeVariableSubtype();
23 } 23 }
24 24
25 void testTypes(TypeEnvironment env, DartType subtype, DartType supertype, 25 void testTypes(TypeEnvironment env, ResolutionDartType subtype,
26 bool expectSubtype, bool expectMoreSpecific) { 26 ResolutionDartType supertype, bool expectSubtype, bool expectMoreSpecific) {
27 if (expectMoreSpecific == null) expectMoreSpecific = expectSubtype; 27 if (expectMoreSpecific == null) expectMoreSpecific = expectSubtype;
28 Expect.equals(expectSubtype, env.isSubtype(subtype, supertype), 28 Expect.equals(expectSubtype, env.isSubtype(subtype, supertype),
29 '$subtype <: $supertype'); 29 '$subtype <: $supertype');
30 Expect.equals(expectMoreSpecific, env.isMoreSpecific(subtype, supertype), 30 Expect.equals(expectMoreSpecific, env.isMoreSpecific(subtype, supertype),
31 '$subtype << $supertype'); 31 '$subtype << $supertype');
32 } 32 }
33 33
34 void testElementTypes(TypeEnvironment env, String subname, String supername, 34 void testElementTypes(TypeEnvironment env, String subname, String supername,
35 bool expectSubtype, bool expectMoreSpecific) { 35 bool expectSubtype, bool expectMoreSpecific) {
36 DartType subtype = env.getElementType(subname); 36 ResolutionDartType subtype = env.getElementType(subname);
37 DartType supertype = env.getElementType(supername); 37 ResolutionDartType supertype = env.getElementType(supername);
38 testTypes(env, subtype, supertype, expectSubtype, expectMoreSpecific); 38 testTypes(env, subtype, supertype, expectSubtype, expectMoreSpecific);
39 } 39 }
40 40
41 void testInterfaceSubtype() { 41 void testInterfaceSubtype() {
42 asyncTest(() => TypeEnvironment.create(r""" 42 asyncTest(() => TypeEnvironment.create(r"""
43 class A<T> {} 43 class A<T> {}
44 class B<T1, T2> extends A<T1> {} 44 class B<T1, T2> extends A<T1> {}
45 // TODO(johnniwinther): Inheritance with different type arguments is 45 // TODO(johnniwinther): Inheritance with different type arguments is
46 // currently not supported by the implementation. 46 // currently not supported by the implementation.
47 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>>*/ {}
48 """).then((env) { 48 """).then((env) {
49 void expect(bool expectSubtype, DartType T, DartType S, 49 void expect(
50 bool expectSubtype, ResolutionDartType T, ResolutionDartType S,
50 {bool expectMoreSpecific}) { 51 {bool expectMoreSpecific}) {
51 testTypes(env, T, S, expectSubtype, expectMoreSpecific); 52 testTypes(env, T, S, expectSubtype, expectMoreSpecific);
52 } 53 }
53 54
54 ClassElement A = env.getElement('A'); 55 ClassElement A = env.getElement('A');
55 ClassElement B = env.getElement('B'); 56 ClassElement B = env.getElement('B');
56 ClassElement C = env.getElement('C'); 57 ClassElement C = env.getElement('C');
57 DartType Object_ = env['Object']; 58 ResolutionDartType Object_ = env['Object'];
58 DartType num_ = env['num']; 59 ResolutionDartType num_ = env['num'];
59 DartType int_ = env['int']; 60 ResolutionDartType int_ = env['int'];
60 DartType String_ = env['String']; 61 ResolutionDartType String_ = env['String'];
61 DartType dynamic_ = env['dynamic']; 62 ResolutionDartType dynamic_ = env['dynamic'];
62 DartType void_ = env['void']; 63 ResolutionDartType void_ = env['void'];
63 DartType Null_ = env['Null']; 64 ResolutionDartType Null_ = env['Null'];
64 65
65 expect(true, void_, void_); 66 expect(true, void_, void_);
66 expect(true, void_, dynamic_); 67 expect(true, void_, dynamic_);
67 // Unsure about the next one, see dartbug.com/14933. 68 // Unsure about the next one, see dartbug.com/14933.
68 expect(true, dynamic_, void_, expectMoreSpecific: false); 69 expect(true, dynamic_, void_, expectMoreSpecific: false);
69 expect(false, void_, Object_); 70 expect(false, void_, Object_);
70 expect(false, Object_, void_); 71 expect(false, Object_, void_);
71 expect(true, Null_, void_); 72 expect(true, Null_, void_);
72 73
73 expect(true, Object_, Object_); 74 expect(true, Object_, Object_);
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 expect(true, dynamic_, dynamic_); 106 expect(true, dynamic_, dynamic_);
106 expect(true, Null_, dynamic_); 107 expect(true, Null_, dynamic_);
107 108
108 expect(false, Object_, Null_); 109 expect(false, Object_, Null_);
109 expect(false, num_, Null_); 110 expect(false, num_, Null_);
110 expect(false, int_, Null_); 111 expect(false, int_, Null_);
111 expect(false, String_, Null_); 112 expect(false, String_, Null_);
112 expect(true, dynamic_, Null_, expectMoreSpecific: false); 113 expect(true, dynamic_, Null_, expectMoreSpecific: false);
113 expect(true, Null_, Null_); 114 expect(true, Null_, Null_);
114 115
115 DartType A_Object = instantiate(A, [Object_]); 116 ResolutionDartType A_Object = instantiate(A, [Object_]);
116 DartType A_num = instantiate(A, [num_]); 117 ResolutionDartType A_num = instantiate(A, [num_]);
117 DartType A_int = instantiate(A, [int_]); 118 ResolutionDartType A_int = instantiate(A, [int_]);
118 DartType A_String = instantiate(A, [String_]); 119 ResolutionDartType A_String = instantiate(A, [String_]);
119 DartType A_dynamic = instantiate(A, [dynamic_]); 120 ResolutionDartType A_dynamic = instantiate(A, [dynamic_]);
120 DartType A_Null = instantiate(A, [Null_]); 121 ResolutionDartType A_Null = instantiate(A, [Null_]);
121 122
122 expect(true, A_Object, Object_); 123 expect(true, A_Object, Object_);
123 expect(false, A_Object, num_); 124 expect(false, A_Object, num_);
124 expect(false, A_Object, int_); 125 expect(false, A_Object, int_);
125 expect(false, A_Object, String_); 126 expect(false, A_Object, String_);
126 expect(true, A_Object, dynamic_); 127 expect(true, A_Object, dynamic_);
127 expect(false, A_Object, Null_); 128 expect(false, A_Object, Null_);
128 129
129 expect(true, A_Object, A_Object); 130 expect(true, A_Object, A_Object);
130 expect(true, A_num, A_Object); 131 expect(true, A_num, A_Object);
(...skipping 30 matching lines...) Expand all
161 expect(true, A_dynamic, A_dynamic); 162 expect(true, A_dynamic, A_dynamic);
162 expect(true, A_Null, A_dynamic); 163 expect(true, A_Null, A_dynamic);
163 164
164 expect(false, A_Object, A_Null); 165 expect(false, A_Object, A_Null);
165 expect(false, A_num, A_Null); 166 expect(false, A_num, A_Null);
166 expect(false, A_int, A_Null); 167 expect(false, A_int, A_Null);
167 expect(false, A_String, A_Null); 168 expect(false, A_String, A_Null);
168 expect(true, A_dynamic, A_Null, expectMoreSpecific: false); 169 expect(true, A_dynamic, A_Null, expectMoreSpecific: false);
169 expect(true, A_Null, A_Null); 170 expect(true, A_Null, A_Null);
170 171
171 DartType B_Object_Object = instantiate(B, [Object_, Object_]); 172 ResolutionDartType B_Object_Object = instantiate(B, [Object_, Object_]);
172 DartType B_num_num = instantiate(B, [num_, num_]); 173 ResolutionDartType B_num_num = instantiate(B, [num_, num_]);
173 DartType B_int_num = instantiate(B, [int_, num_]); 174 ResolutionDartType B_int_num = instantiate(B, [int_, num_]);
174 DartType B_dynamic_dynamic = instantiate(B, [dynamic_, dynamic_]); 175 ResolutionDartType B_dynamic_dynamic =
175 DartType B_String_dynamic = instantiate(B, [String_, dynamic_]); 176 instantiate(B, [dynamic_, dynamic_]);
177 ResolutionDartType B_String_dynamic =
178 instantiate(B, [String_, dynamic_]);
176 179
177 expect(true, B_Object_Object, Object_); 180 expect(true, B_Object_Object, Object_);
178 expect(true, B_Object_Object, A_Object); 181 expect(true, B_Object_Object, A_Object);
179 expect(false, B_Object_Object, A_num); 182 expect(false, B_Object_Object, A_num);
180 expect(false, B_Object_Object, A_int); 183 expect(false, B_Object_Object, A_int);
181 expect(false, B_Object_Object, A_String); 184 expect(false, B_Object_Object, A_String);
182 expect(true, B_Object_Object, A_dynamic); 185 expect(true, B_Object_Object, A_dynamic);
183 186
184 expect(true, B_num_num, Object_); 187 expect(true, B_num_num, Object_);
185 expect(true, B_num_num, A_Object); 188 expect(true, B_num_num, A_Object);
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 expect(true, B_dynamic_dynamic, B_dynamic_dynamic); 238 expect(true, B_dynamic_dynamic, B_dynamic_dynamic);
236 expect(true, B_String_dynamic, B_dynamic_dynamic); 239 expect(true, B_String_dynamic, B_dynamic_dynamic);
237 240
238 expect(false, B_Object_Object, B_String_dynamic); 241 expect(false, B_Object_Object, B_String_dynamic);
239 expect(false, B_num_num, B_String_dynamic); 242 expect(false, B_num_num, B_String_dynamic);
240 expect(false, B_int_num, B_String_dynamic); 243 expect(false, B_int_num, B_String_dynamic);
241 expect(true, B_dynamic_dynamic, B_String_dynamic, 244 expect(true, B_dynamic_dynamic, B_String_dynamic,
242 expectMoreSpecific: false); 245 expectMoreSpecific: false);
243 expect(true, B_String_dynamic, B_String_dynamic); 246 expect(true, B_String_dynamic, B_String_dynamic);
244 247
245 DartType C_Object_Object = instantiate(C, [Object_, Object_]); 248 ResolutionDartType C_Object_Object = instantiate(C, [Object_, Object_]);
246 DartType C_num_num = instantiate(C, [num_, num_]); 249 ResolutionDartType C_num_num = instantiate(C, [num_, num_]);
247 DartType C_int_String = instantiate(C, [int_, String_]); 250 ResolutionDartType C_int_String = instantiate(C, [int_, String_]);
248 DartType C_dynamic_dynamic = instantiate(C, [dynamic_, dynamic_]); 251 ResolutionDartType C_dynamic_dynamic =
252 instantiate(C, [dynamic_, dynamic_]);
249 253
250 expect(true, C_Object_Object, B_Object_Object); 254 expect(true, C_Object_Object, B_Object_Object);
251 expect(false, C_Object_Object, B_num_num); 255 expect(false, C_Object_Object, B_num_num);
252 expect(false, C_Object_Object, B_int_num); 256 expect(false, C_Object_Object, B_int_num);
253 expect(true, C_Object_Object, B_dynamic_dynamic); 257 expect(true, C_Object_Object, B_dynamic_dynamic);
254 expect(false, C_Object_Object, B_String_dynamic); 258 expect(false, C_Object_Object, B_String_dynamic);
255 259
256 expect(true, C_num_num, B_Object_Object); 260 expect(true, C_num_num, B_Object_Object);
257 expect(true, C_num_num, B_num_num); 261 expect(true, C_num_num, B_num_num);
258 expect(false, C_num_num, B_int_num); 262 expect(false, C_num_num, B_int_num);
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
290 class A { 294 class A {
291 int call(V v, int i); 295 int call(V v, int i);
292 296
293 int m1(U u, int i); 297 int m1(U u, int i);
294 int m2(W w, num n); 298 int m2(W w, num n);
295 U m3(V v, int i); 299 U m3(V v, int i);
296 int m4(V v, U u); 300 int m4(V v, U u);
297 void m5(V v, int i); 301 void m5(V v, int i);
298 } 302 }
299 """).then((env) { 303 """).then((env) {
300 void expect(bool expectSubtype, DartType T, DartType S, 304 void expect(
305 bool expectSubtype, ResolutionDartType T, ResolutionDartType S,
301 {bool expectMoreSpecific}) { 306 {bool expectMoreSpecific}) {
302 testTypes(env, T, S, expectSubtype, expectMoreSpecific); 307 testTypes(env, T, S, expectSubtype, expectMoreSpecific);
303 } 308 }
304 309
305 ClassElement classA = env.getElement('A'); 310 ClassElement classA = env.getElement('A');
306 DartType A = classA.rawType; 311 ResolutionDartType A = classA.rawType;
307 DartType function = env['Function']; 312 ResolutionDartType function = env['Function'];
308 DartType call = env.getMemberType(classA, 'call'); 313 ResolutionDartType call = env.getMemberType(classA, 'call');
309 DartType m1 = env.getMemberType(classA, 'm1'); 314 ResolutionDartType m1 = env.getMemberType(classA, 'm1');
310 DartType m2 = env.getMemberType(classA, 'm2'); 315 ResolutionDartType m2 = env.getMemberType(classA, 'm2');
311 DartType m3 = env.getMemberType(classA, 'm3'); 316 ResolutionDartType m3 = env.getMemberType(classA, 'm3');
312 DartType m4 = env.getMemberType(classA, 'm4'); 317 ResolutionDartType m4 = env.getMemberType(classA, 'm4');
313 DartType m5 = env.getMemberType(classA, 'm5'); 318 ResolutionDartType m5 = env.getMemberType(classA, 'm5');
314 319
315 expect(true, A, function); 320 expect(true, A, function);
316 expect(true, A, call); 321 expect(true, A, call);
317 expect(true, call, m1); 322 expect(true, call, m1);
318 expect(true, A, m1); 323 expect(true, A, m1);
319 expect(true, A, m2, expectMoreSpecific: false); 324 expect(true, A, m2, expectMoreSpecific: false);
320 expect(false, A, m3); 325 expect(false, A, m3);
321 expect(false, A, m4); 326 expect(false, A, m4);
322 expect(true, A, m5); 327 expect(true, A, m5);
323 })); 328 }));
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after
575 class B<T extends Object> {} 580 class B<T extends Object> {}
576 class C<T extends num> {} 581 class C<T extends num> {}
577 class D<T extends int> {} 582 class D<T extends int> {}
578 class E<T extends S, S extends num> {} 583 class E<T extends S, S extends num> {}
579 class F<T extends num, S extends T> {} 584 class F<T extends num, S extends T> {}
580 class G<T extends T> {} 585 class G<T extends T> {}
581 class H<T extends S, S extends T> {} 586 class H<T extends S, S extends T> {}
582 class I<T extends S, S extends U, U extends T> {} 587 class I<T extends S, S extends U, U extends T> {}
583 class J<T extends S, S extends U, U extends S> {} 588 class J<T extends S, S extends U, U extends S> {}
584 """).then((env) { 589 """).then((env) {
585 void expect(bool expectSubtype, DartType T, DartType S, 590 void expect(
591 bool expectSubtype, ResolutionDartType T, ResolutionDartType S,
586 {bool expectMoreSpecific}) { 592 {bool expectMoreSpecific}) {
587 testTypes(env, T, S, expectSubtype, expectMoreSpecific); 593 testTypes(env, T, S, expectSubtype, expectMoreSpecific);
588 } 594 }
589 595
590 ClassElement A = env.getElement('A'); 596 ClassElement A = env.getElement('A');
591 TypeVariableType A_T = A.thisType.typeArguments[0]; 597 ResolutionTypeVariableType A_T = A.thisType.typeArguments[0];
592 ClassElement B = env.getElement('B'); 598 ClassElement B = env.getElement('B');
593 TypeVariableType B_T = B.thisType.typeArguments[0]; 599 ResolutionTypeVariableType B_T = B.thisType.typeArguments[0];
594 ClassElement C = env.getElement('C'); 600 ClassElement C = env.getElement('C');
595 TypeVariableType C_T = C.thisType.typeArguments[0]; 601 ResolutionTypeVariableType C_T = C.thisType.typeArguments[0];
596 ClassElement D = env.getElement('D'); 602 ClassElement D = env.getElement('D');
597 TypeVariableType D_T = D.thisType.typeArguments[0]; 603 ResolutionTypeVariableType D_T = D.thisType.typeArguments[0];
598 ClassElement E = env.getElement('E'); 604 ClassElement E = env.getElement('E');
599 TypeVariableType E_T = E.thisType.typeArguments[0]; 605 ResolutionTypeVariableType E_T = E.thisType.typeArguments[0];
600 TypeVariableType E_S = E.thisType.typeArguments[1]; 606 ResolutionTypeVariableType E_S = E.thisType.typeArguments[1];
601 ClassElement F = env.getElement('F'); 607 ClassElement F = env.getElement('F');
602 TypeVariableType F_T = F.thisType.typeArguments[0]; 608 ResolutionTypeVariableType F_T = F.thisType.typeArguments[0];
603 TypeVariableType F_S = F.thisType.typeArguments[1]; 609 ResolutionTypeVariableType F_S = F.thisType.typeArguments[1];
604 ClassElement G = env.getElement('G'); 610 ClassElement G = env.getElement('G');
605 TypeVariableType G_T = G.thisType.typeArguments[0]; 611 ResolutionTypeVariableType G_T = G.thisType.typeArguments[0];
606 ClassElement H = env.getElement('H'); 612 ClassElement H = env.getElement('H');
607 TypeVariableType H_T = H.thisType.typeArguments[0]; 613 ResolutionTypeVariableType H_T = H.thisType.typeArguments[0];
608 TypeVariableType H_S = H.thisType.typeArguments[1]; 614 ResolutionTypeVariableType H_S = H.thisType.typeArguments[1];
609 ClassElement I = env.getElement('I'); 615 ClassElement I = env.getElement('I');
610 TypeVariableType I_T = I.thisType.typeArguments[0]; 616 ResolutionTypeVariableType I_T = I.thisType.typeArguments[0];
611 TypeVariableType I_S = I.thisType.typeArguments[1]; 617 ResolutionTypeVariableType I_S = I.thisType.typeArguments[1];
612 TypeVariableType I_U = I.thisType.typeArguments[2]; 618 ResolutionTypeVariableType I_U = I.thisType.typeArguments[2];
613 ClassElement J = env.getElement('J'); 619 ClassElement J = env.getElement('J');
614 TypeVariableType J_T = J.thisType.typeArguments[0]; 620 ResolutionTypeVariableType J_T = J.thisType.typeArguments[0];
615 TypeVariableType J_S = J.thisType.typeArguments[1]; 621 ResolutionTypeVariableType J_S = J.thisType.typeArguments[1];
616 TypeVariableType J_U = J.thisType.typeArguments[2]; 622 ResolutionTypeVariableType J_U = J.thisType.typeArguments[2];
617 623
618 DartType Object_ = env['Object']; 624 ResolutionDartType Object_ = env['Object'];
619 DartType num_ = env['num']; 625 ResolutionDartType num_ = env['num'];
620 DartType int_ = env['int']; 626 ResolutionDartType int_ = env['int'];
621 DartType String_ = env['String']; 627 ResolutionDartType String_ = env['String'];
622 DartType dynamic_ = env['dynamic']; 628 ResolutionDartType dynamic_ = env['dynamic'];
623 629
624 // class A<T> {} 630 // class A<T> {}
625 expect(true, A_T, Object_); 631 expect(true, A_T, Object_);
626 expect(false, A_T, num_); 632 expect(false, A_T, num_);
627 expect(false, A_T, int_); 633 expect(false, A_T, int_);
628 expect(false, A_T, String_); 634 expect(false, A_T, String_);
629 expect(true, A_T, dynamic_); 635 expect(true, A_T, dynamic_);
630 expect(true, A_T, A_T); 636 expect(true, A_T, A_T);
631 expect(false, A_T, B_T); 637 expect(false, A_T, B_T);
632 638
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
779 expect(false, J_U, num_); 785 expect(false, J_U, num_);
780 expect(false, J_U, int_); 786 expect(false, J_U, int_);
781 expect(false, J_U, String_); 787 expect(false, J_U, String_);
782 expect(true, J_U, dynamic_); 788 expect(true, J_U, dynamic_);
783 expect(false, J_U, J_T); 789 expect(false, J_U, J_T);
784 expect(true, J_U, J_S); 790 expect(true, J_U, J_S);
785 expect(true, J_U, J_U); 791 expect(true, J_U, J_U);
786 expect(false, J_U, A_T); 792 expect(false, J_U, A_T);
787 })); 793 }));
788 } 794 }
OLDNEW
« no previous file with comments | « tests/compiler/dart2js/serialization/test_helper.dart ('k') | tests/compiler/dart2js/type_checker_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698