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

Side by Side Diff: test/checker/checker_test.dart

Issue 1038583004: Rationalize coercions (Closed) Base URL: https://github.com/dart-lang/dev_compiler.git@master
Patch Set: Rebase Created 5 years, 8 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
« no previous file with comments | « lib/src/options.dart ('k') | test/checker/inferred_type_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, 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 /// General type checking tests 5 /// General type checking tests
6 library dev_compiler.test.checker_test; 6 library dev_compiler.test.checker_test;
7 7
8 import 'package:unittest/unittest.dart'; 8 import 'package:unittest/unittest.dart';
9 9
10 import 'package:dev_compiler/src/testing.dart'; 10 import 'package:dev_compiler/src/testing.dart';
(...skipping 11 matching lines...) Expand all
22 22
23 void baz1(y) => x + y; 23 void baz1(y) => x + y;
24 static baz2(y) => y + y; 24 static baz2(y) => y + y;
25 } 25 }
26 26
27 void foo(String str) { 27 void foo(String str) {
28 print(str); 28 print(str);
29 } 29 }
30 30
31 void bar(a) { 31 void bar(a) {
32 foo(/*info:DownCast,warning:DynamicInvoke*/a.x); 32 foo(/*info:DynamicCast,warning:DynamicInvoke*/a.x);
33 } 33 }
34 34
35 typedef DynFun(x); 35 typedef DynFun(x);
36 typedef StrFun(String x); 36 typedef StrFun(String x);
37 37
38 var bar1 = bar; 38 var bar1 = bar;
39 39
40 void main() { 40 void main() {
41 var a = new A(); 41 var a = new A();
42 bar(a); 42 bar(a);
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 void bar(int w, {int x = /*severe:StaticTypeError*/null, int /*severe:In validVariableDeclaration*/y, int z: 0}) { 85 void bar(int w, {int x = /*severe:StaticTypeError*/null, int /*severe:In validVariableDeclaration*/y, int z: 0}) {
86 } 86 }
87 87
88 void main() { 88 void main() {
89 int /*severe:InvalidVariableDeclaration*/x; 89 int /*severe:InvalidVariableDeclaration*/x;
90 double /*severe:InvalidVariableDeclaration*/y; 90 double /*severe:InvalidVariableDeclaration*/y;
91 num z; 91 num z;
92 bool b; 92 bool b;
93 93
94 // int is non-nullable 94 // int is non-nullable
95 // TODO(vsm): This should be an error, not a warning. 95 x = /*severe:StaticTypeError*/null;
96 x = /*warning:DownCastLiteral*/null;
97 x = 42; 96 x = 42;
98 x = /*info:DownCast*/z; 97 x = /*warning:DownCastImplicit*/z;
99 98
100 // double is non-nullable 99 // double is non-nullable
101 // TODO(vsm): This should be an error, not a warning. 100 y = /*severe:StaticTypeError*/null;
102 y = /*warning:DownCastLiteral*/null;
103 y = /*severe:StaticTypeError*/42; 101 y = /*severe:StaticTypeError*/42;
104 y = 42.0; 102 y = 42.0;
105 y = /*info:DownCast*/z; 103 y = /*warning:DownCastImplicit*/z;
106 104
107 // num is nullable 105 // num is nullable
108 z = null; 106 z = null;
109 z = x; 107 z = x;
110 z = y; 108 z = y;
111 109
112 // bool is nullable 110 // bool is nullable
113 b = null; 111 b = null;
114 b = true; 112 b = true;
115 } 113 }
116 ''' 114 '''
117 }, nonnullableTypes: <String>['int', 'double']); 115 }, nonnullableTypes: <String>['int', 'double']);
118 }); 116 });
119 117
120 test('Primitives and generics', () { 118 test('Primitives and generics', () {
121 testChecker({ 119 testChecker({
122 '/main.dart': ''' 120 '/main.dart': '''
123 class A<T> { 121 class A<T> {
124 // TODO(vsm): This needs a static info indicating a runtime 122 // TODO(vsm): This needs a static info indicating a runtime
125 // check at construction. 123 // check at construction.
126 T x; 124 T x;
127 125
128 // TODO(vsm): Should this be a different type of DownCast? 126 // TODO(vsm): Should this be a different type of DownCast?
129 T foo() => /*warning:DownCastLiteral*/null; 127 T foo() => /*warning:DownCastImplicit*/null;
130 128
131 void bar() { 129 void bar() {
132 int /*severe:InvalidVariableDeclaration*/x; 130 int /*severe:InvalidVariableDeclaration*/x;
133 num y; 131 num y;
134 // TODO(vsm): This should be a runtime check: 132 // TODO(vsm): This should be a runtime check:
135 // Transformed to: T z = cast(null, T) 133 // Transformed to: T z = cast(null, T)
136 T /*severe:InvalidVariableDeclaration*/z; 134 T /*severe:InvalidVariableDeclaration*/z;
137 } 135 }
138 136
139 void baz(T x, [T /*severe:InvalidVariableDeclaration*/y, T z = /*sever e:StaticTypeError*/null]) { 137 void baz(T x, [T /*severe:InvalidVariableDeclaration*/y, T z = /*sever e:StaticTypeError*/null]) {
140 } 138 }
141 } 139 }
142 140
143 class B<T extends List> { 141 class B<T extends List> {
144 T x; 142 T x;
145 143
146 // T cannot be primitive. 144 // T cannot be primitive.
147 T foo() => null; 145 T foo() => null;
148 } 146 }
149 147
150 class C<T extends num> { 148 class C<T extends num> {
151 // TODO(vsm): This needs a static info indicating a runtime 149 // TODO(vsm): This needs a static info indicating a runtime
152 // check at construction. 150 // check at construction.
153 T x; 151 T x;
154 152
155 // TODO(vsm): Should this be a different type of DownCast? 153 // TODO(vsm): Should this be a different type of DownCast?
156 T foo() => /*warning:DownCastLiteral*/null; 154 T foo() => /*warning:DownCastImplicit*/null;
157 } 155 }
158 ''' 156 '''
159 }, nonnullableTypes: <String>['int', 'double']); 157 }, nonnullableTypes: <String>['int', 'double']);
160 }); 158 });
161 159
162 test('Constructors', () { 160 test('Constructors', () {
163 testChecker({ 161 testChecker({
164 '/main.dart': ''' 162 '/main.dart': '''
165 const num z = 25; 163 const num z = 25;
166 Object obj = "world"; 164 Object obj = "world";
167 165
168 class A { 166 class A {
169 int x; 167 int x;
170 String y; 168 String y;
171 169
172 A(this.x) : this.y = /*severe:StaticTypeError*/42; 170 A(this.x) : this.y = /*severe:StaticTypeError*/42;
173 171
174 A.c1(p): this.x = /*info:DownCast*/z, this.y = /*info:DownCast*/p; 172 A.c1(p): this.x = /*warning:DownCastImplicit*/z, this.y = /*info:Dynamic Cast*/p;
175 173
176 A.c2(this.x, this.y); 174 A.c2(this.x, this.y);
177 175
178 A.c3(/*severe:InvalidParameterDeclaration*/num this.x, String this.y); 176 A.c3(/*severe:InvalidParameterDeclaration*/num this.x, String this.y);
179 } 177 }
180 178
181 class B extends A { 179 class B extends A {
182 B() : super(/*severe:StaticTypeError*/"hello"); 180 B() : super(/*severe:StaticTypeError*/"hello");
183 181
184 B.c2(int x, String y) : super.c2(/*severe:StaticTypeError*/y, 182 B.c2(int x, String y) : super.c2(/*severe:StaticTypeError*/y,
185 /*severe:StaticTypeError*/x); 183 /*severe:StaticTypeError*/x);
186 184
187 B.c3(num x, Object y) : super.c3(x, /*info:DownCast*/y); 185 B.c3(num x, Object y) : super.c3(x, /*warning:DownCastImplicit*/y);
188 } 186 }
189 187
190 void main() { 188 void main() {
191 A a = new A.c2(/*info:DownCast*/z, /*severe:StaticTypeError*/z); 189 A a = new A.c2(/*warning:DownCastImplicit*/z, /*severe:StaticTypeError* /z);
192 var b = new B.c2(/*severe:StaticTypeError*/"hello", /*info:DownCast*/ob j); 190 var b = new B.c2(/*severe:StaticTypeError*/"hello", /*warning:DownCastI mplicit*/obj);
193 } 191 }
194 ''' 192 '''
195 }); 193 });
196 }); 194 });
197 195
198 test('Unbound variable', () { 196 test('Unbound variable', () {
199 testChecker({ 197 testChecker({
200 '/main.dart': ''' 198 '/main.dart': '''
201 void main() { 199 void main() {
202 dynamic y = /*pass should be severe:StaticTypeError*/unboundVariable; 200 dynamic y = /*pass should be severe:StaticTypeError*/unboundVariable;
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
250 248
251 void main() { 249 void main() {
252 dynamic y; 250 dynamic y;
253 Object o; 251 Object o;
254 int i = 0; 252 int i = 0;
255 double d = 0.0; 253 double d = 0.0;
256 num n; 254 num n;
257 A a; 255 A a;
258 B b; 256 B b;
259 o = y; 257 o = y;
260 i = /*info:DownCast*/y; 258 i = /*info:DynamicCast*/y;
261 d = /*info:DownCast*/y; 259 d = /*info:DynamicCast*/y;
262 n = /*info:DownCast*/y; 260 n = /*info:DynamicCast*/y;
263 a = /*info:DownCast*/y; 261 a = /*info:DynamicCast*/y;
264 b = /*info:DownCast*/y; 262 b = /*info:DynamicCast*/y;
265 } 263 }
266 ''' 264 '''
267 }); 265 });
268 }); 266 });
269 267
270 test('Ground type subtyping: assigning a class', () { 268 test('Ground type subtyping: assigning a class', () {
271 testChecker({ 269 testChecker({
272 '/main.dart': ''' 270 '/main.dart': '''
273 271
274 class A {} 272 class A {}
275 class B extends A {} 273 class B extends A {}
276 274
277 void main() { 275 void main() {
278 dynamic y; 276 dynamic y;
279 Object o; 277 Object o;
280 int i = 0; 278 int i = 0;
281 double d = 0.0; 279 double d = 0.0;
282 num n; 280 num n;
283 A a; 281 A a;
284 B b; 282 B b;
285 y = a; 283 y = a;
286 o = a; 284 o = a;
287 i = /*severe:StaticTypeError*/a; 285 i = /*severe:StaticTypeError*/a;
288 d = /*severe:StaticTypeError*/a; 286 d = /*severe:StaticTypeError*/a;
289 n = /*severe:StaticTypeError*/a; 287 n = /*severe:StaticTypeError*/a;
290 a = a; 288 a = a;
291 b = /*info:DownCast*/a; 289 b = /*warning:DownCastImplicit*/a;
292 } 290 }
293 ''' 291 '''
294 }); 292 });
295 }); 293 });
296 294
297 test('Ground type subtyping: assigning a subclass', () { 295 test('Ground type subtyping: assigning a subclass', () {
298 testChecker({ 296 testChecker({
299 '/main.dart': ''' 297 '/main.dart': '''
300 298
301 class A {} 299 class A {}
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
338 B left; 336 B left;
339 C right; 337 C right;
340 D bot; 338 D bot;
341 { 339 {
342 top = top; 340 top = top;
343 top = left; 341 top = left;
344 top = right; 342 top = right;
345 top = bot; 343 top = bot;
346 } 344 }
347 { 345 {
348 left = /*info:DownCast*/top; 346 left = /*warning:DownCastImplicit*/top;
349 left = left; 347 left = left;
350 left = /*severe:StaticTypeError*/right; 348 left = /*severe:StaticTypeError*/right;
351 left = bot; 349 left = bot;
352 } 350 }
353 { 351 {
354 right = /*info:DownCast*/top; 352 right = /*warning:DownCastImplicit*/top;
355 right = /*severe:StaticTypeError*/left; 353 right = /*severe:StaticTypeError*/left;
356 right = right; 354 right = right;
357 right = bot; 355 right = bot;
358 } 356 }
359 { 357 {
360 bot = /*info:DownCast*/top; 358 bot = /*warning:DownCastImplicit*/top;
361 bot = /*info:DownCast*/left; 359 bot = /*warning:DownCastImplicit*/left;
362 bot = /*info:DownCast*/right; 360 bot = /*warning:DownCastImplicit*/right;
363 bot = bot; 361 bot = bot;
364 } 362 }
365 } 363 }
366 ''' 364 '''
367 }); 365 });
368 }); 366 });
369 367
370 test('Function typing and subtyping: int and object', () { 368 test('Function typing and subtyping: int and object', () {
371 testChecker({ 369 testChecker({
372 '/main.dart': ''' 370 '/main.dart': '''
373 371
374 typedef Object Top(int x); // Top of the lattice 372 typedef Object Top(int x); // Top of the lattice
375 typedef int Left(int x); // Left branch 373 typedef int Left(int x); // Left branch
376 typedef int Left2(int x); // Left branch 374 typedef int Left2(int x); // Left branch
377 typedef Object Right(Object x); // Right branch 375 typedef Object Right(Object x); // Right branch
378 typedef int Bot(Object x); // Bottom of the lattice 376 typedef int Bot(Object x); // Bottom of the lattice
379 377
380 Object top(int x) => x; 378 Object top(int x) => x;
381 int left(int x) => x; 379 int left(int x) => x;
382 Object right(Object x) => x; 380 Object right(Object x) => x;
383 int _bot(Object x) => /*info:DownCast*/x; 381 int _bot(Object x) => /*warning:DownCastImplicit*/x;
384 int bot(Object x) => x as int; 382 int bot(Object x) => x as int;
385 383
386 void main() { 384 void main() {
387 { // Check typedef equality 385 { // Check typedef equality
388 Left f = left; 386 Left f = left;
389 Left2 g = f; 387 Left2 g = f;
390 } 388 }
391 // TODO(leafp) Decide on ClosureWrap vs DownCast (or error). 389 // TODO(leafp) Decide on ClosureWrap vs DownCast (or error).
392 { 390 {
393 Top f; 391 Top f;
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
429 class A {} 427 class A {}
430 class B extends A {} 428 class B extends A {}
431 429
432 typedef A Top(B x); // Top of the lattice 430 typedef A Top(B x); // Top of the lattice
433 typedef B Left(B x); // Left branch 431 typedef B Left(B x); // Left branch
434 typedef B Left2(B x); // Left branch 432 typedef B Left2(B x); // Left branch
435 typedef A Right(A x); // Right branch 433 typedef A Right(A x); // Right branch
436 typedef B Bot(A x); // Bottom of the lattice 434 typedef B Bot(A x); // Bottom of the lattice
437 435
438 B left(B x) => x; 436 B left(B x) => x;
439 B _bot(A x) => /*info:DownCast*/x; 437 B _bot(A x) => /*warning:DownCastImplicit*/x;
440 B bot(A x) => x as B; 438 B bot(A x) => x as B;
441 A top(B x) => x; 439 A top(B x) => x;
442 A right(A x) => x; 440 A right(A x) => x;
443 441
444 void main() { 442 void main() {
445 { // Check typedef equality 443 { // Check typedef equality
446 Left f = left; 444 Left f = left;
447 Left2 g = f; 445 Left2 g = f;
448 } 446 }
449 { 447 {
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
486 class A {} 484 class A {}
487 485
488 typedef dynamic Top(dynamic x); // Top of the lattice 486 typedef dynamic Top(dynamic x); // Top of the lattice
489 typedef dynamic Left(A x); // Left branch 487 typedef dynamic Left(A x); // Left branch
490 typedef A Right(dynamic x); // Right branch 488 typedef A Right(dynamic x); // Right branch
491 typedef A Bottom(A x); // Bottom of the lattice 489 typedef A Bottom(A x); // Bottom of the lattice
492 490
493 dynamic left(A x) => x; 491 dynamic left(A x) => x;
494 A bot(A x) => x; 492 A bot(A x) => x;
495 dynamic top(dynamic x) => x; 493 dynamic top(dynamic x) => x;
496 A right(dynamic x) => /*info:DownCast*/x; 494 A right(dynamic x) => /*info:DynamicCast*/x;
497 495
498 void main() { 496 void main() {
499 { 497 {
500 Top f; 498 Top f;
501 f = top; 499 f = top;
502 f = left; 500 f = left;
503 f = right; 501 f = right;
504 f = bot; 502 f = bot;
505 } 503 }
506 { 504 {
(...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after
859 } 857 }
860 int i2i(int x) => x; 858 int i2i(int x) => x;
861 num n2n(num x) => x; 859 num n2n(num x) => x;
862 void main() { 860 void main() {
863 { 861 {
864 I2I f; 862 I2I f;
865 f = new A(); 863 f = new A();
866 f = /*severe:StaticTypeError*/new B(); 864 f = /*severe:StaticTypeError*/new B();
867 f = i2i; 865 f = i2i;
868 f = /*warning:ClosureWrap*/n2n; 866 f = /*warning:ClosureWrap*/n2n;
869 f = /*warning:DownCast*/(i2i as Object); 867 f = /*warning:DownCastComposite*/(i2i as Object);
870 f = /*warning:DownCast*/(n2n as Function); 868 f = /*warning:DownCastComposite*/(n2n as Function);
871 } 869 }
872 { 870 {
873 N2N f; 871 N2N f;
874 f = /*severe:StaticTypeError*/new A(); 872 f = /*severe:StaticTypeError*/new A();
875 f = new B(); 873 f = new B();
876 f = /*warning:ClosureWrap*/i2i; 874 f = /*warning:ClosureWrap*/i2i;
877 f = n2n; 875 f = n2n;
878 f = /*warning:DownCast*/(i2i as Object); 876 f = /*warning:DownCastComposite*/(i2i as Object);
879 f = /*warning:DownCast*/(n2n as Function); 877 f = /*warning:DownCastComposite*/(n2n as Function);
880 } 878 }
881 { 879 {
882 A f; 880 A f;
883 f = new A(); 881 f = new A();
884 f = /*severe:StaticTypeError*/new B(); 882 f = /*severe:StaticTypeError*/new B();
885 f = /*severe:StaticTypeError*/i2i; 883 f = /*severe:StaticTypeError*/i2i;
886 f = /*severe:StaticTypeError*/n2n; 884 f = /*severe:StaticTypeError*/n2n;
887 f = /*info:DownCast*/(i2i as Object); 885 f = /*warning:DownCastImplicit*/(i2i as Object);
888 f = /*info:DownCast*/(n2n as Function); 886 f = /*warning:DownCastImplicit*/(n2n as Function);
889 } 887 }
890 { 888 {
891 B f; 889 B f;
892 f = /*severe:StaticTypeError*/new A(); 890 f = /*severe:StaticTypeError*/new A();
893 f = new B(); 891 f = new B();
894 f = /*severe:StaticTypeError*/i2i; 892 f = /*severe:StaticTypeError*/i2i;
895 f = /*severe:StaticTypeError*/n2n; 893 f = /*severe:StaticTypeError*/n2n;
896 f = /*info:DownCast*/(i2i as Object); 894 f = /*warning:DownCastImplicit*/(i2i as Object);
897 f = /*info:DownCast*/(n2n as Function); 895 f = /*warning:DownCastImplicit*/(n2n as Function);
898 } 896 }
899 { 897 {
900 Function f; 898 Function f;
901 f = new A(); 899 f = new A();
902 f = new B(); 900 f = new B();
903 f = i2i; 901 f = i2i;
904 f = n2n; 902 f = n2n;
905 f = /*info:DownCast*/(i2i as Object); 903 f = /*warning:DownCastImplicit*/(i2i as Object);
906 f = (n2n as Function); 904 f = (n2n as Function);
907 } 905 }
908 } 906 }
909 ''' 907 '''
910 }); 908 });
911 }); 909 });
912 910
913 test('Function typing and subtyping: void', () { 911 test('Function typing and subtyping: void', () {
914 testChecker({ 912 testChecker({
915 '/main.dart': ''' 913 '/main.dart': '''
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
997 995
998 // M<S> <: L<S> 996 // M<S> <: L<S>
999 lOfCs = /*severe:StaticTypeError*/mOfAs; 997 lOfCs = /*severe:StaticTypeError*/mOfAs;
1000 lOfCs = /*severe:StaticTypeError*/mOfBs; 998 lOfCs = /*severe:StaticTypeError*/mOfBs;
1001 lOfCs = mOfCs; 999 lOfCs = mOfCs;
1002 1000
1003 // N </: L<C> 1001 // N </: L<C>
1004 lOfCs = /*severe:StaticTypeError*/ns; 1002 lOfCs = /*severe:StaticTypeError*/ns;
1005 1003
1006 // M<T> <: L<S> iff S = dynamic or S=T 1004 // M<T> <: L<S> iff S = dynamic or S=T
1007 mOfAs = /*info:DownCast*/lOfAs; 1005 mOfAs = /*warning:DownCastComposite*/lOfAs;
1008 mOfAs = /*severe:StaticTypeError*/lOfBs; 1006 mOfAs = /*severe:StaticTypeError*/lOfBs;
1009 mOfAs = /*severe:StaticTypeError*/lOfCs; 1007 mOfAs = /*severe:StaticTypeError*/lOfCs;
1010 1008
1011 // M<S> <: M<S> iff S = dynamic or S=T 1009 // M<S> <: M<S> iff S = dynamic or S=T
1012 mOfAs = mOfAs; 1010 mOfAs = mOfAs;
1013 mOfAs = /*severe:StaticTypeError*/mOfBs; 1011 mOfAs = /*severe:StaticTypeError*/mOfBs;
1014 mOfAs = /*severe:StaticTypeError*/mOfCs; 1012 mOfAs = /*severe:StaticTypeError*/mOfCs;
1015 1013
1016 // N <: M<A> 1014 // N <: M<A>
1017 mOfAs = ns; 1015 mOfAs = ns;
1018 1016
1019 // M<T> <: L<S> iff S = dynamic or S=T 1017 // M<T> <: L<S> iff S = dynamic or S=T
1020 mOfBs = /*severe:StaticTypeError*/lOfAs; 1018 mOfBs = /*severe:StaticTypeError*/lOfAs;
1021 mOfBs = /*info:DownCast*/lOfBs; 1019 mOfBs = /*warning:DownCastComposite*/lOfBs;
1022 mOfBs = /*severe:StaticTypeError*/lOfCs; 1020 mOfBs = /*severe:StaticTypeError*/lOfCs;
1023 1021
1024 // M<S> <: M<S> iff S = dynamic or S=T 1022 // M<S> <: M<S> iff S = dynamic or S=T
1025 mOfBs = /*severe:StaticTypeError*/mOfAs; 1023 mOfBs = /*severe:StaticTypeError*/mOfAs;
1026 mOfBs = mOfBs; 1024 mOfBs = mOfBs;
1027 mOfBs = /*severe:StaticTypeError*/mOfCs; 1025 mOfBs = /*severe:StaticTypeError*/mOfCs;
1028 1026
1029 // N </: M<B> 1027 // N </: M<B>
1030 mOfBs = /*severe:StaticTypeError*/ns; 1028 mOfBs = /*severe:StaticTypeError*/ns;
1031 1029
1032 // M<T> <: L<S> iff S = dynamic or S=T 1030 // M<T> <: L<S> iff S = dynamic or S=T
1033 mOfCs = /*severe:StaticTypeError*/lOfAs; 1031 mOfCs = /*severe:StaticTypeError*/lOfAs;
1034 mOfCs = /*severe:StaticTypeError*/lOfBs; 1032 mOfCs = /*severe:StaticTypeError*/lOfBs;
1035 mOfCs = /*info:DownCast*/lOfCs; 1033 mOfCs = /*warning:DownCastComposite*/lOfCs;
1036 1034
1037 // M<S> <: M<S> iff S = dynamic or S=T 1035 // M<S> <: M<S> iff S = dynamic or S=T
1038 mOfCs = /*severe:StaticTypeError*/mOfAs; 1036 mOfCs = /*severe:StaticTypeError*/mOfAs;
1039 mOfCs = /*severe:StaticTypeError*/mOfBs; 1037 mOfCs = /*severe:StaticTypeError*/mOfBs;
1040 mOfCs = mOfCs; 1038 mOfCs = mOfCs;
1041 1039
1042 // N </: L<C> 1040 // N </: L<C>
1043 mOfCs = /*severe:StaticTypeError*/ns; 1041 mOfCs = /*severe:StaticTypeError*/ns;
1044 1042
1045 // Concrete subclass subtyping 1043 // Concrete subclass subtyping
1046 ns = /*info:DownCast*/lOfAs; 1044 ns = /*warning:DownCastImplicit*/lOfAs;
1047 ns = /*severe:StaticTypeError*/lOfBs; 1045 ns = /*severe:StaticTypeError*/lOfBs;
1048 ns = /*severe:StaticTypeError*/lOfCs; 1046 ns = /*severe:StaticTypeError*/lOfCs;
1049 ns = /*info:DownCast*/mOfAs; 1047 ns = /*warning:DownCastImplicit*/mOfAs;
1050 ns = /*severe:StaticTypeError*/mOfBs; 1048 ns = /*severe:StaticTypeError*/mOfBs;
1051 ns = /*severe:StaticTypeError*/mOfCs; 1049 ns = /*severe:StaticTypeError*/mOfCs;
1052 ns = ns; 1050 ns = ns;
1053 } 1051 }
1054 ''' 1052 '''
1055 }, covariantGenerics: false, relaxedCasts: false); 1053 }, covariantGenerics: false, relaxedCasts: false);
1056 }); 1054 });
1057 1055
1058 test('Generic subtyping: covariant raw types', () { 1056 test('Generic subtyping: covariant raw types', () {
1059 testChecker({ 1057 testChecker({
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
1102 lOfDynamics = lOfBs; 1100 lOfDynamics = lOfBs;
1103 lOfDynamics = lOfCs; 1101 lOfDynamics = lOfCs;
1104 lOfDynamics = mRaw; 1102 lOfDynamics = mRaw;
1105 lOfDynamics = mOfDynamics; 1103 lOfDynamics = mOfDynamics;
1106 lOfDynamics = mOfAs; 1104 lOfDynamics = mOfAs;
1107 lOfDynamics = mOfBs; 1105 lOfDynamics = mOfBs;
1108 lOfDynamics = mOfCs; 1106 lOfDynamics = mOfCs;
1109 lOfDynamics = ns; 1107 lOfDynamics = ns;
1110 1108
1111 // L<T> <: L<S> iff S = dynamic or S=T 1109 // L<T> <: L<S> iff S = dynamic or S=T
1112 lOfAs = /*warning:DownCastDynamic*/lRaw; 1110 lOfAs = /*warning:DownCastComposite*/lRaw;
1113 lOfAs = /*warning:DownCastDynamic*/lOfDynamics; 1111 lOfAs = /*warning:DownCastComposite*/lOfDynamics;
1114 1112
1115 // M<dynamic> </:/> L<A> 1113 // M<dynamic> </:/> L<A>
1116 lOfAs = /*severe:StaticTypeError*/mRaw; 1114 lOfAs = /*severe:StaticTypeError*/mRaw;
1117 lOfAs = /*severe:StaticTypeError*/mOfDynamics; 1115 lOfAs = /*severe:StaticTypeError*/mOfDynamics;
1118 1116
1119 // L<T> <: L<S> iff S = dynamic or S=T 1117 // L<T> <: L<S> iff S = dynamic or S=T
1120 lOfBs = /*warning:DownCastDynamic*/lRaw; 1118 lOfBs = /*warning:DownCastComposite*/lRaw;
1121 lOfBs = /*warning:DownCastDynamic*/lOfDynamics; 1119 lOfBs = /*warning:DownCastComposite*/lOfDynamics;
1122 1120
1123 // M<dynamic> </:/> L<B> 1121 // M<dynamic> </:/> L<B>
1124 lOfBs = /*severe:StaticTypeError*/mRaw; 1122 lOfBs = /*severe:StaticTypeError*/mRaw;
1125 lOfBs = /*severe:StaticTypeError*/mOfDynamics; 1123 lOfBs = /*severe:StaticTypeError*/mOfDynamics;
1126 1124
1127 // L<T> <: L<S> iff S = dynamic or S=T 1125 // L<T> <: L<S> iff S = dynamic or S=T
1128 lOfCs = /*warning:DownCastDynamic*/lRaw; 1126 lOfCs = /*warning:DownCastComposite*/lRaw;
1129 lOfCs = /*warning:DownCastDynamic*/lOfDynamics; 1127 lOfCs = /*warning:DownCastComposite*/lOfDynamics;
1130 1128
1131 // M<dynamic> </:/> L<C> 1129 // M<dynamic> </:/> L<C>
1132 lOfCs = /*severe:StaticTypeError*/mRaw; 1130 lOfCs = /*severe:StaticTypeError*/mRaw;
1133 lOfCs = /*severe:StaticTypeError*/mOfDynamics; 1131 lOfCs = /*severe:StaticTypeError*/mOfDynamics;
1134 1132
1135 // Raw type subtyping 1133 // Raw type subtyping
1136 mRaw = /*info:DownCast*/lRaw; 1134 mRaw = /*warning:DownCastImplicit*/lRaw;
1137 mRaw = /*info:DownCast*/lOfDynamics; 1135 mRaw = /*warning:DownCastImplicit*/lOfDynamics;
1138 mRaw = /*severe:StaticTypeError*/lOfAs; 1136 mRaw = /*severe:StaticTypeError*/lOfAs;
1139 mRaw = /*severe:StaticTypeError*/lOfBs; 1137 mRaw = /*severe:StaticTypeError*/lOfBs;
1140 mRaw = /*severe:StaticTypeError*/lOfCs; 1138 mRaw = /*severe:StaticTypeError*/lOfCs;
1141 mRaw = mRaw; 1139 mRaw = mRaw;
1142 mRaw = mOfDynamics; 1140 mRaw = mOfDynamics;
1143 mRaw = mOfAs; 1141 mRaw = mOfAs;
1144 mRaw = mOfBs; 1142 mRaw = mOfBs;
1145 mRaw = mOfCs; 1143 mRaw = mOfCs;
1146 mRaw = ns; 1144 mRaw = ns;
1147 1145
1148 // M<dynamic> == M 1146 // M<dynamic> == M
1149 mOfDynamics = /*info:DownCast*/lRaw; 1147 mOfDynamics = /*warning:DownCastImplicit*/lRaw;
1150 mOfDynamics = /*info:DownCast*/lOfDynamics; 1148 mOfDynamics = /*warning:DownCastImplicit*/lOfDynamics;
1151 mOfDynamics = /*severe:StaticTypeError*/lOfAs; 1149 mOfDynamics = /*severe:StaticTypeError*/lOfAs;
1152 mOfDynamics = /*severe:StaticTypeError*/lOfBs; 1150 mOfDynamics = /*severe:StaticTypeError*/lOfBs;
1153 mOfDynamics = /*severe:StaticTypeError*/lOfCs; 1151 mOfDynamics = /*severe:StaticTypeError*/lOfCs;
1154 mOfDynamics = mRaw; 1152 mOfDynamics = mRaw;
1155 mOfDynamics = mOfDynamics; 1153 mOfDynamics = mOfDynamics;
1156 mOfDynamics = mOfAs; 1154 mOfDynamics = mOfAs;
1157 mOfDynamics = mOfBs; 1155 mOfDynamics = mOfBs;
1158 mOfDynamics = mOfCs; 1156 mOfDynamics = mOfCs;
1159 mOfDynamics = ns; 1157 mOfDynamics = ns;
1160 1158
1161 // M<T> <: L<S> iff S = dynamic or S=T 1159 // M<T> <: L<S> iff S = dynamic or S=T
1162 mOfAs = /*info:DownCast*/lRaw; 1160 mOfAs = /*warning:DownCastComposite*/lRaw;
1163 mOfAs = /*info:DownCast*/lOfDynamics; 1161 mOfAs = /*warning:DownCastComposite*/lOfDynamics;
1164 1162
1165 // M<dynamic> </:/> M<A> 1163 // M<dynamic> </:/> M<A>
1166 mOfAs = /*warning:DownCastDynamic*/mRaw; 1164 mOfAs = /*warning:DownCastComposite*/mRaw;
1167 mOfAs = /*warning:DownCastDynamic*/mOfDynamics; 1165 mOfAs = /*warning:DownCastComposite*/mOfDynamics;
1168 1166
1169 // M<T> <: L<S> iff S = dynamic or S=T 1167 // M<T> <: L<S> iff S = dynamic or S=T
1170 mOfBs = /*info:DownCast*/lRaw; 1168 mOfBs = /*warning:DownCastComposite*/lRaw;
1171 mOfBs = /*info:DownCast*/lOfDynamics; 1169 mOfBs = /*warning:DownCastComposite*/lOfDynamics;
1172 1170
1173 // M<dynamic> </:/> M<B> 1171 // M<dynamic> </:/> M<B>
1174 mOfBs = /*warning:DownCastDynamic*/mRaw; 1172 mOfBs = /*warning:DownCastComposite*/mRaw;
1175 mOfBs = /*warning:DownCastDynamic*/mOfDynamics; 1173 mOfBs = /*warning:DownCastComposite*/mOfDynamics;
1176 1174
1177 // M<T> <: L<S> iff S = dynamic or S=T 1175 // M<T> <: L<S> iff S = dynamic or S=T
1178 mOfCs = /*info:DownCast*/lRaw; 1176 mOfCs = /*warning:DownCastComposite*/lRaw;
1179 mOfCs = /*info:DownCast*/lOfDynamics; 1177 mOfCs = /*warning:DownCastComposite*/lOfDynamics;
1180 1178
1181 // M<dynamic> </:/> M<C> 1179 // M<dynamic> </:/> M<C>
1182 mOfCs = /*warning:DownCastDynamic*/mRaw; 1180 mOfCs = /*warning:DownCastComposite*/mRaw;
1183 mOfCs = /*warning:DownCastDynamic*/mOfDynamics; 1181 mOfCs = /*warning:DownCastComposite*/mOfDynamics;
1184 1182
1185 // Concrete subclass subtyping 1183 // Concrete subclass subtyping
1186 ns = /*info:DownCast*/lRaw; 1184 ns = /*warning:DownCastImplicit*/lRaw;
1187 ns = /*info:DownCast*/lOfDynamics; 1185 ns = /*warning:DownCastImplicit*/lOfDynamics;
1188 ns = /*info:DownCast*/mRaw; 1186 ns = /*warning:DownCastImplicit*/mRaw;
1189 ns = /*info:DownCast*/mOfDynamics; 1187 ns = /*warning:DownCastImplicit*/mOfDynamics;
1190 } 1188 }
1191 ''' 1189 '''
1192 }, covariantGenerics: false, relaxedCasts: false); 1190 }, covariantGenerics: false, relaxedCasts: false);
1193 }); 1191 });
1194 1192
1195 test('Generic subtyping: covariant raw types with multiple parameters', () { 1193 test('Generic subtyping: covariant raw types with multiple parameters', () {
1196 testChecker({ 1194 testChecker({
1197 '/main.dart': ''' 1195 '/main.dart': '''
1198 1196
1199 class A {} 1197 class A {}
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
1241 // L<dynamic, dynamic> 1239 // L<dynamic, dynamic>
1242 lOfDD = lRaw; 1240 lOfDD = lRaw;
1243 lOfDD = lOfD_; 1241 lOfDD = lOfD_;
1244 lOfDD = lOfA_; 1242 lOfDD = lOfA_;
1245 lOfDD = lOfDA; 1243 lOfDD = lOfDA;
1246 lOfDD = lOfAD; 1244 lOfDD = lOfAD;
1247 lOfDD = lOfDD; 1245 lOfDD = lOfDD;
1248 lOfDD = lOfAA; 1246 lOfDD = lOfAA;
1249 1247
1250 // L<dynamic, A> 1248 // L<dynamic, A>
1251 lOfDA = /*warning:DownCastDynamic*/lRaw; 1249 lOfDA = /*warning:DownCastComposite*/lRaw;
1252 lOfDA = /*warning:DownCastDynamic*/lOfD_; 1250 lOfDA = /*warning:DownCastComposite*/lOfD_;
1253 lOfDA = /*warning:DownCastDynamic*/lOfA_; 1251 lOfDA = /*warning:DownCastComposite*/lOfA_;
1254 lOfDA = lOfDA; 1252 lOfDA = lOfDA;
1255 lOfDA = /*severe:StaticTypeError*/lOfAD; 1253 lOfDA = /*severe:StaticTypeError*/lOfAD;
1256 lOfDA = /*warning:DownCastDynamic*/lOfDD; 1254 lOfDA = /*warning:DownCastComposite*/lOfDD;
1257 lOfDA = lOfAA; 1255 lOfDA = lOfAA;
1258 1256
1259 // L<A, dynamic> 1257 // L<A, dynamic>
1260 lOfAD = /*warning:DownCastDynamic*/lRaw; 1258 lOfAD = /*warning:DownCastComposite*/lRaw;
1261 lOfAD = /*warning:DownCastDynamic*/lOfD_; 1259 lOfAD = /*warning:DownCastComposite*/lOfD_;
1262 lOfAD = /*warning:DownCastDynamic*/lOfA_; 1260 lOfAD = /*warning:DownCastComposite*/lOfA_;
1263 lOfAD = /*severe:StaticTypeError*/lOfDA; 1261 lOfAD = /*severe:StaticTypeError*/lOfDA;
1264 lOfAD = lOfAD; 1262 lOfAD = lOfAD;
1265 lOfAD = /*warning:DownCastDynamic*/lOfDD; 1263 lOfAD = /*warning:DownCastComposite*/lOfDD;
1266 lOfAD = lOfAA; 1264 lOfAD = lOfAA;
1267 1265
1268 // L<A> == L<dynamic, dynamic> 1266 // L<A> == L<dynamic, dynamic>
1269 lOfA_ = lRaw; 1267 lOfA_ = lRaw;
1270 lOfA_ = lOfD_; 1268 lOfA_ = lOfD_;
1271 lOfA_ = lOfA_; 1269 lOfA_ = lOfA_;
1272 lOfA_ = lOfDA; 1270 lOfA_ = lOfDA;
1273 lOfA_ = lOfAD; 1271 lOfA_ = lOfAD;
1274 lOfA_ = lOfDD; 1272 lOfA_ = lOfDD;
1275 lOfA_ = lOfAA; 1273 lOfA_ = lOfAA;
1276 1274
1277 // L<A, A> 1275 // L<A, A>
1278 lOfAA = /*warning:DownCastDynamic*/lRaw; 1276 lOfAA = /*warning:DownCastComposite*/lRaw;
1279 lOfAA = /*warning:DownCastDynamic*/lOfD_; 1277 lOfAA = /*warning:DownCastComposite*/lOfD_;
1280 lOfAA = /*warning:DownCastDynamic*/lOfA_; 1278 lOfAA = /*warning:DownCastComposite*/lOfA_;
1281 lOfAA = /*warning:DownCastDynamic*/lOfDA; 1279 lOfAA = /*warning:DownCastComposite*/lOfDA;
1282 lOfAA = /*warning:DownCastDynamic*/lOfAD; 1280 lOfAA = /*warning:DownCastComposite*/lOfAD;
1283 lOfAA = /*warning:DownCastDynamic*/lOfDD; 1281 lOfAA = /*warning:DownCastComposite*/lOfDD;
1284 lOfAA = lOfAA; 1282 lOfAA = lOfAA;
1285 } 1283 }
1286 ''' 1284 '''
1287 }, covariantGenerics: false, relaxedCasts: false); 1285 }, covariantGenerics: false, relaxedCasts: false);
1288 }); 1286 });
1289 1287
1290 test('Covariant generic subtyping: invariance', () { 1288 test('Covariant generic subtyping: invariance', () {
1291 testChecker({ 1289 testChecker({
1292 '/main.dart': ''' 1290 '/main.dart': '''
1293 1291
(...skipping 23 matching lines...) Expand all
1317 1315
1318 // M<T> <: L<S> iff T <: S 1316 // M<T> <: L<S> iff T <: S
1319 lOfAs = mOfAs; 1317 lOfAs = mOfAs;
1320 lOfAs = mOfBs; 1318 lOfAs = mOfBs;
1321 lOfAs = mOfCs; 1319 lOfAs = mOfCs;
1322 1320
1323 // N <: L<A> 1321 // N <: L<A>
1324 lOfAs = ns; 1322 lOfAs = ns;
1325 1323
1326 // L<T> <: L<S> iff S <: T 1324 // L<T> <: L<S> iff S <: T
1327 lOfBs = /*info:DownCast*/lOfAs; 1325 lOfBs = /*warning:DownCastComposite*/lOfAs;
1328 lOfBs = lOfBs; 1326 lOfBs = lOfBs;
1329 lOfBs = /*severe:StaticTypeError*/lOfCs; 1327 lOfBs = /*severe:StaticTypeError*/lOfCs;
1330 1328
1331 // M<T> <: L<S> iff T <: S 1329 // M<T> <: L<S> iff T <: S
1332 lOfBs = /*severe:StaticTypeError*/mOfAs; 1330 lOfBs = /*severe:StaticTypeError*/mOfAs;
1333 lOfBs = mOfBs; 1331 lOfBs = mOfBs;
1334 lOfBs = /*severe:StaticTypeError*/mOfCs; 1332 lOfBs = /*severe:StaticTypeError*/mOfCs;
1335 1333
1336 // N </: L<B> 1334 // N </: L<B>
1337 lOfBs = /*severe:StaticTypeError*/ns; 1335 lOfBs = /*severe:StaticTypeError*/ns;
1338 1336
1339 // L<T> <: L<S> iff S <: T 1337 // L<T> <: L<S> iff S <: T
1340 lOfCs = /*info:DownCast*/lOfAs; 1338 lOfCs = /*warning:DownCastComposite*/lOfAs;
1341 lOfCs = /*severe:StaticTypeError*/lOfBs; 1339 lOfCs = /*severe:StaticTypeError*/lOfBs;
1342 lOfCs = lOfCs; 1340 lOfCs = lOfCs;
1343 1341
1344 // M<T> <: L<S> iff T <: S 1342 // M<T> <: L<S> iff T <: S
1345 lOfCs = /*severe:StaticTypeError*/mOfAs; 1343 lOfCs = /*severe:StaticTypeError*/mOfAs;
1346 lOfCs = /*severe:StaticTypeError*/mOfBs; 1344 lOfCs = /*severe:StaticTypeError*/mOfBs;
1347 lOfCs = mOfCs; 1345 lOfCs = mOfCs;
1348 1346
1349 // N </: L<C> 1347 // N </: L<C>
1350 lOfCs = /*severe:StaticTypeError*/ns; 1348 lOfCs = /*severe:StaticTypeError*/ns;
1351 1349
1352 // M<T> <: L<S> iff T <: S 1350 // M<T> <: L<S> iff T <: S
1353 mOfAs = /*info:DownCast*/lOfAs; 1351 mOfAs = /*warning:DownCastComposite*/lOfAs;
1354 mOfAs = /*severe:StaticTypeError*/lOfBs; 1352 mOfAs = /*severe:StaticTypeError*/lOfBs;
1355 mOfAs = /*severe:StaticTypeError*/lOfCs; 1353 mOfAs = /*severe:StaticTypeError*/lOfCs;
1356 1354
1357 // M<T> <: M<S> iff T <: S 1355 // M<T> <: M<S> iff T <: S
1358 mOfAs = mOfAs; 1356 mOfAs = mOfAs;
1359 mOfAs = mOfBs; 1357 mOfAs = mOfBs;
1360 mOfAs = mOfCs; 1358 mOfAs = mOfCs;
1361 1359
1362 // N <: M<A> 1360 // N <: M<A>
1363 mOfAs = ns; 1361 mOfAs = ns;
1364 1362
1365 // M<T> <: L<S> iff T <: S 1363 // M<T> <: L<S> iff T <: S
1366 mOfBs = /*info:DownCast*/lOfAs; 1364 mOfBs = /*warning:DownCastComposite*/lOfAs;
1367 mOfBs = /*info:DownCast*/lOfBs; 1365 mOfBs = /*warning:DownCastComposite*/lOfBs;
1368 mOfBs = /*severe:StaticTypeError*/lOfCs; 1366 mOfBs = /*severe:StaticTypeError*/lOfCs;
1369 1367
1370 // M<T> <: M<S> iff T <: S 1368 // M<T> <: M<S> iff T <: S
1371 mOfBs = /*info:DownCast*/mOfAs; 1369 mOfBs = /*warning:DownCastComposite*/mOfAs;
1372 mOfBs = mOfBs; 1370 mOfBs = mOfBs;
1373 mOfBs = /*severe:StaticTypeError*/mOfCs; 1371 mOfBs = /*severe:StaticTypeError*/mOfCs;
1374 1372
1375 // N </: M<B> 1373 // N </: M<B>
1376 mOfBs = /*severe:StaticTypeError*/ns; 1374 mOfBs = /*severe:StaticTypeError*/ns;
1377 1375
1378 // M<T> <: L<S> iff T <: S 1376 // M<T> <: L<S> iff T <: S
1379 mOfCs = /*info:DownCast*/lOfAs; 1377 mOfCs = /*warning:DownCastComposite*/lOfAs;
1380 mOfCs = /*severe:StaticTypeError*/lOfBs; 1378 mOfCs = /*severe:StaticTypeError*/lOfBs;
1381 mOfCs = /*info:DownCast*/lOfCs; 1379 mOfCs = /*warning:DownCastComposite*/lOfCs;
1382 1380
1383 // M<T> <: M<S> iff T :< S 1381 // M<T> <: M<S> iff T :< S
1384 mOfCs = /*info:DownCast*/mOfAs; 1382 mOfCs = /*warning:DownCastComposite*/mOfAs;
1385 mOfCs = /*severe:StaticTypeError*/mOfBs; 1383 mOfCs = /*severe:StaticTypeError*/mOfBs;
1386 mOfCs = mOfCs; 1384 mOfCs = mOfCs;
1387 1385
1388 // N </: L<C> 1386 // N </: L<C>
1389 mOfCs = /*severe:StaticTypeError*/ns; 1387 mOfCs = /*severe:StaticTypeError*/ns;
1390 1388
1391 // Concrete subclass subtyping 1389 // Concrete subclass subtyping
1392 ns = /*info:DownCast*/lOfAs; 1390 ns = /*warning:DownCastImplicit*/lOfAs;
1393 ns = /*severe:StaticTypeError*/lOfBs; 1391 ns = /*severe:StaticTypeError*/lOfBs;
1394 ns = /*severe:StaticTypeError*/lOfCs; 1392 ns = /*severe:StaticTypeError*/lOfCs;
1395 ns = /*info:DownCast*/mOfAs; 1393 ns = /*warning:DownCastImplicit*/mOfAs;
1396 ns = /*severe:StaticTypeError*/mOfBs; 1394 ns = /*severe:StaticTypeError*/mOfBs;
1397 ns = /*severe:StaticTypeError*/mOfCs; 1395 ns = /*severe:StaticTypeError*/mOfCs;
1398 ns = ns; 1396 ns = ns;
1399 } 1397 }
1400 ''' 1398 '''
1401 }, covariantGenerics: true, relaxedCasts: false); 1399 }, covariantGenerics: true, relaxedCasts: false);
1402 }); 1400 });
1403 1401
1404 test('Relaxed casts', () { 1402 test('Relaxed casts', () {
1405 testChecker({ 1403 testChecker({
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
1437 } 1435 }
1438 { 1436 {
1439 lOfOs = mOfDs; 1437 lOfOs = mOfDs;
1440 lOfOs = mOfOs; 1438 lOfOs = mOfOs;
1441 lOfOs = mOfAs; 1439 lOfOs = mOfAs;
1442 lOfOs = lOfDs; 1440 lOfOs = lOfDs;
1443 lOfOs = lOfOs; 1441 lOfOs = lOfOs;
1444 lOfOs = lOfAs; 1442 lOfOs = lOfAs;
1445 } 1443 }
1446 { 1444 {
1447 lOfAs = /*warning:DownCastDynamic*/mOfDs; 1445 lOfAs = /*warning:DownCastComposite*/mOfDs;
1448 lOfAs = /*severe:StaticTypeError*/mOfOs; 1446 lOfAs = /*severe:StaticTypeError*/mOfOs;
1449 lOfAs = mOfAs; 1447 lOfAs = mOfAs;
1450 lOfAs = /*warning:DownCastDynamic*/lOfDs; 1448 lOfAs = /*warning:DownCastComposite*/lOfDs;
1451 lOfAs = /*info:DownCast*/lOfOs; 1449 lOfAs = /*warning:DownCastComposite*/lOfOs;
1452 lOfAs = lOfAs; 1450 lOfAs = lOfAs;
1453 } 1451 }
1454 { 1452 {
1455 mOfDs = mOfDs; 1453 mOfDs = mOfDs;
1456 mOfDs = mOfOs; 1454 mOfDs = mOfOs;
1457 mOfDs = mOfAs; 1455 mOfDs = mOfAs;
1458 mOfDs = /*info:DownCast*/lOfDs; 1456 mOfDs = /*warning:DownCastImplicit*/lOfDs;
1459 mOfDs = /*info:DownCast*/lOfOs; 1457 mOfDs = /*warning:DownCastImplicit*/lOfOs;
1460 mOfDs = /*info:DownCast*/lOfAs; 1458 mOfDs = /*warning:DownCastImplicit*/lOfAs;
1461 } 1459 }
1462 { 1460 {
1463 mOfOs = mOfDs; 1461 mOfOs = mOfDs;
1464 mOfOs = mOfOs; 1462 mOfOs = mOfOs;
1465 mOfOs = mOfAs; 1463 mOfOs = mOfAs;
1466 mOfOs = /*info:DownCast*/lOfDs; 1464 mOfOs = /*warning:DownCastImplicit*/lOfDs;
1467 mOfOs = /*info:DownCast*/lOfOs; 1465 mOfOs = /*warning:DownCastImplicit*/lOfOs;
1468 mOfOs = /*severe:StaticTypeError*/lOfAs; 1466 mOfOs = /*severe:StaticTypeError*/lOfAs;
1469 } 1467 }
1470 { 1468 {
1471 mOfAs = /*warning:DownCastDynamic*/mOfDs; 1469 mOfAs = /*warning:DownCastComposite*/mOfDs;
1472 mOfAs = /*info:DownCast*/mOfOs; 1470 mOfAs = /*warning:DownCastComposite*/mOfOs;
1473 mOfAs = mOfAs; 1471 mOfAs = mOfAs;
1474 mOfAs = /*info:DownCast*/lOfDs; 1472 mOfAs = /*warning:DownCastComposite*/lOfDs;
1475 mOfAs = /*info:DownCast*/lOfOs; 1473 mOfAs = /*warning:DownCastComposite*/lOfOs;
1476 mOfAs = /*info:DownCast*/lOfAs; 1474 mOfAs = /*warning:DownCastComposite*/lOfAs;
1477 } 1475 }
1478 1476
1479 } 1477 }
1480 ''' 1478 '''
1481 }, covariantGenerics: true, relaxedCasts: true); 1479 }, covariantGenerics: true, relaxedCasts: true);
1482 }); 1480 });
1483 1481
1484 test('Subtyping literals', () { 1482 test('Subtyping literals', () {
1485 testChecker({ 1483 testChecker({
1486 '/main.dart': ''' 1484 '/main.dart': '''
1487 test() { 1485 test() {
1488 Iterable i1 = [1, 2, 3]; 1486 Iterable i1 = [1, 2, 3];
1489 i1 = <int>[1, 2, 3]; 1487 i1 = <int>[1, 2, 3];
1490 1488
1491 List l1 = [1, 2, 3]; 1489 List l1 = [1, 2, 3];
1492 l1 = <int>[1, 2, 3]; 1490 l1 = <int>[1, 2, 3];
1493 1491
1494 Iterable<int> i2 = /*warning:DownCastLiteral*/[1, 2, 3]; 1492 Iterable<int> i2 = /*warning:InferableLiteral*/[1, 2, 3];
1495 i2 = /*warning:DownCastDynamic*/i1; 1493 i2 = /*warning:DownCastComposite*/i1;
1496 i2 = /*warning:DownCastDynamic*/l1; 1494 i2 = /*warning:DownCastComposite*/l1;
1497 i2 = <int>[1, 2, 3]; 1495 i2 = <int>[1, 2, 3];
1498 1496
1499 List<int> l2 = /*warning:DownCastLiteral*/[1, 2, 3]; 1497 List<int> l2 = /*warning:InferableLiteral*/[1, 2, 3];
1500 l2 = /*info:DownCast*/i1; 1498 l2 = /*warning:DownCastComposite*/i1;
1501 l2 = /*warning:DownCastDynamic*/l1; 1499 l2 = /*warning:DownCastComposite*/l1;
1502 1500
1503 l2 = /*warning:DownCastExact*/new List(); 1501 l2 = /*warning:InferableAllocation*/new List();
1504 l2 = /*warning:DownCastExact*/new List(10); 1502 l2 = /*warning:InferableAllocation*/new List(10);
1505 l2 = /*warning:DownCastExact*/new List.filled(10, 42); 1503 l2 = /*warning:InferableAllocation*/new List.filled(10, 42);
1506 } 1504 }
1507 ''' 1505 '''
1508 }); 1506 });
1509 }); 1507 });
1510 1508
1511 test('Type checking literals', () { 1509 test('Type checking literals', () {
1512 testChecker({ 1510 testChecker({
1513 '/main.dart': ''' 1511 '/main.dart': '''
1514 test() { 1512 test() {
1515 num n = 3; 1513 num n = 3;
1516 int i = 3; 1514 int i = 3;
1517 String s = "hello"; 1515 String s = "hello";
1518 { 1516 {
1519 List<int> l = <int>[i]; 1517 List<int> l = <int>[i];
1520 l = <int>[/*severe:StaticTypeError*/s]; 1518 l = <int>[/*severe:StaticTypeError*/s];
1521 l = <int>[/*info:DownCast*/n]; 1519 l = <int>[/*warning:DownCastImplicit*/n];
1522 l = <int>[i, /*info:DownCast*/n, /*severe:StaticTypeError*/s]; 1520 l = <int>[i, /*warning:DownCastImplicit*/n, /*severe:StaticTypeEr ror*/s];
1523 } 1521 }
1524 { 1522 {
1525 List l = [i]; 1523 List l = [i];
1526 l = [s]; 1524 l = [s];
1527 l = [n]; 1525 l = [n];
1528 l = [i, n, s]; 1526 l = [i, n, s];
1529 } 1527 }
1530 { 1528 {
1531 Map<String, int> m = <String, int>{s: i}; 1529 Map<String, int> m = <String, int>{s: i};
1532 m = <String, int>{s: /*severe:StaticTypeError*/s}; 1530 m = <String, int>{s: /*severe:StaticTypeError*/s};
1533 m = <String, int>{s: /*info:DownCast*/n}; 1531 m = <String, int>{s: /*warning:DownCastImplicit*/n};
1534 m = <String, int>{s: i, 1532 m = <String, int>{s: i,
1535 s: /*info:DownCast*/n, 1533 s: /*warning:DownCastImplicit*/n,
1536 s: /*severe:StaticTypeError*/s}; 1534 s: /*severe:StaticTypeError*/s};
1537 } 1535 }
1538 // TODO(leafp): We can't currently test for key errors since the 1536 // TODO(leafp): We can't currently test for key errors since the
1539 // error marker binds to the entire entry. 1537 // error marker binds to the entire entry.
1540 { 1538 {
1541 Map m = {s: i}; 1539 Map m = {s: i};
1542 m = {s: s}; 1540 m = {s: s};
1543 m = {s: n}; 1541 m = {s: n};
1544 m = {s: i, 1542 m = {s: i,
1545 s: n, 1543 s: n,
1546 s: s}; 1544 s: s};
1547 m = {i: s, 1545 m = {i: s,
1548 n: s, 1546 n: s,
1549 s: s}; 1547 s: s};
1550 } 1548 }
1551 } 1549 }
1552 ''' 1550 '''
1553 }); 1551 });
1554 }); 1552 });
1555 1553
1556 test('casts in constant contexts', () { 1554 test('casts in constant contexts', () {
1557 String mk(String error) => ''' 1555 String mk(String error1, String error2) => '''
1558 class A { 1556 class A {
1559 static const num n = 3.0; 1557 static const num n = 3.0;
1560 static const int i = /*$error*/n; 1558 static const int i = /*$error2*/n;
1561 final int fi; 1559 final int fi;
1562 const A(num a) : this.fi = /*$error*/a; 1560 const A(num a) : this.fi = /*$error1*/a;
1563 } 1561 }
1564 class B extends A { 1562 class B extends A {
1565 const B(Object a) : super(/*$error*/a); 1563 const B(Object a) : super(/*$error1*/a);
1566 } 1564 }
1567 void foo(Object o) { 1565 void foo(Object o) {
1568 var a = const A(/*$error*/o); 1566 var a = const A(/*$error1*/o);
1569 } 1567 }
1570 '''; 1568 ''';
1571 testChecker({'/main.dart': mk("severe:StaticTypeError")}, 1569 testChecker(
1570 {'/main.dart': mk("severe:StaticTypeError", "severe:StaticTypeError")},
1572 allowConstCasts: false); 1571 allowConstCasts: false);
1573 testChecker({'/main.dart': mk("info:DownCast")}, allowConstCasts: true); 1572 testChecker(
1573 {'/main.dart': mk("warning:DownCastImplicit", "info:AssignmentCast")},
1574 allowConstCasts: true);
1574 }); 1575 });
1575 1576
1576 test('casts in conditionals', () { 1577 test('casts in conditionals', () {
1577 testChecker({ 1578 testChecker({
1578 '/main.dart': ''' 1579 '/main.dart': '''
1579 main() { 1580 main() {
1580 bool b = true; 1581 bool b = true;
1581 num x = b ? 1 : 2.3; 1582 num x = b ? 1 : 2.3;
1582 int y = /*info:DownCast*/b ? 1 : 2.3; 1583 int y = /*info:AssignmentCast*/b ? 1 : 2.3;
1583 String z = !b ? "hello" : null; 1584 String z = !b ? "hello" : null;
1584 z = b ? null : "hello"; 1585 z = b ? null : "hello";
1585 } 1586 }
1586 ''' 1587 '''
1587 }); 1588 });
1588 }); 1589 });
1589 1590
1590 test('redirecting constructor', () { 1591 test('redirecting constructor', () {
1591 testChecker({ 1592 testChecker({
1592 '/main.dart': ''' 1593 '/main.dart': '''
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after
1832 A operator -(B b) {} 1833 A operator -(B b) {}
1833 } 1834 }
1834 1835
1835 foo() => new A(); 1836 foo() => new A();
1836 1837
1837 test() { 1838 test() {
1838 A a = new A(); 1839 A a = new A();
1839 B b = new B(); 1840 B b = new B();
1840 var c = foo(); 1841 var c = foo();
1841 a = a * b; 1842 a = a * b;
1842 a = a * /*pass should be info:DownCast*/c; 1843 a = a * /*pass should be warning:DownCastImplicit*/c;
1843 a = a / b; 1844 a = a / b;
1844 a = a ~/ b; 1845 a = a ~/ b;
1845 a = a % b; 1846 a = a % b;
1846 a = a + b; 1847 a = a + b;
1847 a = a + /*pass should be severe:StaticTypeError*/a; 1848 a = a + /*pass should be severe:StaticTypeError*/a;
1848 a = a - b; 1849 a = a - b;
1849 b = /*severe:StaticTypeError*/b - b; 1850 b = /*severe:StaticTypeError*/b - b;
1850 a = a << b; 1851 a = a << b;
1851 a = a >> b; 1852 a = a >> b;
1852 a = a & b; 1853 a = a & b;
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
1887 (/*severe:StaticTypeError*/x += 3.14); 1888 (/*severe:StaticTypeError*/x += 3.14);
1888 1889
1889 double y = 0.0; 1890 double y = 0.0;
1890 y += 5; 1891 y += 5;
1891 y += 3.14; 1892 y += 3.14;
1892 1893
1893 num z = 0; 1894 num z = 0;
1894 z += 5; 1895 z += 5;
1895 z += 3.14; 1896 z += 3.14;
1896 1897
1897 x = /*info:DownCast*/x + z; 1898 x = /*warning:DownCastImplicit*/x + z;
1898 x += /*info:DownCast*/z; 1899 x += /*warning:DownCastImplicit*/z;
1899 y = /*info:DownCast*/y + z; 1900 y = /*warning:DownCastImplicit*/y + z;
1900 y += /*info:DownCast*/z; 1901 y += /*warning:DownCastImplicit*/z;
1901 1902
1902 dynamic w = 42; 1903 dynamic w = 42;
1903 x += /*info:DownCast*/w; 1904 x += /*info:DynamicCast*/w;
1904 y += /*info:DownCast*/w; 1905 y += /*info:DynamicCast*/w;
1905 z += /*info:DownCast*/w; 1906 z += /*info:DynamicCast*/w;
1906 1907
1907 A a = new A(); 1908 A a = new A();
1908 B b = new B(); 1909 B b = new B();
1909 var c = foo(); 1910 var c = foo();
1910 a = a * b; 1911 a = a * b;
1911 a *= b; 1912 a *= b;
1912 a *= /*info:DownCast*/c; 1913 a *= /*info:DynamicCast*/c;
1913 a /= b; 1914 a /= b;
1914 a ~/= b; 1915 a ~/= b;
1915 a %= b; 1916 a %= b;
1916 a += b; 1917 a += b;
1917 a += /*severe:StaticTypeError*/a; 1918 a += /*severe:StaticTypeError*/a;
1918 a -= b; 1919 a -= b;
1919 (/*severe:StaticTypeError*/b -= b); 1920 (/*severe:StaticTypeError*/b -= b);
1920 a <<= b; 1921 a <<= b;
1921 a >>= b; 1922 a >>= b;
1922 a &= b; 1923 a &= b;
(...skipping 876 matching lines...) Expand 10 before | Expand all | Expand 10 after
2799 f = bar as II2D; 2800 f = bar as II2D;
2800 f = bar as DD2I; 2801 f = bar as DD2I;
2801 f = bar as DI2D; 2802 f = bar as DI2D;
2802 f = bar as ID2D; 2803 f = bar as ID2D;
2803 f = bar as DD2D; 2804 f = bar as DD2D;
2804 } 2805 }
2805 ''' 2806 '''
2806 }); 2807 });
2807 }); 2808 });
2808 } 2809 }
OLDNEW
« no previous file with comments | « lib/src/options.dart ('k') | test/checker/inferred_type_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698