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

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

Powered by Google App Engine
This is Rietveld 408576698