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

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

Issue 2990223002: Reformat untouched files. (Closed)
Patch Set: Created 3 years, 4 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) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, 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 import 'dart:async'; 5 import 'dart:async';
6 6
7 import 'package:async_helper/async_helper.dart'; 7 import 'package:async_helper/async_helper.dart';
8 import 'package:expect/expect.dart'; 8 import 'package:expect/expect.dart';
9 9
10 import 'package:compiler/src/elements/resolution_types.dart'; 10 import 'package:compiler/src/elements/resolution_types.dart';
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 static String staticString; 172 static String staticString;
173 static int staticInt; 173 static int staticInt;
174 } 174 }
175 """; 175 """;
176 compiler.parseScript(script); 176 compiler.parseScript(script);
177 LibraryElement mainApp = compiler.mainApp; 177 LibraryElement mainApp = compiler.mainApp;
178 ClassElement foo = mainApp.find("Class"); 178 ClassElement foo = mainApp.find("Class");
179 foo.ensureResolved(compiler.resolution); 179 foo.ensureResolved(compiler.resolution);
180 FunctionElement method = foo.lookupLocalMember('forIn'); 180 FunctionElement method = foo.lookupLocalMember('forIn');
181 181
182 analyzeIn( 182 analyzeIn(compiler, method, """{
183 compiler,
184 method,
185 """{
186 for (var e in <String>[]) {} 183 for (var e in <String>[]) {}
187 }"""); 184 }""");
188 analyzeIn( 185 analyzeIn(compiler, method, """{
189 compiler,
190 method,
191 """{
192 for (String e in <String>[]) {} 186 for (String e in <String>[]) {}
193 }"""); 187 }""");
194 analyzeIn( 188 analyzeIn(
195 compiler, 189 compiler,
196 method, 190 method,
197 """{ 191 """{
198 for (int e in <String>[]) {} 192 for (int e in <String>[]) {}
199 }""", 193 }""",
200 hints: MessageKind.FORIN_NOT_ASSIGNABLE); 194 hints: MessageKind.FORIN_NOT_ASSIGNABLE);
201 analyzeIn( 195 analyzeIn(compiler, method, """{
202 compiler,
203 method,
204 """{
205 for (int e in []) {} 196 for (int e in []) {}
206 }"""); 197 }""");
207 198
208 analyzeIn( 199 analyzeIn(compiler, method, """{
209 compiler,
210 method,
211 """{
212 for (var e in new HasUntypedIterator()) {} 200 for (var e in new HasUntypedIterator()) {}
213 }"""); 201 }""");
214 analyzeIn( 202 analyzeIn(compiler, method, """{
215 compiler,
216 method,
217 """{
218 for (String e in new HasUntypedIterator()) {} 203 for (String e in new HasUntypedIterator()) {}
219 }"""); 204 }""");
220 analyzeIn( 205 analyzeIn(compiler, method, """{
221 compiler,
222 method,
223 """{
224 for (int e in new HasUntypedIterator()) {} 206 for (int e in new HasUntypedIterator()) {}
225 }"""); 207 }""");
226 208
227 analyzeIn( 209 analyzeIn(compiler, method, """{
228 compiler,
229 method,
230 """{
231 for (var e in new HasIntIterator()) {} 210 for (var e in new HasIntIterator()) {}
232 }"""); 211 }""");
233 analyzeIn( 212 analyzeIn(
234 compiler, 213 compiler,
235 method, 214 method,
236 """{ 215 """{
237 for (String e in new HasIntIterator()) {} 216 for (String e in new HasIntIterator()) {}
238 }""", 217 }""",
239 hints: MessageKind.FORIN_NOT_ASSIGNABLE); 218 hints: MessageKind.FORIN_NOT_ASSIGNABLE);
240 analyzeIn( 219 analyzeIn(compiler, method, """{
241 compiler,
242 method,
243 """{
244 for (int e in new HasIntIterator()) {} 220 for (int e in new HasIntIterator()) {}
245 }"""); 221 }""");
246 222
247 analyzeIn( 223 analyzeIn(
248 compiler, 224 compiler,
249 method, 225 method,
250 """{ 226 """{
251 for (var e in new HasNoIterator()) {} 227 for (var e in new HasNoIterator()) {}
252 }""", 228 }""",
253 warnings: MessageKind.UNDEFINED_GETTER); 229 warnings: MessageKind.UNDEFINED_GETTER);
254 analyzeIn( 230 analyzeIn(
255 compiler, 231 compiler,
256 method, 232 method,
257 """{ 233 """{
258 for (String e in new HasNoIterator()) {} 234 for (String e in new HasNoIterator()) {}
259 }""", 235 }""",
260 warnings: MessageKind.UNDEFINED_GETTER); 236 warnings: MessageKind.UNDEFINED_GETTER);
261 analyzeIn( 237 analyzeIn(
262 compiler, 238 compiler,
263 method, 239 method,
264 """{ 240 """{
265 for (int e in new HasNoIterator()) {} 241 for (int e in new HasNoIterator()) {}
266 }""", 242 }""",
267 warnings: MessageKind.UNDEFINED_GETTER); 243 warnings: MessageKind.UNDEFINED_GETTER);
268 244
269 analyzeIn( 245 analyzeIn(compiler, method, """{
270 compiler,
271 method,
272 """{
273 for (var e in new HasCustomIntIterator()) {} 246 for (var e in new HasCustomIntIterator()) {}
274 }"""); 247 }""");
275 analyzeIn( 248 analyzeIn(
276 compiler, 249 compiler,
277 method, 250 method,
278 """{ 251 """{
279 for (String e in new HasCustomIntIterator()) {} 252 for (String e in new HasCustomIntIterator()) {}
280 }""", 253 }""",
281 hints: MessageKind.FORIN_NOT_ASSIGNABLE); 254 hints: MessageKind.FORIN_NOT_ASSIGNABLE);
282 analyzeIn( 255 analyzeIn(compiler, method, """{
283 compiler,
284 method,
285 """{
286 for (int e in new HasCustomIntIterator()) {} 256 for (int e in new HasCustomIntIterator()) {}
287 }"""); 257 }""");
288 258
289 analyzeIn( 259 analyzeIn(
290 compiler, 260 compiler,
291 method, 261 method,
292 """{ 262 """{
293 for (var e in new HasCustomNoCurrentIterator()) {} 263 for (var e in new HasCustomNoCurrentIterator()) {}
294 }""", 264 }""",
295 hints: MessageKind.UNDEFINED_GETTER); 265 hints: MessageKind.UNDEFINED_GETTER);
296 analyzeIn( 266 analyzeIn(
297 compiler, 267 compiler,
298 method, 268 method,
299 """{ 269 """{
300 for (String e in new HasCustomNoCurrentIterator()) {} 270 for (String e in new HasCustomNoCurrentIterator()) {}
301 }""", 271 }""",
302 hints: MessageKind.UNDEFINED_GETTER); 272 hints: MessageKind.UNDEFINED_GETTER);
303 analyzeIn( 273 analyzeIn(
304 compiler, 274 compiler,
305 method, 275 method,
306 """{ 276 """{
307 for (int e in new HasCustomNoCurrentIterator()) {} 277 for (int e in new HasCustomNoCurrentIterator()) {}
308 }""", 278 }""",
309 hints: MessageKind.UNDEFINED_GETTER); 279 hints: MessageKind.UNDEFINED_GETTER);
310 280
311 analyzeIn( 281 analyzeIn(compiler, method, """{
312 compiler,
313 method,
314 """{
315 var localDyn; 282 var localDyn;
316 for (localDyn in <String>[]) {} 283 for (localDyn in <String>[]) {}
317 }"""); 284 }""");
318 analyzeIn( 285 analyzeIn(compiler, method, """{
319 compiler,
320 method,
321 """{
322 String localString; 286 String localString;
323 for (localString in <String>[]) {} 287 for (localString in <String>[]) {}
324 }"""); 288 }""");
325 analyzeIn( 289 analyzeIn(
326 compiler, 290 compiler,
327 method, 291 method,
328 """{ 292 """{
329 int localInt; 293 int localInt;
330 for (localInt in <String>[]) {} 294 for (localInt in <String>[]) {}
331 }""", 295 }""",
332 hints: MessageKind.FORIN_NOT_ASSIGNABLE); 296 hints: MessageKind.FORIN_NOT_ASSIGNABLE);
333 297
334 analyzeIn( 298 analyzeIn(compiler, method, """{
335 compiler,
336 method,
337 """{
338 for (topLevelDyn in <String>[]) {} 299 for (topLevelDyn in <String>[]) {}
339 }"""); 300 }""");
340 analyzeIn( 301 analyzeIn(compiler, method, """{
341 compiler,
342 method,
343 """{
344 for (topLevelString in <String>[]) {} 302 for (topLevelString in <String>[]) {}
345 }"""); 303 }""");
346 analyzeIn( 304 analyzeIn(
347 compiler, 305 compiler,
348 method, 306 method,
349 """{ 307 """{
350 for (topLevelInt in <String>[]) {} 308 for (topLevelInt in <String>[]) {}
351 }""", 309 }""",
352 hints: MessageKind.FORIN_NOT_ASSIGNABLE); 310 hints: MessageKind.FORIN_NOT_ASSIGNABLE);
353 311
354 analyzeIn( 312 analyzeIn(compiler, method, """{
355 compiler,
356 method,
357 """{
358 for (instanceDyn in <String>[]) {} 313 for (instanceDyn in <String>[]) {}
359 }"""); 314 }""");
360 analyzeIn( 315 analyzeIn(compiler, method, """{
361 compiler,
362 method,
363 """{
364 for (instanceString in <String>[]) {} 316 for (instanceString in <String>[]) {}
365 }"""); 317 }""");
366 analyzeIn( 318 analyzeIn(
367 compiler, 319 compiler,
368 method, 320 method,
369 """{ 321 """{
370 for (instanceInt in <String>[]) {} 322 for (instanceInt in <String>[]) {}
371 }""", 323 }""",
372 hints: MessageKind.FORIN_NOT_ASSIGNABLE); 324 hints: MessageKind.FORIN_NOT_ASSIGNABLE);
373 325
374 analyzeIn( 326 analyzeIn(compiler, method, """{
375 compiler,
376 method,
377 """{
378 for (staticDyn in <String>[]) {} 327 for (staticDyn in <String>[]) {}
379 }"""); 328 }""");
380 analyzeIn( 329 analyzeIn(compiler, method, """{
381 compiler,
382 method,
383 """{
384 for (staticString in <String>[]) {} 330 for (staticString in <String>[]) {}
385 }"""); 331 }""");
386 analyzeIn( 332 analyzeIn(
387 compiler, 333 compiler,
388 method, 334 method,
389 """{ 335 """{
390 for (staticInt in <String>[]) {} 336 for (staticInt in <String>[]) {}
391 }""", 337 }""",
392 hints: MessageKind.FORIN_NOT_ASSIGNABLE); 338 hints: MessageKind.FORIN_NOT_ASSIGNABLE);
393 } 339 }
(...skipping 18 matching lines...) Expand all
412 static String staticString; 358 static String staticString;
413 static int staticInt; 359 static int staticInt;
414 } 360 }
415 """; 361 """;
416 compiler.parseScript(script); 362 compiler.parseScript(script);
417 LibraryElement mainApp = compiler.mainApp; 363 LibraryElement mainApp = compiler.mainApp;
418 ClassElement foo = mainApp.find("Class"); 364 ClassElement foo = mainApp.find("Class");
419 foo.ensureResolved(compiler.resolution); 365 foo.ensureResolved(compiler.resolution);
420 FunctionElement method = foo.lookupLocalMember('forIn'); 366 FunctionElement method = foo.lookupLocalMember('forIn');
421 367
422 analyzeIn( 368 analyzeIn(compiler, method, """{
423 compiler,
424 method,
425 """{
426 var stream; 369 var stream;
427 await for (var e in stream) {} 370 await for (var e in stream) {}
428 }"""); 371 }""");
429 analyzeIn( 372 analyzeIn(compiler, method, """{
430 compiler,
431 method,
432 """{
433 var stream; 373 var stream;
434 await for (String e in stream) {} 374 await for (String e in stream) {}
435 }"""); 375 }""");
436 analyzeIn( 376 analyzeIn(compiler, method, """{
437 compiler,
438 method,
439 """{
440 var stream; 377 var stream;
441 await for (int e in stream) {} 378 await for (int e in stream) {}
442 }"""); 379 }""");
443 380
444 analyzeIn( 381 analyzeIn(
445 compiler, 382 compiler,
446 method, 383 method,
447 """{ 384 """{
448 await for (var e in []) {} 385 await for (var e in []) {}
449 }""", 386 }""",
450 hints: MessageKind.NOT_ASSIGNABLE); 387 hints: MessageKind.NOT_ASSIGNABLE);
451 388
452 analyzeIn( 389 analyzeIn(compiler, method, """{
453 compiler,
454 method,
455 """{
456 Stream<String> stream; 390 Stream<String> stream;
457 await for (var e in stream) {} 391 await for (var e in stream) {}
458 }"""); 392 }""");
459 analyzeIn( 393 analyzeIn(compiler, method, """{
460 compiler,
461 method,
462 """{
463 Stream<String> stream; 394 Stream<String> stream;
464 await for (String e in stream) {} 395 await for (String e in stream) {}
465 }"""); 396 }""");
466 analyzeIn( 397 analyzeIn(
467 compiler, 398 compiler,
468 method, 399 method,
469 """{ 400 """{
470 Stream<String> stream; 401 Stream<String> stream;
471 await for (int e in stream) {} 402 await for (int e in stream) {}
472 }""", 403 }""",
473 hints: MessageKind.FORIN_NOT_ASSIGNABLE); 404 hints: MessageKind.FORIN_NOT_ASSIGNABLE);
474 405
475 analyzeIn( 406 analyzeIn(compiler, method, """{
476 compiler,
477 method,
478 """{
479 CustomStream<String> stream; 407 CustomStream<String> stream;
480 await for (var e in stream) {} 408 await for (var e in stream) {}
481 }"""); 409 }""");
482 analyzeIn( 410 analyzeIn(compiler, method, """{
483 compiler,
484 method,
485 """{
486 CustomStream<String> stream; 411 CustomStream<String> stream;
487 await for (String e in stream) {} 412 await for (String e in stream) {}
488 }"""); 413 }""");
489 analyzeIn( 414 analyzeIn(
490 compiler, 415 compiler,
491 method, 416 method,
492 """{ 417 """{
493 CustomStream<String> stream; 418 CustomStream<String> stream;
494 await for (int e in stream) {} 419 await for (int e in stream) {}
495 }""", 420 }""",
496 hints: MessageKind.FORIN_NOT_ASSIGNABLE); 421 hints: MessageKind.FORIN_NOT_ASSIGNABLE);
497 422
498 analyzeIn( 423 analyzeIn(compiler, method, """{
499 compiler,
500 method,
501 """{
502 StringStream stream; 424 StringStream stream;
503 await for (var e in stream) {} 425 await for (var e in stream) {}
504 }"""); 426 }""");
505 analyzeIn( 427 analyzeIn(compiler, method, """{
506 compiler,
507 method,
508 """{
509 StringStream stream; 428 StringStream stream;
510 await for (String e in stream) {} 429 await for (String e in stream) {}
511 }"""); 430 }""");
512 analyzeIn( 431 analyzeIn(
513 compiler, 432 compiler,
514 method, 433 method,
515 """{ 434 """{
516 StringStream stream; 435 StringStream stream;
517 await for (int e in stream) {} 436 await for (int e in stream) {}
518 }""", 437 }""",
519 hints: MessageKind.FORIN_NOT_ASSIGNABLE); 438 hints: MessageKind.FORIN_NOT_ASSIGNABLE);
520 439
521 analyzeIn( 440 analyzeIn(compiler, method, """{
522 compiler,
523 method,
524 """{
525 Stream<String> stream; 441 Stream<String> stream;
526 var localDyn; 442 var localDyn;
527 await for (localDyn in stream) {} 443 await for (localDyn in stream) {}
528 }"""); 444 }""");
529 analyzeIn( 445 analyzeIn(compiler, method, """{
530 compiler,
531 method,
532 """{
533 Stream<String> stream; 446 Stream<String> stream;
534 String localString; 447 String localString;
535 await for (localString in stream) {} 448 await for (localString in stream) {}
536 }"""); 449 }""");
537 analyzeIn( 450 analyzeIn(
538 compiler, 451 compiler,
539 method, 452 method,
540 """{ 453 """{
541 Stream<String> stream; 454 Stream<String> stream;
542 int localInt; 455 int localInt;
543 await for (localInt in stream) {} 456 await for (localInt in stream) {}
544 }""", 457 }""",
545 hints: MessageKind.FORIN_NOT_ASSIGNABLE); 458 hints: MessageKind.FORIN_NOT_ASSIGNABLE);
546 459
547 analyzeIn( 460 analyzeIn(compiler, method, """{
548 compiler,
549 method,
550 """{
551 Stream<String> stream; 461 Stream<String> stream;
552 await for (topLevelDyn in stream) {} 462 await for (topLevelDyn in stream) {}
553 }"""); 463 }""");
554 analyzeIn( 464 analyzeIn(compiler, method, """{
555 compiler,
556 method,
557 """{
558 Stream<String> stream; 465 Stream<String> stream;
559 await for (topLevelString in stream) {} 466 await for (topLevelString in stream) {}
560 }"""); 467 }""");
561 analyzeIn( 468 analyzeIn(
562 compiler, 469 compiler,
563 method, 470 method,
564 """{ 471 """{
565 Stream<String> stream; 472 Stream<String> stream;
566 await for (topLevelInt in stream) {} 473 await for (topLevelInt in stream) {}
567 }""", 474 }""",
568 hints: MessageKind.FORIN_NOT_ASSIGNABLE); 475 hints: MessageKind.FORIN_NOT_ASSIGNABLE);
569 476
570 analyzeIn( 477 analyzeIn(compiler, method, """{
571 compiler,
572 method,
573 """{
574 Stream<String> stream; 478 Stream<String> stream;
575 await for (instanceDyn in stream) {} 479 await for (instanceDyn in stream) {}
576 }"""); 480 }""");
577 analyzeIn( 481 analyzeIn(compiler, method, """{
578 compiler,
579 method,
580 """{
581 Stream<String> stream; 482 Stream<String> stream;
582 await for (instanceString in stream) {} 483 await for (instanceString in stream) {}
583 }"""); 484 }""");
584 analyzeIn( 485 analyzeIn(
585 compiler, 486 compiler,
586 method, 487 method,
587 """{ 488 """{
588 Stream<String> stream; 489 Stream<String> stream;
589 await for (instanceInt in stream) {} 490 await for (instanceInt in stream) {}
590 }""", 491 }""",
591 hints: MessageKind.FORIN_NOT_ASSIGNABLE); 492 hints: MessageKind.FORIN_NOT_ASSIGNABLE);
592 493
593 analyzeIn( 494 analyzeIn(compiler, method, """{
594 compiler,
595 method,
596 """{
597 Stream<String> stream; 495 Stream<String> stream;
598 await for (staticDyn in stream) {} 496 await for (staticDyn in stream) {}
599 }"""); 497 }""");
600 analyzeIn( 498 analyzeIn(compiler, method, """{
601 compiler,
602 method,
603 """{
604 Stream<String> stream; 499 Stream<String> stream;
605 await for (staticString in stream) {} 500 await for (staticString in stream) {}
606 }"""); 501 }""");
607 analyzeIn( 502 analyzeIn(
608 compiler, 503 compiler,
609 method, 504 method,
610 """{ 505 """{
611 Stream<String> stream; 506 Stream<String> stream;
612 await for (staticInt in stream) {} 507 await for (staticInt in stream) {}
613 }""", 508 }""",
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
704 default: break; 599 default: break;
705 }"""); 600 }""");
706 601
707 check(""" 602 check("""
708 switch (Enum.A) { 603 switch (Enum.A) {
709 case Enum.A: break; 604 case Enum.A: break;
710 case Enum.B: break; 605 case Enum.B: break;
711 case Enum.C: break; 606 case Enum.C: break;
712 }"""); 607 }""");
713 608
714 check( 609 check("""
715 """
716 switch (Enum.A) { 610 switch (Enum.A) {
717 case Enum.B: break; 611 case Enum.B: break;
718 case Enum.C: break; 612 case Enum.C: break;
719 }""", 613 }""", warnings: MessageKind.MISSING_ENUM_CASES);
720 warnings: MessageKind.MISSING_ENUM_CASES);
721 614
722 check( 615 check("""
723 """
724 switch (Enum.A) { 616 switch (Enum.A) {
725 case Enum.A: break; 617 case Enum.A: break;
726 case Enum.C: break; 618 case Enum.C: break;
727 }""", 619 }""", warnings: MessageKind.MISSING_ENUM_CASES);
728 warnings: MessageKind.MISSING_ENUM_CASES);
729 620
730 check( 621 check("""
731 """
732 switch (Enum.A) { 622 switch (Enum.A) {
733 case Enum.A: break; 623 case Enum.A: break;
734 case Enum.B: break; 624 case Enum.B: break;
735 }""", 625 }""", warnings: MessageKind.MISSING_ENUM_CASES);
736 warnings: MessageKind.MISSING_ENUM_CASES);
737 626
738 check( 627 check("""
739 """
740 switch (Enum.A) { 628 switch (Enum.A) {
741 case Enum.A: break; 629 case Enum.A: break;
742 }""", 630 }""", warnings: MessageKind.MISSING_ENUM_CASES);
743 warnings: MessageKind.MISSING_ENUM_CASES);
744 631
745 check( 632 check("""
746 """
747 switch (Enum.A) { 633 switch (Enum.A) {
748 case Enum.B: break; 634 case Enum.B: break;
749 }""", 635 }""", warnings: MessageKind.MISSING_ENUM_CASES);
750 warnings: MessageKind.MISSING_ENUM_CASES);
751 636
752 check( 637 check("""
753 """
754 switch (Enum.A) { 638 switch (Enum.A) {
755 case Enum.C: break; 639 case Enum.C: break;
756 }""", 640 }""", warnings: MessageKind.MISSING_ENUM_CASES);
757 warnings: MessageKind.MISSING_ENUM_CASES);
758 641
759 check( 642 check("""
760 """
761 switch (Enum.A) { 643 switch (Enum.A) {
762 }""", 644 }""", warnings: MessageKind.MISSING_ENUM_CASES);
763 warnings: MessageKind.MISSING_ENUM_CASES);
764 } 645 }
765 646
766 testOperators(MockCompiler compiler) { 647 testOperators(MockCompiler compiler) {
767 check(String code, {warnings}) { 648 check(String code, {warnings}) {
768 analyze(compiler, code, warnings: warnings); 649 analyze(compiler, code, warnings: warnings);
769 } 650 }
770 651
771 // TODO(karlklose): add the DartC tests for operators when we can parse 652 // TODO(karlklose): add the DartC tests for operators when we can parse
772 // classes with operators. 653 // classes with operators.
773 for (final op in ['+', '-', '*', '/', '%', '~/', '|', '&']) { 654 for (final op in ['+', '-', '*', '/', '%', '~/', '|', '&']) {
(...skipping 883 matching lines...) Expand 10 before | Expand all | Expand 10 after
1657 Future check(String code, [expectedWarnings]) { 1538 Future check(String code, [expectedWarnings]) {
1658 return analyzeTopLevel(code, expectedWarnings); 1539 return analyzeTopLevel(code, expectedWarnings);
1659 } 1540 }
1660 1541
1661 return Future.wait([ 1542 return Future.wait([
1662 check("""int i = 0;"""), 1543 check("""int i = 0;"""),
1663 check("""int i = '';""", NOT_ASSIGNABLE), 1544 check("""int i = '';""", NOT_ASSIGNABLE),
1664 check("""class Class { 1545 check("""class Class {
1665 int i = 0; 1546 int i = 0;
1666 }"""), 1547 }"""),
1667 check( 1548 check("""class Class {
1668 """class Class {
1669 int i = ''; 1549 int i = '';
1670 }""", 1550 }""", NOT_ASSIGNABLE),
1671 NOT_ASSIGNABLE),
1672 ]); 1551 ]);
1673 } 1552 }
1674 1553
1675 void testTypeVariableExpressions(MockCompiler compiler) { 1554 void testTypeVariableExpressions(MockCompiler compiler) {
1676 String script = """class Foo<T> { 1555 String script = """class Foo<T> {
1677 void method() {} 1556 void method() {}
1678 }"""; 1557 }""";
1679 compiler.parseScript(script); 1558 compiler.parseScript(script);
1680 LibraryElement mainApp = compiler.mainApp; 1559 LibraryElement mainApp = compiler.mainApp;
1681 ClassElement foo = mainApp.find("Foo"); 1560 ClassElement foo = mainApp.find("Foo");
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
1873 check(r'''class Class { 1752 check(r'''class Class {
1874 int a; 1753 int a;
1875 Class(this.a); 1754 Class(this.a);
1876 } 1755 }
1877 '''), 1756 '''),
1878 check(r'''class Class { 1757 check(r'''class Class {
1879 var a; 1758 var a;
1880 Class(int this.a); 1759 Class(int this.a);
1881 } 1760 }
1882 '''), 1761 '''),
1883 check( 1762 check(r'''class Class {
1884 r'''class Class {
1885 String a; 1763 String a;
1886 Class(int this.a); 1764 Class(int this.a);
1887 } 1765 }
1888 ''', 1766 ''', NOT_ASSIGNABLE),
1889 NOT_ASSIGNABLE),
1890 check(r'''class Class { 1767 check(r'''class Class {
1891 var a; 1768 var a;
1892 Class(int a) : this.a = a; 1769 Class(int a) : this.a = a;
1893 } 1770 }
1894 '''), 1771 '''),
1895 check( 1772 check(r'''class Class {
1896 r'''class Class {
1897 String a; 1773 String a;
1898 Class(int a) : this.a = a; 1774 Class(int a) : this.a = a;
1899 } 1775 }
1900 ''', 1776 ''', NOT_ASSIGNABLE),
1901 NOT_ASSIGNABLE),
1902 1777
1903 // Check this-calls. 1778 // Check this-calls.
1904 check(r'''class Class { 1779 check(r'''class Class {
1905 var a; 1780 var a;
1906 Class(this.a); 1781 Class(this.a);
1907 Class.named(int a) : this(a); 1782 Class.named(int a) : this(a);
1908 } 1783 }
1909 '''), 1784 '''),
1910 check( 1785 check(r'''class Class {
1911 r'''class Class {
1912 String a; 1786 String a;
1913 Class(this.a); 1787 Class(this.a);
1914 Class.named(int a) : this(a); 1788 Class.named(int a) : this(a);
1915 } 1789 }
1916 ''', 1790 ''', NOT_ASSIGNABLE),
1917 NOT_ASSIGNABLE),
1918 check(r'''class Class { 1791 check(r'''class Class {
1919 String a; 1792 String a;
1920 Class(var a) : this.a = a; 1793 Class(var a) : this.a = a;
1921 Class.named(int a) : this(a); 1794 Class.named(int a) : this(a);
1922 } 1795 }
1923 '''), 1796 '''),
1924 check( 1797 check(r'''class Class {
1925 r'''class Class {
1926 String a; 1798 String a;
1927 Class(String a) : this.a = a; 1799 Class(String a) : this.a = a;
1928 Class.named(int a) : this(a); 1800 Class.named(int a) : this(a);
1929 } 1801 }
1930 ''', 1802 ''', NOT_ASSIGNABLE),
1931 NOT_ASSIGNABLE),
1932 1803
1933 // Check super-calls. 1804 // Check super-calls.
1934 check(r'''class Super { 1805 check(r'''class Super {
1935 var a; 1806 var a;
1936 Super(this.a); 1807 Super(this.a);
1937 } 1808 }
1938 class Class extends Super { 1809 class Class extends Super {
1939 Class.named(int a) : super(a); 1810 Class.named(int a) : super(a);
1940 } 1811 }
1941 '''), 1812 '''),
1942 check( 1813 check(r'''class Super {
1943 r'''class Super {
1944 String a; 1814 String a;
1945 Super(this.a); 1815 Super(this.a);
1946 } 1816 }
1947 class Class extends Super { 1817 class Class extends Super {
1948 Class.named(int a) : super(a); 1818 Class.named(int a) : super(a);
1949 } 1819 }
1950 ''', 1820 ''', NOT_ASSIGNABLE),
1951 NOT_ASSIGNABLE),
1952 check(r'''class Super { 1821 check(r'''class Super {
1953 String a; 1822 String a;
1954 Super(var a) : this.a = a; 1823 Super(var a) : this.a = a;
1955 } 1824 }
1956 class Class extends Super { 1825 class Class extends Super {
1957 Class.named(int a) : super(a); 1826 Class.named(int a) : super(a);
1958 } 1827 }
1959 '''), 1828 '''),
1960 check( 1829 check(r'''class Super {
1961 r'''class Super {
1962 String a; 1830 String a;
1963 Super(String a) : this.a = a; 1831 Super(String a) : this.a = a;
1964 } 1832 }
1965 class Class extends Super { 1833 class Class extends Super {
1966 Class.named(int a) : super(a); 1834 Class.named(int a) : super(a);
1967 } 1835 }
1968 ''', 1836 ''', NOT_ASSIGNABLE),
1969 NOT_ASSIGNABLE),
1970 1837
1971 // Check super-calls involving generics. 1838 // Check super-calls involving generics.
1972 check(r'''class Super<T> { 1839 check(r'''class Super<T> {
1973 var a; 1840 var a;
1974 Super(this.a); 1841 Super(this.a);
1975 } 1842 }
1976 class Class extends Super<String> { 1843 class Class extends Super<String> {
1977 Class.named(int a) : super(a); 1844 Class.named(int a) : super(a);
1978 } 1845 }
1979 '''), 1846 '''),
1980 check( 1847 check(r'''class Super<T> {
1981 r'''class Super<T> {
1982 T a; 1848 T a;
1983 Super(this.a); 1849 Super(this.a);
1984 } 1850 }
1985 class Class extends Super<String> { 1851 class Class extends Super<String> {
1986 Class.named(int a) : super(a); 1852 Class.named(int a) : super(a);
1987 } 1853 }
1988 ''', 1854 ''', NOT_ASSIGNABLE),
1989 NOT_ASSIGNABLE),
1990 check(r'''class Super<T> { 1855 check(r'''class Super<T> {
1991 T a; 1856 T a;
1992 Super(var a) : this.a = a; 1857 Super(var a) : this.a = a;
1993 } 1858 }
1994 class Class extends Super<String> { 1859 class Class extends Super<String> {
1995 Class.named(int a) : super(a); 1860 Class.named(int a) : super(a);
1996 } 1861 }
1997 '''), 1862 '''),
1998 check( 1863 check(r'''class Super<T> {
1999 r'''class Super<T> {
2000 T a; 1864 T a;
2001 Super(T a) : this.a = a; 1865 Super(T a) : this.a = a;
2002 } 1866 }
2003 class Class extends Super<String> { 1867 class Class extends Super<String> {
2004 Class.named(int a) : super(a); 1868 Class.named(int a) : super(a);
2005 } 1869 }
2006 ''', 1870 ''', NOT_ASSIGNABLE),
2007 NOT_ASSIGNABLE),
2008 1871
2009 // Check instance creations. 1872 // Check instance creations.
2010 check(r'''class Class { 1873 check(r'''class Class {
2011 var a; 1874 var a;
2012 Class(this.a); 1875 Class(this.a);
2013 } 1876 }
2014 method(int a) => new Class(a); 1877 method(int a) => new Class(a);
2015 '''), 1878 '''),
2016 check( 1879 check(r'''class Class {
2017 r'''class Class {
2018 String a; 1880 String a;
2019 Class(this.a); 1881 Class(this.a);
2020 } 1882 }
2021 method(int a) => new Class(a); 1883 method(int a) => new Class(a);
2022 ''', 1884 ''', NOT_ASSIGNABLE),
2023 NOT_ASSIGNABLE),
2024 check(r'''class Class { 1885 check(r'''class Class {
2025 String a; 1886 String a;
2026 Class(var a) : this.a = a; 1887 Class(var a) : this.a = a;
2027 } 1888 }
2028 method(int a) => new Class(a); 1889 method(int a) => new Class(a);
2029 '''), 1890 '''),
2030 check( 1891 check(r'''class Class {
2031 r'''class Class {
2032 String a; 1892 String a;
2033 Class(String a) : this.a = a; 1893 Class(String a) : this.a = a;
2034 } 1894 }
2035 method(int a) => new Class(a); 1895 method(int a) => new Class(a);
2036 ''', 1896 ''', NOT_ASSIGNABLE),
2037 NOT_ASSIGNABLE),
2038 1897
2039 // Check instance creations involving generics. 1898 // Check instance creations involving generics.
2040 check(r'''class Class<T> { 1899 check(r'''class Class<T> {
2041 var a; 1900 var a;
2042 Class(this.a); 1901 Class(this.a);
2043 } 1902 }
2044 method(int a) => new Class<String>(a); 1903 method(int a) => new Class<String>(a);
2045 '''), 1904 '''),
2046 check( 1905 check(r'''class Class<T> {
2047 r'''class Class<T> {
2048 T a; 1906 T a;
2049 Class(this.a); 1907 Class(this.a);
2050 } 1908 }
2051 method(int a) => new Class<String>(a); 1909 method(int a) => new Class<String>(a);
2052 ''', 1910 ''', NOT_ASSIGNABLE),
2053 NOT_ASSIGNABLE),
2054 check(r'''class Class<T> { 1911 check(r'''class Class<T> {
2055 T a; 1912 T a;
2056 Class(var a) : this.a = a; 1913 Class(var a) : this.a = a;
2057 } 1914 }
2058 method(int a) => new Class<String>(a); 1915 method(int a) => new Class<String>(a);
2059 '''), 1916 '''),
2060 check( 1917 check(r'''class Class<T> {
2061 r'''class Class<T> {
2062 T a; 1918 T a;
2063 Class(String a) : this.a = a; 1919 Class(String a) : this.a = a;
2064 } 1920 }
2065 method(int a) => new Class<String>(a); 1921 method(int a) => new Class<String>(a);
2066 ''', 1922 ''', NOT_ASSIGNABLE),
2067 NOT_ASSIGNABLE),
2068 ]); 1923 ]);
2069 } 1924 }
2070 1925
2071 void testGetterSetterInvocation(MockCompiler compiler) { 1926 void testGetterSetterInvocation(MockCompiler compiler) {
2072 compiler.parseScript(r'''int get variable => 0; 1927 compiler.parseScript(r'''int get variable => 0;
2073 void set variable(String s) {} 1928 void set variable(String s) {}
2074 1929
2075 class Class { 1930 class Class {
2076 int get instanceField => 0; 1931 int get instanceField => 0;
2077 void set instanceField(String s) {} 1932 void set instanceField(String s) {}
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
2184 class G<V> extends F<V, V> { 2039 class G<V> extends F<V, V> {
2185 V g; 2040 V g;
2186 } 2041 }
2187 '''); 2042 ''');
2188 2043
2189 check(String text, {warnings, hints, infos}) { 2044 check(String text, {warnings, hints, infos}) {
2190 analyze(compiler, '{ $text }', 2045 analyze(compiler, '{ $text }',
2191 warnings: warnings, hints: hints, infos: infos); 2046 warnings: warnings, hints: hints, infos: infos);
2192 } 2047 }
2193 2048
2194 check( 2049 check(r'''
2195 r'''
2196 A a = new B(); 2050 A a = new B();
2197 if (a is C) { 2051 if (a is C) {
2198 var x = a.c; 2052 var x = a.c;
2199 }''', 2053 }''',
2200 warnings: [MessageKind.UNDEFINED_GETTER], 2054 warnings: [MessageKind.UNDEFINED_GETTER],
2201 hints: [MessageKind.NOT_MORE_SPECIFIC_SUBTYPE], 2055 hints: [MessageKind.NOT_MORE_SPECIFIC_SUBTYPE],
2202 infos: []); 2056 infos: []);
2203 2057
2204 check( 2058 check(r'''
2205 r'''
2206 A a = new B(); 2059 A a = new B();
2207 if (a is C) { 2060 if (a is C) {
2208 var x = '${a.c}${a.c}'; 2061 var x = '${a.c}${a.c}';
2209 }''', 2062 }''',
2210 warnings: [MessageKind.UNDEFINED_GETTER, MessageKind.UNDEFINED_GETTER], 2063 warnings: [MessageKind.UNDEFINED_GETTER, MessageKind.UNDEFINED_GETTER],
2211 hints: [MessageKind.NOT_MORE_SPECIFIC_SUBTYPE], 2064 hints: [MessageKind.NOT_MORE_SPECIFIC_SUBTYPE],
2212 infos: []); 2065 infos: []);
2213 2066
2214 check( 2067 check(r'''
2215 r'''
2216 A a = new B(); 2068 A a = new B();
2217 if (a is C) { 2069 if (a is C) {
2218 var x = '${a.d}${a.d}'; // Type promotion wouldn't help. 2070 var x = '${a.d}${a.d}'; // Type promotion wouldn't help.
2219 }''', 2071 }''',
2220 warnings: [MessageKind.UNDEFINED_GETTER, MessageKind.UNDEFINED_GETTER], 2072 warnings: [MessageKind.UNDEFINED_GETTER, MessageKind.UNDEFINED_GETTER],
2221 hints: [], 2073 hints: [],
2222 infos: []); 2074 infos: []);
2223 2075
2224 check( 2076 check('''
2225 '''
2226 D<int> d = new E(); 2077 D<int> d = new E();
2227 if (d is E) { // Suggest E<int>. 2078 if (d is E) { // Suggest E<int>.
2228 var x = d.e; 2079 var x = d.e;
2229 }''', 2080 }''', warnings: [
2230 warnings: [ 2081 MessageKind.UNDEFINED_GETTER
2231 MessageKind.UNDEFINED_GETTER 2082 ], hints: [
2232 ], 2083 checkMessage(MessageKind.NOT_MORE_SPECIFIC_SUGGESTION,
2233 hints: [ 2084 {'shownTypeSuggestion': 'E<int>'})
2234 checkMessage(MessageKind.NOT_MORE_SPECIFIC_SUGGESTION, 2085 ], infos: []);
2235 {'shownTypeSuggestion': 'E<int>'})
2236 ],
2237 infos: []);
2238 2086
2239 check( 2087 check('''
2240 '''
2241 D<int> d = new F(); 2088 D<int> d = new F();
2242 if (d is F) { // Suggest F<int, dynamic>. 2089 if (d is F) { // Suggest F<int, dynamic>.
2243 var x = d.f; 2090 var x = d.f;
2244 }''', 2091 }''', warnings: [
2245 warnings: [ 2092 MessageKind.UNDEFINED_GETTER
2246 MessageKind.UNDEFINED_GETTER 2093 ], hints: [
2247 ], 2094 checkMessage(MessageKind.NOT_MORE_SPECIFIC_SUGGESTION,
2248 hints: [ 2095 {'shownTypeSuggestion': 'F<int, dynamic>'})
2249 checkMessage(MessageKind.NOT_MORE_SPECIFIC_SUGGESTION, 2096 ], infos: []);
2250 {'shownTypeSuggestion': 'F<int, dynamic>'})
2251 ],
2252 infos: []);
2253 2097
2254 check( 2098 check('''
2255 '''
2256 D<int> d = new G(); 2099 D<int> d = new G();
2257 if (d is G) { // Suggest G<int>. 2100 if (d is G) { // Suggest G<int>.
2258 var x = d.f; 2101 var x = d.f;
2259 }''', 2102 }''', warnings: [
2260 warnings: [ 2103 MessageKind.UNDEFINED_GETTER
2261 MessageKind.UNDEFINED_GETTER 2104 ], hints: [
2262 ], 2105 checkMessage(MessageKind.NOT_MORE_SPECIFIC_SUGGESTION,
2263 hints: [ 2106 {'shownTypeSuggestion': 'G<int>'})
2264 checkMessage(MessageKind.NOT_MORE_SPECIFIC_SUGGESTION, 2107 ], infos: []);
2265 {'shownTypeSuggestion': 'G<int>'})
2266 ],
2267 infos: []);
2268 2108
2269 check( 2109 check('''
2270 '''
2271 F<double, int> f = new G(); 2110 F<double, int> f = new G();
2272 if (f is G) { // Cannot suggest a more specific type. 2111 if (f is G) { // Cannot suggest a more specific type.
2273 var x = f.g; 2112 var x = f.g;
2274 }''', 2113 }''',
2275 warnings: [MessageKind.UNDEFINED_GETTER], 2114 warnings: [MessageKind.UNDEFINED_GETTER],
2276 hints: [MessageKind.NOT_MORE_SPECIFIC], 2115 hints: [MessageKind.NOT_MORE_SPECIFIC],
2277 infos: []); 2116 infos: []);
2278 2117
2279 check( 2118 check('''
2280 '''
2281 D<int> d = new E(); 2119 D<int> d = new E();
2282 if (d is E) { 2120 if (d is E) {
2283 var x = d.f; // Type promotion wouldn't help. 2121 var x = d.f; // Type promotion wouldn't help.
2284 }''', 2122 }''',
2285 warnings: [MessageKind.UNDEFINED_GETTER], 2123 warnings: [MessageKind.UNDEFINED_GETTER], hints: [], infos: []);
2286 hints: [],
2287 infos: []);
2288 2124
2289 check( 2125 check('''
2290 '''
2291 A a = new B(); 2126 A a = new B();
2292 if (a is B) { 2127 if (a is B) {
2293 a = null; 2128 a = null;
2294 var x = a.b; 2129 var x = a.b;
2295 }''', 2130 }''',
2296 warnings: [MessageKind.UNDEFINED_GETTER], 2131 warnings: [MessageKind.UNDEFINED_GETTER],
2297 hints: [MessageKind.POTENTIAL_MUTATION], 2132 hints: [MessageKind.POTENTIAL_MUTATION],
2298 infos: [MessageKind.POTENTIAL_MUTATION_HERE]); 2133 infos: [MessageKind.POTENTIAL_MUTATION_HERE]);
2299 2134
2300 check( 2135 check('''
2301 '''
2302 A a = new B(); 2136 A a = new B();
2303 if (a is B) { 2137 if (a is B) {
2304 a = null; 2138 a = null;
2305 var x = a.c; // Type promotion wouldn't help. 2139 var x = a.c; // Type promotion wouldn't help.
2306 }''', 2140 }''',
2307 warnings: [MessageKind.UNDEFINED_GETTER], 2141 warnings: [MessageKind.UNDEFINED_GETTER], hints: [], infos: []);
2308 hints: [],
2309 infos: []);
2310 2142
2311 check( 2143 check('''
2312 '''
2313 A a = new B(); 2144 A a = new B();
2314 local() { a = new A(); } 2145 local() { a = new A(); }
2315 if (a is B) { 2146 if (a is B) {
2316 var x = a.b; 2147 var x = a.b;
2317 }''', 2148 }''',
2318 warnings: [MessageKind.UNDEFINED_GETTER], 2149 warnings: [MessageKind.UNDEFINED_GETTER],
2319 hints: [MessageKind.POTENTIAL_MUTATION_IN_CLOSURE], 2150 hints: [MessageKind.POTENTIAL_MUTATION_IN_CLOSURE],
2320 infos: [MessageKind.POTENTIAL_MUTATION_IN_CLOSURE_HERE]); 2151 infos: [MessageKind.POTENTIAL_MUTATION_IN_CLOSURE_HERE]);
2321 2152
2322 check( 2153 check('''
2323 '''
2324 A a = new B(); 2154 A a = new B();
2325 local() { a = new A(); } 2155 local() { a = new A(); }
2326 if (a is B) { 2156 if (a is B) {
2327 var x = a.c; // Type promotion wouldn't help. 2157 var x = a.c; // Type promotion wouldn't help.
2328 }''', 2158 }''',
2329 warnings: [MessageKind.UNDEFINED_GETTER], 2159 warnings: [MessageKind.UNDEFINED_GETTER], hints: [], infos: []);
2330 hints: [],
2331 infos: []);
2332 2160
2333 check( 2161 check('''
2334 '''
2335 A a = new B(); 2162 A a = new B();
2336 if (a is B) { 2163 if (a is B) {
2337 var x = () => a; 2164 var x = () => a;
2338 var y = a.b; 2165 var y = a.b;
2339 } 2166 }
2340 a = new A();''', 2167 a = new A();''', warnings: [
2341 warnings: [ 2168 MessageKind.UNDEFINED_GETTER
2342 MessageKind.UNDEFINED_GETTER 2169 ], hints: [
2343 ], 2170 MessageKind.ACCESSED_IN_CLOSURE
2344 hints: [ 2171 ], infos: [
2345 MessageKind.ACCESSED_IN_CLOSURE 2172 MessageKind.ACCESSED_IN_CLOSURE_HERE,
2346 ], 2173 MessageKind.POTENTIAL_MUTATION_HERE
2347 infos: [ 2174 ]);
2348 MessageKind.ACCESSED_IN_CLOSURE_HERE,
2349 MessageKind.POTENTIAL_MUTATION_HERE
2350 ]);
2351 2175
2352 check( 2176 check('''
2353 '''
2354 A a = new B(); 2177 A a = new B();
2355 if (a is B) { 2178 if (a is B) {
2356 var x = () => a; 2179 var x = () => a;
2357 var y = a.c; // Type promotion wouldn't help. 2180 var y = a.c; // Type promotion wouldn't help.
2358 } 2181 }
2359 a = new A();''', 2182 a = new A();''',
2360 warnings: [MessageKind.UNDEFINED_GETTER], 2183 warnings: [MessageKind.UNDEFINED_GETTER], hints: [], infos: []);
2361 hints: [],
2362 infos: []);
2363 } 2184 }
2364 2185
2365 void testCascade(MockCompiler compiler) { 2186 void testCascade(MockCompiler compiler) {
2366 compiler.parseScript(r'''typedef A AFunc(); 2187 compiler.parseScript(r'''typedef A AFunc();
2367 typedef Function FuncFunc(); 2188 typedef Function FuncFunc();
2368 class A { 2189 class A {
2369 A a; 2190 A a;
2370 B b; 2191 B b;
2371 C c; 2192 C c;
2372 AFunc afunc() => null; 2193 AFunc afunc() => null;
(...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after
2789 TreeElements elements = compiler.resolveNodeStatement(node, element); 2610 TreeElements elements = compiler.resolveNodeStatement(node, element);
2790 TypeCheckerVisitor checker = 2611 TypeCheckerVisitor checker =
2791 new TypeCheckerVisitor(compiler, elements, compiler.resolution.types); 2612 new TypeCheckerVisitor(compiler, elements, compiler.resolution.types);
2792 DiagnosticCollector collector = compiler.diagnosticCollector; 2613 DiagnosticCollector collector = compiler.diagnosticCollector;
2793 collector.clear(); 2614 collector.clear();
2794 checker.analyze(node, mustHaveType: false); 2615 checker.analyze(node, mustHaveType: false);
2795 generateOutput(compiler, text); 2616 generateOutput(compiler, text);
2796 compareWarningKinds(text, warnings, collector.warnings); 2617 compareWarningKinds(text, warnings, collector.warnings);
2797 compareWarningKinds(text, hints, collector.hints); 2618 compareWarningKinds(text, hints, collector.hints);
2798 } 2619 }
OLDNEW
« no previous file with comments | « tests/compiler/dart2js/subtypeset_test.dart ('k') | tests/compiler/dart2js/type_equals_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698