| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 library engine.resolver_test; | 5 library engine.resolver_test; |
| 6 | 6 |
| 7 import 'dart:collection'; | 7 import 'dart:collection'; |
| 8 import 'package:analyzer/src/generated/java_core.dart'; | 8 import 'package:analyzer/src/generated/java_core.dart'; |
| 9 import 'package:analyzer/src/generated/java_junit.dart'; | 9 import 'package:analyzer/src/generated/java_junit.dart'; |
| 10 import 'package:analyzer/src/generated/java_engine.dart'; | 10 import 'package:analyzer/src/generated/java_engine.dart'; |
| (...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 413 changeSet.removedContainer(new SourceContainer_ChangeSetTest_test_toString()
); | 413 changeSet.removedContainer(new SourceContainer_ChangeSetTest_test_toString()
); |
| 414 JUnitTestCase.assertNotNull(changeSet.toString()); | 414 JUnitTestCase.assertNotNull(changeSet.toString()); |
| 415 } | 415 } |
| 416 } | 416 } |
| 417 | 417 |
| 418 class CheckedModeCompileTimeErrorCodeTest extends ResolverTestCase { | 418 class CheckedModeCompileTimeErrorCodeTest extends ResolverTestCase { |
| 419 void test_fieldFormalParameterAssignableToField_extends() { | 419 void test_fieldFormalParameterAssignableToField_extends() { |
| 420 // According to checked-mode type checking rules, a value of type B is | 420 // According to checked-mode type checking rules, a value of type B is |
| 421 // assignable to a field of type A, because B extends A (and hence is a | 421 // assignable to a field of type A, because B extends A (and hence is a |
| 422 // subtype of A). | 422 // subtype of A). |
| 423 Source source = addSource(EngineTestCase.createSource([ | 423 Source source = addSource(r''' |
| 424 "class A {", | 424 class A { |
| 425 " const A();", | 425 const A(); |
| 426 "}", | 426 } |
| 427 "class B extends A {", | 427 class B extends A { |
| 428 " const B();", | 428 const B(); |
| 429 "}", | 429 } |
| 430 "class C {", | 430 class C { |
| 431 " final A a;", | 431 final A a; |
| 432 " const C(this.a);", | 432 const C(this.a); |
| 433 "}", | 433 } |
| 434 "var v = const C(const B());"])); | 434 var v = const C(const B());'''); |
| 435 resolve(source); | 435 resolve(source); |
| 436 assertNoErrors(source); | 436 assertNoErrors(source); |
| 437 verify([source]); | 437 verify([source]); |
| 438 } | 438 } |
| 439 | 439 |
| 440 void test_fieldFormalParameterAssignableToField_fieldType_unresolved_null() { | 440 void test_fieldFormalParameterAssignableToField_fieldType_unresolved_null() { |
| 441 // Null always passes runtime type checks, even when the type is | 441 // Null always passes runtime type checks, even when the type is |
| 442 // unresolved. | 442 // unresolved. |
| 443 Source source = addSource(EngineTestCase.createSource([ | 443 Source source = addSource(r''' |
| 444 "class A {", | 444 class A { |
| 445 " final Unresolved x;", | 445 final Unresolved x; |
| 446 " const A(String this.x);", | 446 const A(String this.x); |
| 447 "}", | 447 } |
| 448 "var v = const A(null);"])); | 448 var v = const A(null);'''); |
| 449 resolve(source); | 449 resolve(source); |
| 450 assertErrors(source, [ | 450 assertErrors(source, [ |
| 451 StaticWarningCode.UNDEFINED_CLASS]); | 451 StaticWarningCode.UNDEFINED_CLASS]); |
| 452 verify([source]); | 452 verify([source]); |
| 453 } | 453 } |
| 454 | 454 |
| 455 void test_fieldFormalParameterAssignableToField_implements() { | 455 void test_fieldFormalParameterAssignableToField_implements() { |
| 456 // According to checked-mode type checking rules, a value of type B is | 456 // According to checked-mode type checking rules, a value of type B is |
| 457 // assignable to a field of type A, because B implements A (and hence is a | 457 // assignable to a field of type A, because B implements A (and hence is a |
| 458 // subtype of A). | 458 // subtype of A). |
| 459 Source source = addSource(EngineTestCase.createSource([ | 459 Source source = addSource(r''' |
| 460 "class A {}", | 460 class A {} |
| 461 "class B implements A {", | 461 class B implements A { |
| 462 " const B();", | 462 const B(); |
| 463 "}", | 463 } |
| 464 "class C {", | 464 class C { |
| 465 " final A a;", | 465 final A a; |
| 466 " const C(this.a);", | 466 const C(this.a); |
| 467 "}", | 467 } |
| 468 "var v = const C(const B());"])); | 468 var v = const C(const B());'''); |
| 469 resolve(source); | 469 resolve(source); |
| 470 assertNoErrors(source); | 470 assertNoErrors(source); |
| 471 verify([source]); | 471 verify([source]); |
| 472 } | 472 } |
| 473 | 473 |
| 474 void test_fieldFormalParameterAssignableToField_list_dynamic() { | 474 void test_fieldFormalParameterAssignableToField_list_dynamic() { |
| 475 // [1, 2, 3] has type List<dynamic>, which is a subtype of List<int>. | 475 // [1, 2, 3] has type List<dynamic>, which is a subtype of List<int>. |
| 476 Source source = addSource(EngineTestCase.createSource([ | 476 Source source = addSource(r''' |
| 477 "class A {", | 477 class A { |
| 478 " const A(List<int> x);", | 478 const A(List<int> x); |
| 479 "}", | 479 } |
| 480 "var x = const A(const [1, 2, 3]);"])); | 480 var x = const A(const [1, 2, 3]);'''); |
| 481 resolve(source); | 481 resolve(source); |
| 482 assertNoErrors(source); | 482 assertNoErrors(source); |
| 483 verify([source]); | 483 verify([source]); |
| 484 } | 484 } |
| 485 | 485 |
| 486 void test_fieldFormalParameterAssignableToField_list_nonDynamic() { | 486 void test_fieldFormalParameterAssignableToField_list_nonDynamic() { |
| 487 // <int>[1, 2, 3] has type List<int>, which is a subtype of List<num>. | 487 // <int>[1, 2, 3] has type List<int>, which is a subtype of List<num>. |
| 488 Source source = addSource(EngineTestCase.createSource([ | 488 Source source = addSource(r''' |
| 489 "class A {", | 489 class A { |
| 490 " const A(List<num> x);", | 490 const A(List<num> x); |
| 491 "}", | 491 } |
| 492 "var x = const A(const <int>[1, 2, 3]);"])); | 492 var x = const A(const <int>[1, 2, 3]);'''); |
| 493 resolve(source); | 493 resolve(source); |
| 494 assertNoErrors(source); | 494 assertNoErrors(source); |
| 495 verify([source]); | 495 verify([source]); |
| 496 } | 496 } |
| 497 | 497 |
| 498 void test_fieldFormalParameterAssignableToField_map_dynamic() { | 498 void test_fieldFormalParameterAssignableToField_map_dynamic() { |
| 499 // {1: 2} has type Map<dynamic, dynamic>, which is a subtype of | 499 // {1: 2} has type Map<dynamic, dynamic>, which is a subtype of |
| 500 // Map<int, int>. | 500 // Map<int, int>. |
| 501 Source source = addSource(EngineTestCase.createSource([ | 501 Source source = addSource(r''' |
| 502 "class A {", | 502 class A { |
| 503 " const A(Map<int, int> x);", | 503 const A(Map<int, int> x); |
| 504 "}", | 504 } |
| 505 "var x = const A(const {1: 2});"])); | 505 var x = const A(const {1: 2});'''); |
| 506 resolve(source); | 506 resolve(source); |
| 507 assertNoErrors(source); | 507 assertNoErrors(source); |
| 508 verify([source]); | 508 verify([source]); |
| 509 } | 509 } |
| 510 | 510 |
| 511 void test_fieldFormalParameterAssignableToField_map_keyDifferent() { | 511 void test_fieldFormalParameterAssignableToField_map_keyDifferent() { |
| 512 // <int, int>{1: 2} has type Map<int, int>, which is a subtype of | 512 // <int, int>{1: 2} has type Map<int, int>, which is a subtype of |
| 513 // Map<num, int>. | 513 // Map<num, int>. |
| 514 Source source = addSource(EngineTestCase.createSource([ | 514 Source source = addSource(r''' |
| 515 "class A {", | 515 class A { |
| 516 " const A(Map<num, int> x);", | 516 const A(Map<num, int> x); |
| 517 "}", | 517 } |
| 518 "var x = const A(const <int, int>{1: 2});"])); | 518 var x = const A(const <int, int>{1: 2});'''); |
| 519 resolve(source); | 519 resolve(source); |
| 520 assertNoErrors(source); | 520 assertNoErrors(source); |
| 521 verify([source]); | 521 verify([source]); |
| 522 } | 522 } |
| 523 | 523 |
| 524 void test_fieldFormalParameterAssignableToField_map_valueDifferent() { | 524 void test_fieldFormalParameterAssignableToField_map_valueDifferent() { |
| 525 // <int, int>{1: 2} has type Map<int, int>, which is a subtype of | 525 // <int, int>{1: 2} has type Map<int, int>, which is a subtype of |
| 526 // Map<int, num>. | 526 // Map<int, num>. |
| 527 Source source = addSource(EngineTestCase.createSource([ | 527 Source source = addSource(r''' |
| 528 "class A {", | 528 class A { |
| 529 " const A(Map<int, num> x);", | 529 const A(Map<int, num> x); |
| 530 "}", | 530 } |
| 531 "var x = const A(const <int, int>{1: 2});"])); | 531 var x = const A(const <int, int>{1: 2});'''); |
| 532 resolve(source); | 532 resolve(source); |
| 533 assertNoErrors(source); | 533 assertNoErrors(source); |
| 534 verify([source]); | 534 verify([source]); |
| 535 } | 535 } |
| 536 | 536 |
| 537 void test_fieldFormalParameterAssignableToField_notype() { | 537 void test_fieldFormalParameterAssignableToField_notype() { |
| 538 // If a field is declared without a type, then any value may be assigned to | 538 // If a field is declared without a type, then any value may be assigned to |
| 539 // it. | 539 // it. |
| 540 Source source = addSource(EngineTestCase.createSource([ | 540 Source source = addSource(r''' |
| 541 "class A {", | 541 class A { |
| 542 " final x;", | 542 final x; |
| 543 " const A(this.x);", | 543 const A(this.x); |
| 544 "}", | 544 } |
| 545 "var v = const A(5);"])); | 545 var v = const A(5);'''); |
| 546 resolve(source); | 546 resolve(source); |
| 547 assertNoErrors(source); | 547 assertNoErrors(source); |
| 548 verify([source]); | 548 verify([source]); |
| 549 } | 549 } |
| 550 | 550 |
| 551 void test_fieldFormalParameterAssignableToField_null() { | 551 void test_fieldFormalParameterAssignableToField_null() { |
| 552 // Null is assignable to anything. | 552 // Null is assignable to anything. |
| 553 Source source = addSource(EngineTestCase.createSource([ | 553 Source source = addSource(r''' |
| 554 "class A {", | 554 class A { |
| 555 " final int x;", | 555 final int x; |
| 556 " const A(this.x);", | 556 const A(this.x); |
| 557 "}", | 557 } |
| 558 "var v = const A(null);"])); | 558 var v = const A(null);'''); |
| 559 resolve(source); | 559 resolve(source); |
| 560 assertNoErrors(source); | 560 assertNoErrors(source); |
| 561 verify([source]); | 561 verify([source]); |
| 562 } | 562 } |
| 563 | 563 |
| 564 void test_fieldFormalParameterAssignableToField_typeSubstitution() { | 564 void test_fieldFormalParameterAssignableToField_typeSubstitution() { |
| 565 // foo has the runtime type dynamic -> dynamic, so it should be assignable | 565 // foo has the runtime type dynamic -> dynamic, so it should be assignable |
| 566 // to A.f. | 566 // to A.f. |
| 567 Source source = addSource(EngineTestCase.createSource([ | 567 Source source = addSource(r''' |
| 568 "class A<T> {", | 568 class A<T> { |
| 569 " final T x;", | 569 final T x; |
| 570 " const A(this.x);", | 570 const A(this.x); |
| 571 "}", | 571 } |
| 572 "var v = const A<int>(3);"])); | 572 var v = const A<int>(3);'''); |
| 573 resolve(source); | 573 resolve(source); |
| 574 assertNoErrors(source); | 574 assertNoErrors(source); |
| 575 verify([source]); | 575 verify([source]); |
| 576 } | 576 } |
| 577 | 577 |
| 578 void test_fieldFormalParameterAssignableToField_typedef() { | 578 void test_fieldFormalParameterAssignableToField_typedef() { |
| 579 // foo has the runtime type dynamic -> dynamic, so it should be assignable | 579 // foo has the runtime type dynamic -> dynamic, so it should be assignable |
| 580 // to A.f. | 580 // to A.f. |
| 581 Source source = addSource(EngineTestCase.createSource([ | 581 Source source = addSource(r''' |
| 582 "typedef String Int2String(int x);", | 582 typedef String Int2String(int x); |
| 583 "class A {", | 583 class A { |
| 584 " final Int2String f;", | 584 final Int2String f; |
| 585 " const A(this.f);", | 585 const A(this.f); |
| 586 "}", | 586 } |
| 587 "foo(x) => 1;" | 587 foo(x) => 1; |
| 588 "var v = const A(foo);"])); | 588 var v = const A(foo);'''); |
| 589 resolve(source); | 589 resolve(source); |
| 590 assertNoErrors(source); | 590 assertNoErrors(source); |
| 591 verify([source]); | 591 verify([source]); |
| 592 } | 592 } |
| 593 | 593 |
| 594 void test_fieldFormalParameterNotAssignableToField() { | 594 void test_fieldFormalParameterNotAssignableToField() { |
| 595 Source source = addSource(EngineTestCase.createSource([ | 595 Source source = addSource(r''' |
| 596 "class A {", | 596 class A { |
| 597 " final int x;", | 597 final int x; |
| 598 " const A(this.x);", | 598 const A(this.x); |
| 599 "}", | 599 } |
| 600 "var v = const A('foo');"])); | 600 var v = const A('foo');'''); |
| 601 resolve(source); | 601 resolve(source); |
| 602 assertErrors(source, [ | 602 assertErrors(source, [ |
| 603 CheckedModeCompileTimeErrorCode.CONST_CONSTRUCTOR_PARAM_TYPE_MISMATCH, | 603 CheckedModeCompileTimeErrorCode.CONST_CONSTRUCTOR_PARAM_TYPE_MISMATCH, |
| 604 StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE]); | 604 StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE]); |
| 605 verify([source]); | 605 verify([source]); |
| 606 } | 606 } |
| 607 | 607 |
| 608 void test_fieldFormalParameterNotAssignableToField_fieldType() { | 608 void test_fieldFormalParameterNotAssignableToField_fieldType() { |
| 609 Source source = addSource(EngineTestCase.createSource([ | 609 Source source = addSource(r''' |
| 610 "class A {", | 610 class A { |
| 611 " final int x;", | 611 final int x; |
| 612 " const A(String this.x);", | 612 const A(String this.x); |
| 613 "}", | 613 } |
| 614 "var v = const A('foo');"])); | 614 var v = const A('foo');'''); |
| 615 resolve(source); | 615 resolve(source); |
| 616 assertErrors(source, [ | 616 assertErrors(source, [ |
| 617 CheckedModeCompileTimeErrorCode.CONST_CONSTRUCTOR_PARAM_TYPE_MISMATCH, | 617 CheckedModeCompileTimeErrorCode.CONST_CONSTRUCTOR_PARAM_TYPE_MISMATCH, |
| 618 StaticWarningCode.FIELD_INITIALIZING_FORMAL_NOT_ASSIGNABLE]); | 618 StaticWarningCode.FIELD_INITIALIZING_FORMAL_NOT_ASSIGNABLE]); |
| 619 verify([source]); | 619 verify([source]); |
| 620 } | 620 } |
| 621 | 621 |
| 622 void test_fieldFormalParameterNotAssignableToField_fieldType_unresolved() { | 622 void test_fieldFormalParameterNotAssignableToField_fieldType_unresolved() { |
| 623 Source source = addSource(EngineTestCase.createSource([ | 623 Source source = addSource(r''' |
| 624 "class A {", | 624 class A { |
| 625 " final Unresolved x;", | 625 final Unresolved x; |
| 626 " const A(String this.x);", | 626 const A(String this.x); |
| 627 "}", | 627 } |
| 628 "var v = const A('foo');"])); | 628 var v = const A('foo');'''); |
| 629 resolve(source); | 629 resolve(source); |
| 630 assertErrors(source, [ | 630 assertErrors(source, [ |
| 631 CheckedModeCompileTimeErrorCode.CONST_CONSTRUCTOR_PARAM_TYPE_MISMATCH, | 631 CheckedModeCompileTimeErrorCode.CONST_CONSTRUCTOR_PARAM_TYPE_MISMATCH, |
| 632 StaticWarningCode.UNDEFINED_CLASS]); | 632 StaticWarningCode.UNDEFINED_CLASS]); |
| 633 verify([source]); | 633 verify([source]); |
| 634 } | 634 } |
| 635 | 635 |
| 636 void test_fieldFormalParameterNotAssignableToField_extends() { | 636 void test_fieldFormalParameterNotAssignableToField_extends() { |
| 637 // According to checked-mode type checking rules, a value of type A is not | 637 // According to checked-mode type checking rules, a value of type A is not |
| 638 // assignable to a field of type B, because B extends A (the subtyping | 638 // assignable to a field of type B, because B extends A (the subtyping |
| 639 // relationship is in the wrong direction). | 639 // relationship is in the wrong direction). |
| 640 Source source = addSource(EngineTestCase.createSource([ | 640 Source source = addSource(r''' |
| 641 "class A {", | 641 class A { |
| 642 " const A();", | 642 const A(); |
| 643 "}", | 643 } |
| 644 "class B extends A {", | 644 class B extends A { |
| 645 " const B();", | 645 const B(); |
| 646 "}", | 646 } |
| 647 "class C {", | 647 class C { |
| 648 " final B b;", | 648 final B b; |
| 649 " const C(this.b);", | 649 const C(this.b); |
| 650 "}", | 650 } |
| 651 "var v = const C(const A());"])); | 651 var v = const C(const A());'''); |
| 652 resolve(source); | 652 resolve(source); |
| 653 assertErrors(source, [ | 653 assertErrors(source, [ |
| 654 CheckedModeCompileTimeErrorCode.CONST_CONSTRUCTOR_PARAM_TYPE_MISMATCH]); | 654 CheckedModeCompileTimeErrorCode.CONST_CONSTRUCTOR_PARAM_TYPE_MISMATCH]); |
| 655 verify([source]); | 655 verify([source]); |
| 656 } | 656 } |
| 657 | 657 |
| 658 void test_fieldFormalParameterNotAssignableToField_implements() { | 658 void test_fieldFormalParameterNotAssignableToField_implements() { |
| 659 // According to checked-mode type checking rules, a value of type A is not | 659 // According to checked-mode type checking rules, a value of type A is not |
| 660 // assignable to a field of type B, because B implements A (the subtyping | 660 // assignable to a field of type B, because B implements A (the subtyping |
| 661 // relationship is in the wrong direction). | 661 // relationship is in the wrong direction). |
| 662 Source source = addSource(EngineTestCase.createSource([ | 662 Source source = addSource(r''' |
| 663 "class A {", | 663 class A { |
| 664 " const A();", | 664 const A(); |
| 665 "}", | 665 } |
| 666 "class B implements A {}", | 666 class B implements A {} |
| 667 "class C {", | 667 class C { |
| 668 " final B b;", | 668 final B b; |
| 669 " const C(this.b);", | 669 const C(this.b); |
| 670 "}", | 670 } |
| 671 "var v = const C(const A());"])); | 671 var v = const C(const A());'''); |
| 672 resolve(source); | 672 resolve(source); |
| 673 assertErrors(source, [ | 673 assertErrors(source, [ |
| 674 CheckedModeCompileTimeErrorCode.CONST_CONSTRUCTOR_PARAM_TYPE_MISMATCH]); | 674 CheckedModeCompileTimeErrorCode.CONST_CONSTRUCTOR_PARAM_TYPE_MISMATCH]); |
| 675 verify([source]); | 675 verify([source]); |
| 676 } | 676 } |
| 677 | 677 |
| 678 void test_fieldFormalParameterNotAssignableToField_list() { | 678 void test_fieldFormalParameterNotAssignableToField_list() { |
| 679 // <num>[1, 2, 3] has type List<num>, which is not a subtype of List<int>. | 679 // <num>[1, 2, 3] has type List<num>, which is not a subtype of List<int>. |
| 680 Source source = addSource(EngineTestCase.createSource([ | 680 Source source = addSource(r''' |
| 681 "class A {", | 681 class A { |
| 682 " const A(List<int> x);", | 682 const A(List<int> x); |
| 683 "}", | 683 } |
| 684 "var x = const A(const <num>[1, 2, 3]);"])); | 684 var x = const A(const <num>[1, 2, 3]);'''); |
| 685 resolve(source); | 685 resolve(source); |
| 686 assertErrors(source, [ | 686 assertErrors(source, [ |
| 687 CheckedModeCompileTimeErrorCode.CONST_CONSTRUCTOR_PARAM_TYPE_MISMATCH]); | 687 CheckedModeCompileTimeErrorCode.CONST_CONSTRUCTOR_PARAM_TYPE_MISMATCH]); |
| 688 verify([source]); | 688 verify([source]); |
| 689 } | 689 } |
| 690 | 690 |
| 691 void test_fieldFormalParameterNotAssignableToField_map_keyMismatch() { | 691 void test_fieldFormalParameterNotAssignableToField_map_keyMismatch() { |
| 692 // <num, int>{1: 2} has type Map<num, int>, which is not a subtype of | 692 // <num, int>{1: 2} has type Map<num, int>, which is not a subtype of |
| 693 // Map<int, int>. | 693 // Map<int, int>. |
| 694 Source source = addSource(EngineTestCase.createSource([ | 694 Source source = addSource(r''' |
| 695 "class A {", | 695 class A { |
| 696 " const A(Map<int, int> x);", | 696 const A(Map<int, int> x); |
| 697 "}", | 697 } |
| 698 "var x = const A(const <num, int>{1: 2});"])); | 698 var x = const A(const <num, int>{1: 2});'''); |
| 699 resolve(source); | 699 resolve(source); |
| 700 assertErrors(source, [ | 700 assertErrors(source, [ |
| 701 CheckedModeCompileTimeErrorCode.CONST_CONSTRUCTOR_PARAM_TYPE_MISMATCH]); | 701 CheckedModeCompileTimeErrorCode.CONST_CONSTRUCTOR_PARAM_TYPE_MISMATCH]); |
| 702 verify([source]); | 702 verify([source]); |
| 703 } | 703 } |
| 704 | 704 |
| 705 void test_fieldFormalParameterNotAssignableToField_map_valueMismatch() { | 705 void test_fieldFormalParameterNotAssignableToField_map_valueMismatch() { |
| 706 // <int, num>{1: 2} has type Map<int, num>, which is not a subtype of | 706 // <int, num>{1: 2} has type Map<int, num>, which is not a subtype of |
| 707 // Map<int, int>. | 707 // Map<int, int>. |
| 708 Source source = addSource(EngineTestCase.createSource([ | 708 Source source = addSource(r''' |
| 709 "class A {", | 709 class A { |
| 710 " const A(Map<int, int> x);", | 710 const A(Map<int, int> x); |
| 711 "}", | 711 } |
| 712 "var x = const A(const <int, num>{1: 2});"])); | 712 var x = const A(const <int, num>{1: 2});'''); |
| 713 resolve(source); | 713 resolve(source); |
| 714 assertErrors(source, [ | 714 assertErrors(source, [ |
| 715 CheckedModeCompileTimeErrorCode.CONST_CONSTRUCTOR_PARAM_TYPE_MISMATCH]); | 715 CheckedModeCompileTimeErrorCode.CONST_CONSTRUCTOR_PARAM_TYPE_MISMATCH]); |
| 716 verify([source]); | 716 verify([source]); |
| 717 } | 717 } |
| 718 | 718 |
| 719 void test_fieldFormalParameterNotAssignableToField_optional() { | 719 void test_fieldFormalParameterNotAssignableToField_optional() { |
| 720 Source source = addSource(EngineTestCase.createSource([ | 720 Source source = addSource(r''' |
| 721 "class A {", | 721 class A { |
| 722 " final int x;", | 722 final int x; |
| 723 " const A([this.x = 'foo']);", | 723 const A([this.x = 'foo']); |
| 724 "}", | 724 } |
| 725 "var v = const A();"])); | 725 var v = const A();'''); |
| 726 resolve(source); | 726 resolve(source); |
| 727 assertErrors(source, [ | 727 assertErrors(source, [ |
| 728 CheckedModeCompileTimeErrorCode.CONST_CONSTRUCTOR_PARAM_TYPE_MISMATCH, | 728 CheckedModeCompileTimeErrorCode.CONST_CONSTRUCTOR_PARAM_TYPE_MISMATCH, |
| 729 StaticTypeWarningCode.INVALID_ASSIGNMENT]); | 729 StaticTypeWarningCode.INVALID_ASSIGNMENT]); |
| 730 verify([source]); | 730 verify([source]); |
| 731 } | 731 } |
| 732 | 732 |
| 733 void test_fieldFormalParameterNotAssignableToField_typedef() { | 733 void test_fieldFormalParameterNotAssignableToField_typedef() { |
| 734 // foo has the runtime type String -> int, so it should not be assignable | 734 // foo has the runtime type String -> int, so it should not be assignable |
| 735 // to A.f (A.f requires it to be int -> String). | 735 // to A.f (A.f requires it to be int -> String). |
| 736 Source source = addSource(EngineTestCase.createSource([ | 736 Source source = addSource(r''' |
| 737 "typedef String Int2String(int x);", | 737 typedef String Int2String(int x); |
| 738 "class A {", | 738 class A { |
| 739 " final Int2String f;", | 739 final Int2String f; |
| 740 " const A(this.f);", | 740 const A(this.f); |
| 741 "}", | 741 } |
| 742 "int foo(String x) => 1;" | 742 int foo(String x) => 1; |
| 743 "var v = const A(foo);"])); | 743 var v = const A(foo);'''); |
| 744 resolve(source); | 744 resolve(source); |
| 745 assertErrors(source, [ | 745 assertErrors(source, [ |
| 746 CheckedModeCompileTimeErrorCode.CONST_CONSTRUCTOR_PARAM_TYPE_MISMATCH, | 746 CheckedModeCompileTimeErrorCode.CONST_CONSTRUCTOR_PARAM_TYPE_MISMATCH, |
| 747 StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE]); | 747 StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE]); |
| 748 verify([source]); | 748 verify([source]); |
| 749 } | 749 } |
| 750 | 750 |
| 751 void test_fieldInitializerNotAssignable() { | 751 void test_fieldInitializerNotAssignable() { |
| 752 Source source = addSource(EngineTestCase.createSource([ | 752 Source source = addSource(r''' |
| 753 "class A {", | 753 class A { |
| 754 " final int x;", | 754 final int x; |
| 755 " const A() : x = '';", | 755 const A() : x = ''; |
| 756 "}"])); | 756 }'''); |
| 757 resolve(source); | 757 resolve(source); |
| 758 assertErrors(source, [ | 758 assertErrors(source, [ |
| 759 CheckedModeCompileTimeErrorCode.CONST_FIELD_INITIALIZER_NOT_ASSIGNABLE, | 759 CheckedModeCompileTimeErrorCode.CONST_FIELD_INITIALIZER_NOT_ASSIGNABLE, |
| 760 StaticWarningCode.FIELD_INITIALIZER_NOT_ASSIGNABLE]); | 760 StaticWarningCode.FIELD_INITIALIZER_NOT_ASSIGNABLE]); |
| 761 verify([source]); | 761 verify([source]); |
| 762 } | 762 } |
| 763 | 763 |
| 764 void test_fieldTypeMismatch() { | 764 void test_fieldTypeMismatch() { |
| 765 Source source = addSource(EngineTestCase.createSource([ | 765 Source source = addSource(r''' |
| 766 "class A {", | 766 class A { |
| 767 " const A(x) : y = x;", | 767 const A(x) : y = x; |
| 768 " final int y;", | 768 final int y; |
| 769 "}", | 769 } |
| 770 "var v = const A('foo');"])); | 770 var v = const A('foo');'''); |
| 771 resolve(source); | 771 resolve(source); |
| 772 assertErrors(source, [ | 772 assertErrors(source, [ |
| 773 CheckedModeCompileTimeErrorCode.CONST_CONSTRUCTOR_FIELD_TYPE_MISMATCH]); | 773 CheckedModeCompileTimeErrorCode.CONST_CONSTRUCTOR_FIELD_TYPE_MISMATCH]); |
| 774 verify([source]); | 774 verify([source]); |
| 775 } | 775 } |
| 776 | 776 |
| 777 void test_fieldTypeMismatch_unresolved() { | 777 void test_fieldTypeMismatch_unresolved() { |
| 778 Source source = addSource(EngineTestCase.createSource([ | 778 Source source = addSource(r''' |
| 779 "class A {", | 779 class A { |
| 780 " const A(x) : y = x;", | 780 const A(x) : y = x; |
| 781 " final Unresolved y;", | 781 final Unresolved y; |
| 782 "}", | 782 } |
| 783 "var v = const A('foo');"])); | 783 var v = const A('foo');'''); |
| 784 resolve(source); | 784 resolve(source); |
| 785 assertErrors(source, [ | 785 assertErrors(source, [ |
| 786 CheckedModeCompileTimeErrorCode.CONST_CONSTRUCTOR_FIELD_TYPE_MISMATCH, | 786 CheckedModeCompileTimeErrorCode.CONST_CONSTRUCTOR_FIELD_TYPE_MISMATCH, |
| 787 StaticWarningCode.UNDEFINED_CLASS]); | 787 StaticWarningCode.UNDEFINED_CLASS]); |
| 788 verify([source]); | 788 verify([source]); |
| 789 } | 789 } |
| 790 | 790 |
| 791 void test_fieldTypeOk_null() { | 791 void test_fieldTypeOk_null() { |
| 792 Source source = addSource(EngineTestCase.createSource([ | 792 Source source = addSource(r''' |
| 793 "class A {", | 793 class A { |
| 794 " const A(x) : y = x;", | 794 const A(x) : y = x; |
| 795 " final int y;", | 795 final int y; |
| 796 "}", | 796 } |
| 797 "var v = const A(null);"])); | 797 var v = const A(null);'''); |
| 798 resolve(source); | 798 resolve(source); |
| 799 assertNoErrors(source); | 799 assertNoErrors(source); |
| 800 verify([source]); | 800 verify([source]); |
| 801 } | 801 } |
| 802 | 802 |
| 803 void test_fieldTypeOk_unresolved_null() { | 803 void test_fieldTypeOk_unresolved_null() { |
| 804 // Null always passes runtime type checks, even when the type is | 804 // Null always passes runtime type checks, even when the type is |
| 805 // unresolved. | 805 // unresolved. |
| 806 Source source = addSource(EngineTestCase.createSource([ | 806 Source source = addSource(r''' |
| 807 "class A {", | 807 class A { |
| 808 " const A(x) : y = x;", | 808 const A(x) : y = x; |
| 809 " final Unresolved y;", | 809 final Unresolved y; |
| 810 "}", | 810 } |
| 811 "var v = const A(null);"])); | 811 var v = const A(null);'''); |
| 812 resolve(source); | 812 resolve(source); |
| 813 assertErrors(source, [ | 813 assertErrors(source, [ |
| 814 StaticWarningCode.UNDEFINED_CLASS]); | 814 StaticWarningCode.UNDEFINED_CLASS]); |
| 815 verify([source]); | 815 verify([source]); |
| 816 } | 816 } |
| 817 | 817 |
| 818 void test_listElementTypeNotAssignable() { | 818 void test_listElementTypeNotAssignable() { |
| 819 Source source = addSource(EngineTestCase.createSource(["var v = const <Strin
g> [42];"])); | 819 Source source = addSource("var v = const <String> [42];"); |
| 820 resolve(source); | 820 resolve(source); |
| 821 assertErrors(source, [ | 821 assertErrors(source, [ |
| 822 CheckedModeCompileTimeErrorCode.LIST_ELEMENT_TYPE_NOT_ASSIGNABLE, | 822 CheckedModeCompileTimeErrorCode.LIST_ELEMENT_TYPE_NOT_ASSIGNABLE, |
| 823 StaticWarningCode.LIST_ELEMENT_TYPE_NOT_ASSIGNABLE]); | 823 StaticWarningCode.LIST_ELEMENT_TYPE_NOT_ASSIGNABLE]); |
| 824 verify([source]); | 824 verify([source]); |
| 825 } | 825 } |
| 826 | 826 |
| 827 void test_mapKeyTypeNotAssignable() { | 827 void test_mapKeyTypeNotAssignable() { |
| 828 Source source = addSource(EngineTestCase.createSource(["var v = const <Strin
g, int > {1 : 2};"])); | 828 Source source = addSource("var v = const <String, int > {1 : 2};"); |
| 829 resolve(source); | 829 resolve(source); |
| 830 assertErrors(source, [ | 830 assertErrors(source, [ |
| 831 CheckedModeCompileTimeErrorCode.MAP_KEY_TYPE_NOT_ASSIGNABLE, | 831 CheckedModeCompileTimeErrorCode.MAP_KEY_TYPE_NOT_ASSIGNABLE, |
| 832 StaticWarningCode.MAP_KEY_TYPE_NOT_ASSIGNABLE]); | 832 StaticWarningCode.MAP_KEY_TYPE_NOT_ASSIGNABLE]); |
| 833 verify([source]); | 833 verify([source]); |
| 834 } | 834 } |
| 835 | 835 |
| 836 void test_mapValueTypeNotAssignable() { | 836 void test_mapValueTypeNotAssignable() { |
| 837 Source source = addSource(EngineTestCase.createSource(["var v = const <Strin
g, String> {'a' : 2};"])); | 837 Source source = addSource("var v = const <String, String> {'a' : 2};"); |
| 838 resolve(source); | 838 resolve(source); |
| 839 assertErrors(source, [ | 839 assertErrors(source, [ |
| 840 CheckedModeCompileTimeErrorCode.MAP_VALUE_TYPE_NOT_ASSIGNABLE, | 840 CheckedModeCompileTimeErrorCode.MAP_VALUE_TYPE_NOT_ASSIGNABLE, |
| 841 StaticWarningCode.MAP_VALUE_TYPE_NOT_ASSIGNABLE]); | 841 StaticWarningCode.MAP_VALUE_TYPE_NOT_ASSIGNABLE]); |
| 842 verify([source]); | 842 verify([source]); |
| 843 } | 843 } |
| 844 | 844 |
| 845 void test_redirectingConstructor_paramTypeMismatch() { | 845 void test_redirectingConstructor_paramTypeMismatch() { |
| 846 Source source = addSource(EngineTestCase.createSource([ | 846 Source source = addSource(r''' |
| 847 "class A {", | 847 class A { |
| 848 " const A.a1(x) : this.a2(x);", | 848 const A.a1(x) : this.a2(x); |
| 849 " const A.a2(String x);", | 849 const A.a2(String x); |
| 850 "}", | 850 } |
| 851 "var v = const A.a1(0);"])); | 851 var v = const A.a1(0);'''); |
| 852 resolve(source); | 852 resolve(source); |
| 853 assertErrors(source, [ | 853 assertErrors(source, [ |
| 854 CheckedModeCompileTimeErrorCode.CONST_CONSTRUCTOR_PARAM_TYPE_MISMATCH]); | 854 CheckedModeCompileTimeErrorCode.CONST_CONSTRUCTOR_PARAM_TYPE_MISMATCH]); |
| 855 verify([source]); | 855 verify([source]); |
| 856 } | 856 } |
| 857 | 857 |
| 858 void test_parameterAssignable_null() { | 858 void test_parameterAssignable_null() { |
| 859 // Null is assignable to anything. | 859 // Null is assignable to anything. |
| 860 Source source = addSource(EngineTestCase.createSource([ | 860 Source source = addSource(r''' |
| 861 "class A {", | 861 class A { |
| 862 " const A(int x);", | 862 const A(int x); |
| 863 "}", | 863 } |
| 864 "var v = const A(null);"])); | 864 var v = const A(null);'''); |
| 865 resolve(source); | 865 resolve(source); |
| 866 assertNoErrors(source); | 866 assertNoErrors(source); |
| 867 verify([source]); | 867 verify([source]); |
| 868 } | 868 } |
| 869 | 869 |
| 870 void test_parameterAssignable_undefined_null() { | 870 void test_parameterAssignable_undefined_null() { |
| 871 // Null always passes runtime type checks, even when the type is | 871 // Null always passes runtime type checks, even when the type is |
| 872 // unresolved. | 872 // unresolved. |
| 873 Source source = addSource(EngineTestCase.createSource([ | 873 Source source = addSource(r''' |
| 874 "class A {", | 874 class A { |
| 875 " const A(Unresolved x);", | 875 const A(Unresolved x); |
| 876 "}", | 876 } |
| 877 "var v = const A(null);"])); | 877 var v = const A(null);'''); |
| 878 resolve(source); | 878 resolve(source); |
| 879 assertErrors(source, [ | 879 assertErrors(source, [ |
| 880 StaticWarningCode.UNDEFINED_CLASS]); | 880 StaticWarningCode.UNDEFINED_CLASS]); |
| 881 verify([source]); | 881 verify([source]); |
| 882 } | 882 } |
| 883 | 883 |
| 884 void test_parameterAssignable_typeSubstitution() { | 884 void test_parameterAssignable_typeSubstitution() { |
| 885 Source source = addSource(EngineTestCase.createSource([ | 885 Source source = addSource(r''' |
| 886 "class A<T> {", | 886 class A<T> { |
| 887 " const A(T x);", | 887 const A(T x); |
| 888 "}", | 888 } |
| 889 "var v = const A<int>(3);"])); | 889 var v = const A<int>(3);'''); |
| 890 resolve(source); | 890 resolve(source); |
| 891 assertNoErrors(source); | 891 assertNoErrors(source); |
| 892 verify([source]); | 892 verify([source]); |
| 893 } | 893 } |
| 894 | 894 |
| 895 void test_parameterNotAssignable() { | 895 void test_parameterNotAssignable() { |
| 896 Source source = addSource(EngineTestCase.createSource([ | 896 Source source = addSource(r''' |
| 897 "class A {", | 897 class A { |
| 898 " const A(int x);", | 898 const A(int x); |
| 899 "}", | 899 } |
| 900 "var v = const A('foo');"])); | 900 var v = const A('foo');'''); |
| 901 resolve(source); | 901 resolve(source); |
| 902 assertErrors(source, [ | 902 assertErrors(source, [ |
| 903 CheckedModeCompileTimeErrorCode.CONST_CONSTRUCTOR_PARAM_TYPE_MISMATCH, | 903 CheckedModeCompileTimeErrorCode.CONST_CONSTRUCTOR_PARAM_TYPE_MISMATCH, |
| 904 StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE]); | 904 StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE]); |
| 905 verify([source]); | 905 verify([source]); |
| 906 } | 906 } |
| 907 | 907 |
| 908 void test_parameterNotAssignable_undefined() { | 908 void test_parameterNotAssignable_undefined() { |
| 909 Source source = addSource(EngineTestCase.createSource([ | 909 Source source = addSource(r''' |
| 910 "class A {", | 910 class A { |
| 911 " const A(Unresolved x);", | 911 const A(Unresolved x); |
| 912 "}", | 912 } |
| 913 "var v = const A('foo');"])); | 913 var v = const A('foo');'''); |
| 914 resolve(source); | 914 resolve(source); |
| 915 assertErrors(source, [ | 915 assertErrors(source, [ |
| 916 CheckedModeCompileTimeErrorCode.CONST_CONSTRUCTOR_PARAM_TYPE_MISMATCH, | 916 CheckedModeCompileTimeErrorCode.CONST_CONSTRUCTOR_PARAM_TYPE_MISMATCH, |
| 917 StaticWarningCode.UNDEFINED_CLASS]); | 917 StaticWarningCode.UNDEFINED_CLASS]); |
| 918 verify([source]); | 918 verify([source]); |
| 919 } | 919 } |
| 920 | 920 |
| 921 void test_parameterNotAssignable_typeSubstitution() { | 921 void test_parameterNotAssignable_typeSubstitution() { |
| 922 Source source = addSource(EngineTestCase.createSource([ | 922 Source source = addSource(r''' |
| 923 "class A<T> {", | 923 class A<T> { |
| 924 " const A(T x);", | 924 const A(T x); |
| 925 "}", | 925 } |
| 926 "var v = const A<int>('foo');"])); | 926 var v = const A<int>('foo');'''); |
| 927 resolve(source); | 927 resolve(source); |
| 928 assertErrors(source, [ | 928 assertErrors(source, [ |
| 929 CheckedModeCompileTimeErrorCode.CONST_CONSTRUCTOR_PARAM_TYPE_MISMATCH, | 929 CheckedModeCompileTimeErrorCode.CONST_CONSTRUCTOR_PARAM_TYPE_MISMATCH, |
| 930 StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE]); | 930 StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE]); |
| 931 verify([source]); | 931 verify([source]); |
| 932 } | 932 } |
| 933 | 933 |
| 934 void test_topLevelVarAssignable_null() { | 934 void test_topLevelVarAssignable_null() { |
| 935 Source source = addSource(EngineTestCase.createSource([ | 935 Source source = addSource("const int x = null;"); |
| 936 "const int x = null;"])); | |
| 937 resolve(source); | 936 resolve(source); |
| 938 assertNoErrors(source); | 937 assertNoErrors(source); |
| 939 verify([source]); | 938 verify([source]); |
| 940 } | 939 } |
| 941 | 940 |
| 942 void test_topLevelVarAssignable_undefined_null() { | 941 void test_topLevelVarAssignable_undefined_null() { |
| 943 // Null always passes runtime type checks, even when the type is | 942 // Null always passes runtime type checks, even when the type is |
| 944 // unresolved. | 943 // unresolved. |
| 945 Source source = addSource(EngineTestCase.createSource([ | 944 Source source = addSource("const Unresolved x = null;"); |
| 946 "const Unresolved x = null;"])); | |
| 947 resolve(source); | 945 resolve(source); |
| 948 assertErrors(source, [ | 946 assertErrors(source, [ |
| 949 StaticWarningCode.UNDEFINED_CLASS]); | 947 StaticWarningCode.UNDEFINED_CLASS]); |
| 950 verify([source]); | 948 verify([source]); |
| 951 } | 949 } |
| 952 | 950 |
| 953 void test_topLevelVarNotAssignable() { | 951 void test_topLevelVarNotAssignable() { |
| 954 Source source = addSource(EngineTestCase.createSource([ | 952 Source source = addSource("const int x = 'foo';"); |
| 955 "const int x = 'foo';"])); | |
| 956 resolve(source); | 953 resolve(source); |
| 957 assertErrors(source, [ | 954 assertErrors(source, [ |
| 958 CheckedModeCompileTimeErrorCode.VARIABLE_TYPE_MISMATCH, | 955 CheckedModeCompileTimeErrorCode.VARIABLE_TYPE_MISMATCH, |
| 959 StaticTypeWarningCode.INVALID_ASSIGNMENT]); | 956 StaticTypeWarningCode.INVALID_ASSIGNMENT]); |
| 960 verify([source]); | 957 verify([source]); |
| 961 } | 958 } |
| 962 | 959 |
| 963 void test_topLevelVarNotAssignable_undefined() { | 960 void test_topLevelVarNotAssignable_undefined() { |
| 964 Source source = addSource(EngineTestCase.createSource([ | 961 Source source = addSource("const Unresolved x = 'foo';"); |
| 965 "const Unresolved x = 'foo';"])); | |
| 966 resolve(source); | 962 resolve(source); |
| 967 assertErrors(source, [ | 963 assertErrors(source, [ |
| 968 CheckedModeCompileTimeErrorCode.VARIABLE_TYPE_MISMATCH, | 964 CheckedModeCompileTimeErrorCode.VARIABLE_TYPE_MISMATCH, |
| 969 StaticWarningCode.UNDEFINED_CLASS]); | 965 StaticWarningCode.UNDEFINED_CLASS]); |
| 970 verify([source]); | 966 verify([source]); |
| 971 } | 967 } |
| 972 } | 968 } |
| 973 | 969 |
| 974 class DeclarationMatcherTest extends ResolverTestCase { | 970 class DeclarationMatcherTest extends ResolverTestCase { |
| 975 void test_compilationUnitMatches_false_topLevelVariable() { | 971 void test_compilationUnitMatches_false_topLevelVariable() { |
| 976 _assertCompilationUnitMatches(false, EngineTestCase.createSource([ | 972 _assertCompilationUnitMatches(false, r''' |
| 977 "class C {", | 973 class C { |
| 978 " int m(int p) {", | 974 int m(int p) { |
| 979 " return p + p;", | 975 return p + p; |
| 980 " }", | 976 } |
| 981 "}"]), EngineTestCase.createSource([ | 977 }''', r''' |
| 982 "const int ZERO = 0;", | 978 const int ZERO = 0; |
| 983 "class C {", | 979 class C { |
| 984 " int m(int p) {", | 980 int m(int p) { |
| 985 " return (p * p) + (p * p) + ZERO;", | 981 return (p * p) + (p * p) + ZERO; |
| 986 " }", | 982 } |
| 987 "}"])); | 983 }'''); |
| 988 } | 984 } |
| 989 | 985 |
| 990 void test_compilationUnitMatches_true_different() { | 986 void test_compilationUnitMatches_true_different() { |
| 991 _assertCompilationUnitMatches(true, EngineTestCase.createSource([ | 987 _assertCompilationUnitMatches(true, r''' |
| 992 "class C {", | 988 class C { |
| 993 " int m(int p) {", | 989 int m(int p) { |
| 994 " return p + p;", | 990 return p + p; |
| 995 " }", | 991 } |
| 996 "}"]), EngineTestCase.createSource([ | 992 }''', r''' |
| 997 "class C {", | 993 class C { |
| 998 " int m(int p) {", | 994 int m(int p) { |
| 999 " return (p * p) + (p * p);", | 995 return (p * p) + (p * p); |
| 1000 " }", | 996 } |
| 1001 "}"])); | 997 }'''); |
| 1002 } | 998 } |
| 1003 | 999 |
| 1004 void test_compilationUnitMatches_true_same() { | 1000 void test_compilationUnitMatches_true_same() { |
| 1005 String content = EngineTestCase.createSource([ | 1001 String content = r''' |
| 1006 "class C {", | 1002 class C { |
| 1007 " int m(int p) {", | 1003 int m(int p) { |
| 1008 " return p + p;", | 1004 return p + p; |
| 1009 " }", | 1005 } |
| 1010 "}"]); | 1006 }'''; |
| 1011 _assertCompilationUnitMatches(true, content, content); | 1007 _assertCompilationUnitMatches(true, content, content); |
| 1012 } | 1008 } |
| 1013 | 1009 |
| 1014 void test_methodDeclarationMatches_false_localVariable() { | 1010 void test_methodDeclarationMatches_false_localVariable() { |
| 1015 _assertMethodMatches(false, EngineTestCase.createSource([ | 1011 _assertMethodMatches(false, r''' |
| 1016 "class C {", | 1012 class C { |
| 1017 " int m(int p) {", | 1013 int m(int p) { |
| 1018 " return p + p;", | 1014 return p + p; |
| 1019 " }", | 1015 } |
| 1020 "}"]), EngineTestCase.createSource([ | 1016 }''', r''' |
| 1021 "class C {", | 1017 class C { |
| 1022 " int m(int p) {", | 1018 int m(int p) { |
| 1023 " int product = p * p;", | 1019 int product = p * p; |
| 1024 " return product + product;", | 1020 return product + product; |
| 1025 " }", | 1021 } |
| 1026 "}"])); | 1022 }'''); |
| 1027 } | 1023 } |
| 1028 | 1024 |
| 1029 void test_methodDeclarationMatches_false_parameter() { | 1025 void test_methodDeclarationMatches_false_parameter() { |
| 1030 _assertMethodMatches(false, EngineTestCase.createSource([ | 1026 _assertMethodMatches(false, r''' |
| 1031 "class C {", | 1027 class C { |
| 1032 " int m(int p) {", | 1028 int m(int p) { |
| 1033 " return p + p;", | 1029 return p + p; |
| 1034 " }", | 1030 } |
| 1035 "}"]), EngineTestCase.createSource([ | 1031 }''', r''' |
| 1036 "class C {", | 1032 class C { |
| 1037 " int m(int p, int q) {", | 1033 int m(int p, int q) { |
| 1038 " return (p * q) + (q * p);", | 1034 return (p * q) + (q * p); |
| 1039 " }", | 1035 } |
| 1040 "}"])); | 1036 }'''); |
| 1041 } | 1037 } |
| 1042 | 1038 |
| 1043 void test_methodDeclarationMatches_true_different() { | 1039 void test_methodDeclarationMatches_true_different() { |
| 1044 _assertMethodMatches(true, EngineTestCase.createSource([ | 1040 _assertMethodMatches(true, r''' |
| 1045 "class C {", | 1041 class C { |
| 1046 " int m(int p) {", | 1042 int m(int p) { |
| 1047 " return p + p;", | 1043 return p + p; |
| 1048 " }", | 1044 } |
| 1049 "}"]), EngineTestCase.createSource([ | 1045 }''', r''' |
| 1050 "class C {", | 1046 class C { |
| 1051 " int m(int p) {", | 1047 int m(int p) { |
| 1052 " return (p * p) + (p * p);", | 1048 return (p * p) + (p * p); |
| 1053 " }", | 1049 } |
| 1054 "}"])); | 1050 }'''); |
| 1055 } | 1051 } |
| 1056 | 1052 |
| 1057 void test_methodDeclarationMatches_true_same() { | 1053 void test_methodDeclarationMatches_true_same() { |
| 1058 String content = EngineTestCase.createSource([ | 1054 String content = r''' |
| 1059 "class C {", | 1055 class C { |
| 1060 " int m(int p) {", | 1056 int m(int p) { |
| 1061 " return p + p;", | 1057 return p + p; |
| 1062 " }", | 1058 } |
| 1063 "}"]); | 1059 }'''; |
| 1064 _assertMethodMatches(true, content, content); | 1060 _assertMethodMatches(true, content, content); |
| 1065 } | 1061 } |
| 1066 | 1062 |
| 1067 void _assertCompilationUnitMatches(bool expectMatch, String oldContent, String
newContent) { | 1063 void _assertCompilationUnitMatches(bool expectMatch, String oldContent, String
newContent) { |
| 1068 Source source = addSource(oldContent); | 1064 Source source = addSource(oldContent); |
| 1069 LibraryElement library = resolve(source); | 1065 LibraryElement library = resolve(source); |
| 1070 CompilationUnit oldUnit = resolveCompilationUnit(source, library); | 1066 CompilationUnit oldUnit = resolveCompilationUnit(source, library); |
| 1071 AnalysisContext context = analysisContext; | 1067 AnalysisContext context = analysisContext; |
| 1072 context.setContents(source, newContent); | 1068 context.setContents(source, newContent); |
| 1073 CompilationUnit newUnit = context.parseCompilationUnit(source); | 1069 CompilationUnit newUnit = context.parseCompilationUnit(source); |
| (...skipping 807 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1881 VariableElement element1 = ElementFactory.localVariableElement(AstFactory.id
entifier3("v1")); | 1877 VariableElement element1 = ElementFactory.localVariableElement(AstFactory.id
entifier3("v1")); |
| 1882 VariableElement element2 = ElementFactory.localVariableElement(AstFactory.id
entifier3("v2")); | 1878 VariableElement element2 = ElementFactory.localVariableElement(AstFactory.id
entifier3("v2")); |
| 1883 outerScope.define(element1); | 1879 outerScope.define(element1); |
| 1884 innerScope.define(element2); | 1880 innerScope.define(element2); |
| 1885 listener.assertNoErrors(); | 1881 listener.assertNoErrors(); |
| 1886 } | 1882 } |
| 1887 } | 1883 } |
| 1888 | 1884 |
| 1889 class ErrorResolverTest extends ResolverTestCase { | 1885 class ErrorResolverTest extends ResolverTestCase { |
| 1890 void test_breakLabelOnSwitchMember() { | 1886 void test_breakLabelOnSwitchMember() { |
| 1891 Source source = addSource(EngineTestCase.createSource([ | 1887 Source source = addSource(r''' |
| 1892 "class A {", | 1888 class A { |
| 1893 " void m(int i) {", | 1889 void m(int i) { |
| 1894 " switch (i) {", | 1890 switch (i) { |
| 1895 " l: case 0:", | 1891 l: case 0: |
| 1896 " break;", | 1892 break; |
| 1897 " case 1:", | 1893 case 1: |
| 1898 " break l;", | 1894 break l; |
| 1899 " }", | 1895 } |
| 1900 " }", | 1896 } |
| 1901 "}"])); | 1897 }'''); |
| 1902 resolve(source); | 1898 resolve(source); |
| 1903 assertErrors(source, [ResolverErrorCode.BREAK_LABEL_ON_SWITCH_MEMBER]); | 1899 assertErrors(source, [ResolverErrorCode.BREAK_LABEL_ON_SWITCH_MEMBER]); |
| 1904 verify([source]); | 1900 verify([source]); |
| 1905 } | 1901 } |
| 1906 | 1902 |
| 1907 void test_continueLabelOnSwitch() { | 1903 void test_continueLabelOnSwitch() { |
| 1908 Source source = addSource(EngineTestCase.createSource([ | 1904 Source source = addSource(r''' |
| 1909 "class A {", | 1905 class A { |
| 1910 " void m(int i) {", | 1906 void m(int i) { |
| 1911 " l: switch (i) {", | 1907 l: switch (i) { |
| 1912 " case 0:", | 1908 case 0: |
| 1913 " continue l;", | 1909 continue l; |
| 1914 " }", | 1910 } |
| 1915 " }", | 1911 } |
| 1916 "}"])); | 1912 }'''); |
| 1917 resolve(source); | 1913 resolve(source); |
| 1918 assertErrors(source, [ResolverErrorCode.CONTINUE_LABEL_ON_SWITCH]); | 1914 assertErrors(source, [ResolverErrorCode.CONTINUE_LABEL_ON_SWITCH]); |
| 1919 verify([source]); | 1915 verify([source]); |
| 1920 } | 1916 } |
| 1921 | 1917 |
| 1922 void test_enclosingElement_invalidLocalFunction() { | 1918 void test_enclosingElement_invalidLocalFunction() { |
| 1923 Source source = addSource(EngineTestCase.createSource([ | 1919 Source source = addSource(r''' |
| 1924 "class C {", | 1920 class C { |
| 1925 " C() {", | 1921 C() { |
| 1926 " int get x => 0;", | 1922 int get x => 0; |
| 1927 " }", | 1923 } |
| 1928 "}"])); | 1924 }'''); |
| 1929 LibraryElement library = resolve(source); | 1925 LibraryElement library = resolve(source); |
| 1930 JUnitTestCase.assertNotNull(library); | 1926 JUnitTestCase.assertNotNull(library); |
| 1931 var unit = library.definingCompilationUnit; | 1927 var unit = library.definingCompilationUnit; |
| 1932 JUnitTestCase.assertNotNull(unit); | 1928 JUnitTestCase.assertNotNull(unit); |
| 1933 var types = unit.types; | 1929 var types = unit.types; |
| 1934 JUnitTestCase.assertNotNull(types); | 1930 JUnitTestCase.assertNotNull(types); |
| 1935 EngineTestCase.assertSizeOfList(1, types); | 1931 EngineTestCase.assertSizeOfList(1, types); |
| 1936 var type = types[0]; | 1932 var type = types[0]; |
| 1937 JUnitTestCase.assertNotNull(type); | 1933 JUnitTestCase.assertNotNull(type); |
| 1938 var constructors = type.constructors; | 1934 var constructors = type.constructors; |
| 1939 JUnitTestCase.assertNotNull(constructors); | 1935 JUnitTestCase.assertNotNull(constructors); |
| 1940 EngineTestCase.assertSizeOfList(1, constructors); | 1936 EngineTestCase.assertSizeOfList(1, constructors); |
| 1941 ConstructorElement constructor = constructors[0]; | 1937 ConstructorElement constructor = constructors[0]; |
| 1942 JUnitTestCase.assertNotNull(constructor); | 1938 JUnitTestCase.assertNotNull(constructor); |
| 1943 List<FunctionElement> functions = constructor.functions; | 1939 List<FunctionElement> functions = constructor.functions; |
| 1944 JUnitTestCase.assertNotNull(functions); | 1940 JUnitTestCase.assertNotNull(functions); |
| 1945 EngineTestCase.assertSizeOfList(1, functions); | 1941 EngineTestCase.assertSizeOfList(1, functions); |
| 1946 JUnitTestCase.assertEquals(constructor, functions[0].enclosingElement); | 1942 JUnitTestCase.assertEquals(constructor, functions[0].enclosingElement); |
| 1947 assertErrors(source, [ParserErrorCode.GETTER_IN_FUNCTION]); | 1943 assertErrors(source, [ParserErrorCode.GETTER_IN_FUNCTION]); |
| 1948 } | 1944 } |
| 1949 } | 1945 } |
| 1950 | 1946 |
| 1951 class HintCodeTest extends ResolverTestCase { | 1947 class HintCodeTest extends ResolverTestCase { |
| 1952 void fail_deadCode_statementAfterRehrow() { | 1948 void fail_deadCode_statementAfterRehrow() { |
| 1953 Source source = addSource(EngineTestCase.createSource([ | 1949 Source source = addSource(r''' |
| 1954 "f() {", | 1950 f() { |
| 1955 " try {", | 1951 try { |
| 1956 " var one = 1;", | 1952 var one = 1; |
| 1957 " } catch (e) {", | 1953 } catch (e) { |
| 1958 " rethrow;", | 1954 rethrow; |
| 1959 " var two = 2;", | 1955 var two = 2; |
| 1960 " }", | 1956 } |
| 1961 "}"])); | 1957 }'''); |
| 1962 resolve(source); | 1958 resolve(source); |
| 1963 assertErrors(source, [HintCode.DEAD_CODE]); | 1959 assertErrors(source, [HintCode.DEAD_CODE]); |
| 1964 verify([source]); | 1960 verify([source]); |
| 1965 } | 1961 } |
| 1966 | 1962 |
| 1967 void fail_deadCode_statementAfterThrow() { | 1963 void fail_deadCode_statementAfterThrow() { |
| 1968 Source source = addSource(EngineTestCase.createSource([ | 1964 Source source = addSource(r''' |
| 1969 "f() {", | 1965 f() { |
| 1970 " var one = 1;", | 1966 var one = 1; |
| 1971 " throw 'Stop here';", | 1967 throw 'Stop here'; |
| 1972 " var two = 2;", | 1968 var two = 2; |
| 1973 "}"])); | 1969 }'''); |
| 1974 resolve(source); | 1970 resolve(source); |
| 1975 assertErrors(source, [HintCode.DEAD_CODE]); | 1971 assertErrors(source, [HintCode.DEAD_CODE]); |
| 1976 verify([source]); | 1972 verify([source]); |
| 1977 } | 1973 } |
| 1978 | 1974 |
| 1979 void fail_isInt() { | 1975 void fail_isInt() { |
| 1980 Source source = addSource(EngineTestCase.createSource(["var v = 1 is int;"])
); | 1976 Source source = addSource("var v = 1 is int;"); |
| 1981 resolve(source); | 1977 resolve(source); |
| 1982 assertErrors(source, [HintCode.IS_INT]); | 1978 assertErrors(source, [HintCode.IS_INT]); |
| 1983 verify([source]); | 1979 verify([source]); |
| 1984 } | 1980 } |
| 1985 | 1981 |
| 1986 void fail_isNotInt() { | 1982 void fail_isNotInt() { |
| 1987 Source source = addSource(EngineTestCase.createSource(["var v = 1 is! int;"]
)); | 1983 Source source = addSource("var v = 1 is! int;"); |
| 1988 resolve(source); | 1984 resolve(source); |
| 1989 assertErrors(source, [HintCode.IS_NOT_INT]); | 1985 assertErrors(source, [HintCode.IS_NOT_INT]); |
| 1990 verify([source]); | 1986 verify([source]); |
| 1991 } | 1987 } |
| 1992 | 1988 |
| 1993 void fail_overrideEqualsButNotHashCode() { | 1989 void fail_overrideEqualsButNotHashCode() { |
| 1994 Source source = addSource(EngineTestCase.createSource(["class A {", " bool
operator ==(x) {}", "}"])); | 1990 Source source = addSource(r''' |
| 1991 class A { |
| 1992 bool operator ==(x) {} |
| 1993 }'''); |
| 1995 resolve(source); | 1994 resolve(source); |
| 1996 assertErrors(source, [HintCode.OVERRIDE_EQUALS_BUT_NOT_HASH_CODE]); | 1995 assertErrors(source, [HintCode.OVERRIDE_EQUALS_BUT_NOT_HASH_CODE]); |
| 1997 verify([source]); | 1996 verify([source]); |
| 1998 } | 1997 } |
| 1999 | 1998 |
| 2000 void fail_unusedImport_as_equalPrefixes() { | 1999 void fail_unusedImport_as_equalPrefixes() { |
| 2001 // See todo at ImportsVerifier.prefixElementMap. | 2000 // See todo at ImportsVerifier.prefixElementMap. |
| 2002 Source source = addSource(EngineTestCase.createSource([ | 2001 Source source = addSource(r''' |
| 2003 "library L;", | 2002 library L; |
| 2004 "import 'lib1.dart' as one;", | 2003 import 'lib1.dart' as one; |
| 2005 "import 'lib2.dart' as one;", | 2004 import 'lib2.dart' as one; |
| 2006 "one.A a;"])); | 2005 one.A a;'''); |
| 2007 Source source2 = addNamedSource("/lib1.dart", EngineTestCase.createSource(["
library lib1;", "class A {}"])); | 2006 Source source2 = addNamedSource("/lib1.dart", r''' |
| 2008 Source source3 = addNamedSource("/lib2.dart", EngineTestCase.createSource(["
library lib2;", "class B {}"])); | 2007 library lib1; |
| 2008 class A {}'''); |
| 2009 Source source3 = addNamedSource("/lib2.dart", r''' |
| 2010 library lib2; |
| 2011 class B {}'''); |
| 2009 resolve(source); | 2012 resolve(source); |
| 2010 assertErrors(source, [HintCode.UNUSED_IMPORT]); | 2013 assertErrors(source, [HintCode.UNUSED_IMPORT]); |
| 2011 assertNoErrors(source2); | 2014 assertNoErrors(source2); |
| 2012 assertNoErrors(source3); | 2015 assertNoErrors(source3); |
| 2013 verify([source, source2, source3]); | 2016 verify([source, source2, source3]); |
| 2014 } | 2017 } |
| 2015 | 2018 |
| 2016 void test_argumentTypeNotAssignable_functionType() { | 2019 void test_argumentTypeNotAssignable_functionType() { |
| 2017 Source source = addSource(EngineTestCase.createSource([ | 2020 Source source = addSource(r''' |
| 2018 "m() {", | 2021 m() { |
| 2019 " var a = new A();", | 2022 var a = new A(); |
| 2020 " a.n(() => 0);", | 2023 a.n(() => 0); |
| 2021 "}", | 2024 } |
| 2022 "class A {", | 2025 class A { |
| 2023 " n(void f(int i)) {}", | 2026 n(void f(int i)) {} |
| 2024 "}"])); | 2027 }'''); |
| 2025 resolve(source); | 2028 resolve(source); |
| 2026 assertErrors(source, [HintCode.ARGUMENT_TYPE_NOT_ASSIGNABLE]); | 2029 assertErrors(source, [HintCode.ARGUMENT_TYPE_NOT_ASSIGNABLE]); |
| 2027 verify([source]); | 2030 verify([source]); |
| 2028 } | 2031 } |
| 2029 | 2032 |
| 2030 void test_argumentTypeNotAssignable_message() { | 2033 void test_argumentTypeNotAssignable_message() { |
| 2031 // The implementation of HintCode.ARGUMENT_TYPE_NOT_ASSIGNABLE assumes that | 2034 // The implementation of HintCode.ARGUMENT_TYPE_NOT_ASSIGNABLE assumes that |
| 2032 // StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE has the same message. | 2035 // StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE has the same message. |
| 2033 JUnitTestCase.assertEquals(HintCode.ARGUMENT_TYPE_NOT_ASSIGNABLE.message, St
aticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE.message); | 2036 JUnitTestCase.assertEquals(HintCode.ARGUMENT_TYPE_NOT_ASSIGNABLE.message, St
aticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE.message); |
| 2034 } | 2037 } |
| 2035 | 2038 |
| 2036 void test_argumentTypeNotAssignable_type() { | 2039 void test_argumentTypeNotAssignable_type() { |
| 2037 Source source = addSource(EngineTestCase.createSource(["m() {", " var i = '
';", " n(i);", "}", "n(int i) {}"])); | 2040 Source source = addSource(r''' |
| 2041 m() { |
| 2042 var i = ''; |
| 2043 n(i); |
| 2044 } |
| 2045 n(int i) {}'''); |
| 2038 resolve(source); | 2046 resolve(source); |
| 2039 assertErrors(source, [HintCode.ARGUMENT_TYPE_NOT_ASSIGNABLE]); | 2047 assertErrors(source, [HintCode.ARGUMENT_TYPE_NOT_ASSIGNABLE]); |
| 2040 verify([source]); | 2048 verify([source]); |
| 2041 } | 2049 } |
| 2042 | 2050 |
| 2043 void test_argumentTypeNotAssignable_unionTypeMethodMerge() { | 2051 void test_argumentTypeNotAssignable_unionTypeMethodMerge() { |
| 2044 enableUnionTypes(false); | 2052 enableUnionTypes(false); |
| 2045 Source source = addSource(EngineTestCase.createSource([ | 2053 Source source = addSource(r''' |
| 2046 "class A {", | 2054 class A { |
| 2047 " int m(int x) => 0;", | 2055 int m(int x) => 0; |
| 2048 "}", | 2056 } |
| 2049 "class B {", | 2057 class B { |
| 2050 " String m(String x) => '0';", | 2058 String m(String x) => '0'; |
| 2051 "}", | 2059 } |
| 2052 "f(A a, B b) {", | 2060 f(A a, B b) { |
| 2053 " var ab;", | 2061 var ab; |
| 2054 " if (0 < 1) {", | 2062 if (0 < 1) { |
| 2055 " ab = a;", | 2063 ab = a; |
| 2056 " } else {", | 2064 } else { |
| 2057 " ab = b;", | 2065 ab = b; |
| 2058 " }", | 2066 } |
| 2059 " ab.m(0.5);", | 2067 ab.m(0.5); |
| 2060 "}"])); | 2068 }'''); |
| 2061 resolve(source); | 2069 resolve(source); |
| 2062 assertErrors(source, [HintCode.ARGUMENT_TYPE_NOT_ASSIGNABLE]); | 2070 assertErrors(source, [HintCode.ARGUMENT_TYPE_NOT_ASSIGNABLE]); |
| 2063 verify([source]); | 2071 verify([source]); |
| 2064 } | 2072 } |
| 2065 | 2073 |
| 2066 void test_deadCode_deadBlock_conditionalElse() { | 2074 void test_deadCode_deadBlock_conditionalElse() { |
| 2067 Source source = addSource(EngineTestCase.createSource(["f() {", " true ? 1
: 2;", "}"])); | 2075 Source source = addSource(r''' |
| 2076 f() { |
| 2077 true ? 1 : 2; |
| 2078 }'''); |
| 2068 resolve(source); | 2079 resolve(source); |
| 2069 assertErrors(source, [HintCode.DEAD_CODE]); | 2080 assertErrors(source, [HintCode.DEAD_CODE]); |
| 2070 verify([source]); | 2081 verify([source]); |
| 2071 } | 2082 } |
| 2072 | 2083 |
| 2073 void test_deadCode_deadBlock_conditionalElse_nested() { | 2084 void test_deadCode_deadBlock_conditionalElse_nested() { |
| 2074 // test that a dead else-statement can't generate additional violations | 2085 // test that a dead else-statement can't generate additional violations |
| 2075 Source source = addSource(EngineTestCase.createSource(["f() {", " true ? tr
ue : false && false;", "}"])); | 2086 Source source = addSource(r''' |
| 2087 f() { |
| 2088 true ? true : false && false; |
| 2089 }'''); |
| 2076 resolve(source); | 2090 resolve(source); |
| 2077 assertErrors(source, [HintCode.DEAD_CODE]); | 2091 assertErrors(source, [HintCode.DEAD_CODE]); |
| 2078 verify([source]); | 2092 verify([source]); |
| 2079 } | 2093 } |
| 2080 | 2094 |
| 2081 void test_deadCode_deadBlock_conditionalIf() { | 2095 void test_deadCode_deadBlock_conditionalIf() { |
| 2082 Source source = addSource(EngineTestCase.createSource(["f() {", " false ? 1
: 2;", "}"])); | 2096 Source source = addSource(r''' |
| 2097 f() { |
| 2098 false ? 1 : 2; |
| 2099 }'''); |
| 2083 resolve(source); | 2100 resolve(source); |
| 2084 assertErrors(source, [HintCode.DEAD_CODE]); | 2101 assertErrors(source, [HintCode.DEAD_CODE]); |
| 2085 verify([source]); | 2102 verify([source]); |
| 2086 } | 2103 } |
| 2087 | 2104 |
| 2088 void test_deadCode_deadBlock_conditionalIf_nested() { | 2105 void test_deadCode_deadBlock_conditionalIf_nested() { |
| 2089 // test that a dead then-statement can't generate additional violations | 2106 // test that a dead then-statement can't generate additional violations |
| 2090 Source source = addSource(EngineTestCase.createSource(["f() {", " false ? f
alse && false : true;", "}"])); | 2107 Source source = addSource(r''' |
| 2108 f() { |
| 2109 false ? false && false : true; |
| 2110 }'''); |
| 2091 resolve(source); | 2111 resolve(source); |
| 2092 assertErrors(source, [HintCode.DEAD_CODE]); | 2112 assertErrors(source, [HintCode.DEAD_CODE]); |
| 2093 verify([source]); | 2113 verify([source]); |
| 2094 } | 2114 } |
| 2095 | 2115 |
| 2096 void test_deadCode_deadBlock_else() { | 2116 void test_deadCode_deadBlock_else() { |
| 2097 Source source = addSource(EngineTestCase.createSource(["f() {", " if(true)
{} else {}", "}"])); | 2117 Source source = addSource(r''' |
| 2118 f() { |
| 2119 if(true) {} else {} |
| 2120 }'''); |
| 2098 resolve(source); | 2121 resolve(source); |
| 2099 assertErrors(source, [HintCode.DEAD_CODE]); | 2122 assertErrors(source, [HintCode.DEAD_CODE]); |
| 2100 verify([source]); | 2123 verify([source]); |
| 2101 } | 2124 } |
| 2102 | 2125 |
| 2103 void test_deadCode_deadBlock_else_nested() { | 2126 void test_deadCode_deadBlock_else_nested() { |
| 2104 // test that a dead else-statement can't generate additional violations | 2127 // test that a dead else-statement can't generate additional violations |
| 2105 Source source = addSource(EngineTestCase.createSource(["f() {", " if(true)
{} else {if (false) {}}", "}"])); | 2128 Source source = addSource(r''' |
| 2129 f() { |
| 2130 if(true) {} else {if (false) {}} |
| 2131 }'''); |
| 2106 resolve(source); | 2132 resolve(source); |
| 2107 assertErrors(source, [HintCode.DEAD_CODE]); | 2133 assertErrors(source, [HintCode.DEAD_CODE]); |
| 2108 verify([source]); | 2134 verify([source]); |
| 2109 } | 2135 } |
| 2110 | 2136 |
| 2111 void test_deadCode_deadBlock_if() { | 2137 void test_deadCode_deadBlock_if() { |
| 2112 Source source = addSource(EngineTestCase.createSource(["f() {", " if(false)
{}", "}"])); | 2138 Source source = addSource(r''' |
| 2139 f() { |
| 2140 if(false) {} |
| 2141 }'''); |
| 2113 resolve(source); | 2142 resolve(source); |
| 2114 assertErrors(source, [HintCode.DEAD_CODE]); | 2143 assertErrors(source, [HintCode.DEAD_CODE]); |
| 2115 verify([source]); | 2144 verify([source]); |
| 2116 } | 2145 } |
| 2117 | 2146 |
| 2118 void test_deadCode_deadBlock_if_nested() { | 2147 void test_deadCode_deadBlock_if_nested() { |
| 2119 // test that a dead then-statement can't generate additional violations | 2148 // test that a dead then-statement can't generate additional violations |
| 2120 Source source = addSource(EngineTestCase.createSource(["f() {", " if(false)
{if(false) {}}", "}"])); | 2149 Source source = addSource(r''' |
| 2150 f() { |
| 2151 if(false) {if(false) {}} |
| 2152 }'''); |
| 2121 resolve(source); | 2153 resolve(source); |
| 2122 assertErrors(source, [HintCode.DEAD_CODE]); | 2154 assertErrors(source, [HintCode.DEAD_CODE]); |
| 2123 verify([source]); | 2155 verify([source]); |
| 2124 } | 2156 } |
| 2125 | 2157 |
| 2126 void test_deadCode_deadBlock_while() { | 2158 void test_deadCode_deadBlock_while() { |
| 2127 Source source = addSource(EngineTestCase.createSource(["f() {", " while(fal
se) {}", "}"])); | 2159 Source source = addSource(r''' |
| 2160 f() { |
| 2161 while(false) {} |
| 2162 }'''); |
| 2128 resolve(source); | 2163 resolve(source); |
| 2129 assertErrors(source, [HintCode.DEAD_CODE]); | 2164 assertErrors(source, [HintCode.DEAD_CODE]); |
| 2130 verify([source]); | 2165 verify([source]); |
| 2131 } | 2166 } |
| 2132 | 2167 |
| 2133 void test_deadCode_deadBlock_while_nested() { | 2168 void test_deadCode_deadBlock_while_nested() { |
| 2134 // test that a dead while body can't generate additional violations | 2169 // test that a dead while body can't generate additional violations |
| 2135 Source source = addSource(EngineTestCase.createSource(["f() {", " while(fal
se) {if(false) {}}", "}"])); | 2170 Source source = addSource(r''' |
| 2171 f() { |
| 2172 while(false) {if(false) {}} |
| 2173 }'''); |
| 2136 resolve(source); | 2174 resolve(source); |
| 2137 assertErrors(source, [HintCode.DEAD_CODE]); | 2175 assertErrors(source, [HintCode.DEAD_CODE]); |
| 2138 verify([source]); | 2176 verify([source]); |
| 2139 } | 2177 } |
| 2140 | 2178 |
| 2141 void test_deadCode_deadCatch_catchFollowingCatch() { | 2179 void test_deadCode_deadCatch_catchFollowingCatch() { |
| 2142 Source source = addSource(EngineTestCase.createSource([ | 2180 Source source = addSource(r''' |
| 2143 "class A {}", | 2181 class A {} |
| 2144 "f() {", | 2182 f() { |
| 2145 " try {} catch (e) {} catch (e) {}", | 2183 try {} catch (e) {} catch (e) {} |
| 2146 "}"])); | 2184 }'''); |
| 2147 resolve(source); | 2185 resolve(source); |
| 2148 assertErrors(source, [HintCode.DEAD_CODE_CATCH_FOLLOWING_CATCH]); | 2186 assertErrors(source, [HintCode.DEAD_CODE_CATCH_FOLLOWING_CATCH]); |
| 2149 verify([source]); | 2187 verify([source]); |
| 2150 } | 2188 } |
| 2151 | 2189 |
| 2152 void test_deadCode_deadCatch_catchFollowingCatch_nested() { | 2190 void test_deadCode_deadCatch_catchFollowingCatch_nested() { |
| 2153 // test that a dead catch clause can't generate additional violations | 2191 // test that a dead catch clause can't generate additional violations |
| 2154 Source source = addSource(EngineTestCase.createSource([ | 2192 Source source = addSource(r''' |
| 2155 "class A {}", | 2193 class A {} |
| 2156 "f() {", | 2194 f() { |
| 2157 " try {} catch (e) {} catch (e) {if(false) {}}", | 2195 try {} catch (e) {} catch (e) {if(false) {}} |
| 2158 "}"])); | 2196 }'''); |
| 2159 resolve(source); | 2197 resolve(source); |
| 2160 assertErrors(source, [HintCode.DEAD_CODE_CATCH_FOLLOWING_CATCH]); | 2198 assertErrors(source, [HintCode.DEAD_CODE_CATCH_FOLLOWING_CATCH]); |
| 2161 verify([source]); | 2199 verify([source]); |
| 2162 } | 2200 } |
| 2163 | 2201 |
| 2164 void test_deadCode_deadCatch_catchFollowingCatch_object() { | 2202 void test_deadCode_deadCatch_catchFollowingCatch_object() { |
| 2165 Source source = addSource(EngineTestCase.createSource([ | 2203 Source source = addSource(r''' |
| 2166 "f() {", | 2204 f() { |
| 2167 " try {} on Object catch (e) {} catch (e) {}", | 2205 try {} on Object catch (e) {} catch (e) {} |
| 2168 "}"])); | 2206 }'''); |
| 2169 resolve(source); | 2207 resolve(source); |
| 2170 assertErrors(source, [HintCode.DEAD_CODE_CATCH_FOLLOWING_CATCH]); | 2208 assertErrors(source, [HintCode.DEAD_CODE_CATCH_FOLLOWING_CATCH]); |
| 2171 verify([source]); | 2209 verify([source]); |
| 2172 } | 2210 } |
| 2173 | 2211 |
| 2174 void test_deadCode_deadCatch_catchFollowingCatch_object_nested() { | 2212 void test_deadCode_deadCatch_catchFollowingCatch_object_nested() { |
| 2175 // test that a dead catch clause can't generate additional violations | 2213 // test that a dead catch clause can't generate additional violations |
| 2176 Source source = addSource(EngineTestCase.createSource([ | 2214 Source source = addSource(r''' |
| 2177 "f() {", | 2215 f() { |
| 2178 " try {} on Object catch (e) {} catch (e) {if(false) {}}", | 2216 try {} on Object catch (e) {} catch (e) {if(false) {}} |
| 2179 "}"])); | 2217 }'''); |
| 2180 resolve(source); | 2218 resolve(source); |
| 2181 assertErrors(source, [HintCode.DEAD_CODE_CATCH_FOLLOWING_CATCH]); | 2219 assertErrors(source, [HintCode.DEAD_CODE_CATCH_FOLLOWING_CATCH]); |
| 2182 verify([source]); | 2220 verify([source]); |
| 2183 } | 2221 } |
| 2184 | 2222 |
| 2185 void test_deadCode_deadCatch_onCatchSubtype() { | 2223 void test_deadCode_deadCatch_onCatchSubtype() { |
| 2186 Source source = addSource(EngineTestCase.createSource([ | 2224 Source source = addSource(r''' |
| 2187 "class A {}", | 2225 class A {} |
| 2188 "class B extends A {}", | 2226 class B extends A {} |
| 2189 "f() {", | 2227 f() { |
| 2190 " try {} on A catch (e) {} on B catch (e) {}", | 2228 try {} on A catch (e) {} on B catch (e) {} |
| 2191 "}"])); | 2229 }'''); |
| 2192 resolve(source); | 2230 resolve(source); |
| 2193 assertErrors(source, [HintCode.DEAD_CODE_ON_CATCH_SUBTYPE]); | 2231 assertErrors(source, [HintCode.DEAD_CODE_ON_CATCH_SUBTYPE]); |
| 2194 verify([source]); | 2232 verify([source]); |
| 2195 } | 2233 } |
| 2196 | 2234 |
| 2197 void test_deadCode_deadCatch_onCatchSubtype_nested() { | 2235 void test_deadCode_deadCatch_onCatchSubtype_nested() { |
| 2198 // test that a dead catch clause can't generate additional violations | 2236 // test that a dead catch clause can't generate additional violations |
| 2199 Source source = addSource(EngineTestCase.createSource([ | 2237 Source source = addSource(r''' |
| 2200 "class A {}", | 2238 class A {} |
| 2201 "class B extends A {}", | 2239 class B extends A {} |
| 2202 "f() {", | 2240 f() { |
| 2203 " try {} on A catch (e) {} on B catch (e) {if(false) {}}", | 2241 try {} on A catch (e) {} on B catch (e) {if(false) {}} |
| 2204 "}"])); | 2242 }'''); |
| 2205 resolve(source); | 2243 resolve(source); |
| 2206 assertErrors(source, [HintCode.DEAD_CODE_ON_CATCH_SUBTYPE]); | 2244 assertErrors(source, [HintCode.DEAD_CODE_ON_CATCH_SUBTYPE]); |
| 2207 verify([source]); | 2245 verify([source]); |
| 2208 } | 2246 } |
| 2209 | 2247 |
| 2210 void test_deadCode_deadOperandLHS_and() { | 2248 void test_deadCode_deadOperandLHS_and() { |
| 2211 Source source = addSource(EngineTestCase.createSource(["f() {", " bool b =
false && false;", "}"])); | 2249 Source source = addSource(r''' |
| 2250 f() { |
| 2251 bool b = false && false; |
| 2252 }'''); |
| 2212 resolve(source); | 2253 resolve(source); |
| 2213 assertErrors(source, [HintCode.DEAD_CODE]); | 2254 assertErrors(source, [HintCode.DEAD_CODE]); |
| 2214 verify([source]); | 2255 verify([source]); |
| 2215 } | 2256 } |
| 2216 | 2257 |
| 2217 void test_deadCode_deadOperandLHS_and_nested() { | 2258 void test_deadCode_deadOperandLHS_and_nested() { |
| 2218 Source source = addSource(EngineTestCase.createSource(["f() {", " bool b =
false && (false && false);", "}"])); | 2259 Source source = addSource(r''' |
| 2260 f() { |
| 2261 bool b = false && (false && false); |
| 2262 }'''); |
| 2219 resolve(source); | 2263 resolve(source); |
| 2220 assertErrors(source, [HintCode.DEAD_CODE]); | 2264 assertErrors(source, [HintCode.DEAD_CODE]); |
| 2221 verify([source]); | 2265 verify([source]); |
| 2222 } | 2266 } |
| 2223 | 2267 |
| 2224 void test_deadCode_deadOperandLHS_or() { | 2268 void test_deadCode_deadOperandLHS_or() { |
| 2225 Source source = addSource(EngineTestCase.createSource(["f() {", " bool b =
true || true;", "}"])); | 2269 Source source = addSource(r''' |
| 2270 f() { |
| 2271 bool b = true || true; |
| 2272 }'''); |
| 2226 resolve(source); | 2273 resolve(source); |
| 2227 assertErrors(source, [HintCode.DEAD_CODE]); | 2274 assertErrors(source, [HintCode.DEAD_CODE]); |
| 2228 verify([source]); | 2275 verify([source]); |
| 2229 } | 2276 } |
| 2230 | 2277 |
| 2231 void test_deadCode_deadOperandLHS_or_nested() { | 2278 void test_deadCode_deadOperandLHS_or_nested() { |
| 2232 Source source = addSource(EngineTestCase.createSource(["f() {", " bool b =
true || (false && false);", "}"])); | 2279 Source source = addSource(r''' |
| 2280 f() { |
| 2281 bool b = true || (false && false); |
| 2282 }'''); |
| 2233 resolve(source); | 2283 resolve(source); |
| 2234 assertErrors(source, [HintCode.DEAD_CODE]); | 2284 assertErrors(source, [HintCode.DEAD_CODE]); |
| 2235 verify([source]); | 2285 verify([source]); |
| 2236 } | 2286 } |
| 2237 | 2287 |
| 2238 void test_deadCode_statementAfterBreak_inDefaultCase() { | 2288 void test_deadCode_statementAfterBreak_inDefaultCase() { |
| 2239 Source source = addSource(EngineTestCase.createSource([ | 2289 Source source = addSource(r''' |
| 2240 "f(v) {", | 2290 f(v) { |
| 2241 " switch(v) {", | 2291 switch(v) { |
| 2242 " case 1:", | 2292 case 1: |
| 2243 " default:", | 2293 default: |
| 2244 " break;", | 2294 break; |
| 2245 " var a;", | 2295 var a; |
| 2246 " }", | 2296 } |
| 2247 "}"])); | 2297 }'''); |
| 2248 resolve(source); | 2298 resolve(source); |
| 2249 assertErrors(source, [HintCode.DEAD_CODE]); | 2299 assertErrors(source, [HintCode.DEAD_CODE]); |
| 2250 verify([source]); | 2300 verify([source]); |
| 2251 } | 2301 } |
| 2252 | 2302 |
| 2253 void test_deadCode_statementAfterBreak_inForEachStatement() { | 2303 void test_deadCode_statementAfterBreak_inForEachStatement() { |
| 2254 Source source = addSource(EngineTestCase.createSource([ | 2304 Source source = addSource(r''' |
| 2255 "f() {", | 2305 f() { |
| 2256 " var list;", | 2306 var list; |
| 2257 " for(var l in list) {", | 2307 for(var l in list) { |
| 2258 " break;", | 2308 break; |
| 2259 " var a;", | 2309 var a; |
| 2260 " }", | 2310 } |
| 2261 "}"])); | 2311 }'''); |
| 2262 resolve(source); | 2312 resolve(source); |
| 2263 assertErrors(source, [HintCode.DEAD_CODE]); | 2313 assertErrors(source, [HintCode.DEAD_CODE]); |
| 2264 verify([source]); | 2314 verify([source]); |
| 2265 } | 2315 } |
| 2266 | 2316 |
| 2267 void test_deadCode_statementAfterBreak_inForStatement() { | 2317 void test_deadCode_statementAfterBreak_inForStatement() { |
| 2268 Source source = addSource(EngineTestCase.createSource([ | 2318 Source source = addSource(r''' |
| 2269 "f() {", | 2319 f() { |
| 2270 " for(;;) {", | 2320 for(;;) { |
| 2271 " break;", | 2321 break; |
| 2272 " var a;", | 2322 var a; |
| 2273 " }", | 2323 } |
| 2274 "}"])); | 2324 }'''); |
| 2275 resolve(source); | 2325 resolve(source); |
| 2276 assertErrors(source, [HintCode.DEAD_CODE]); | 2326 assertErrors(source, [HintCode.DEAD_CODE]); |
| 2277 verify([source]); | 2327 verify([source]); |
| 2278 } | 2328 } |
| 2279 | 2329 |
| 2280 void test_deadCode_statementAfterBreak_inSwitchCase() { | 2330 void test_deadCode_statementAfterBreak_inSwitchCase() { |
| 2281 Source source = addSource(EngineTestCase.createSource([ | 2331 Source source = addSource(r''' |
| 2282 "f(v) {", | 2332 f(v) { |
| 2283 " switch(v) {", | 2333 switch(v) { |
| 2284 " case 1:", | 2334 case 1: |
| 2285 " break;", | 2335 break; |
| 2286 " var a;", | 2336 var a; |
| 2287 " }", | 2337 } |
| 2288 "}"])); | 2338 }'''); |
| 2289 resolve(source); | 2339 resolve(source); |
| 2290 assertErrors(source, [HintCode.DEAD_CODE]); | 2340 assertErrors(source, [HintCode.DEAD_CODE]); |
| 2291 verify([source]); | 2341 verify([source]); |
| 2292 } | 2342 } |
| 2293 | 2343 |
| 2294 void test_deadCode_statementAfterBreak_inWhileStatement() { | 2344 void test_deadCode_statementAfterBreak_inWhileStatement() { |
| 2295 Source source = addSource(EngineTestCase.createSource([ | 2345 Source source = addSource(r''' |
| 2296 "f(v) {", | 2346 f(v) { |
| 2297 " while(v) {", | 2347 while(v) { |
| 2298 " break;", | 2348 break; |
| 2299 " var a;", | 2349 var a; |
| 2300 " }", | 2350 } |
| 2301 "}"])); | 2351 }'''); |
| 2302 resolve(source); | 2352 resolve(source); |
| 2303 assertErrors(source, [HintCode.DEAD_CODE]); | 2353 assertErrors(source, [HintCode.DEAD_CODE]); |
| 2304 verify([source]); | 2354 verify([source]); |
| 2305 } | 2355 } |
| 2306 | 2356 |
| 2307 void test_deadCode_statementAfterContinue_inForEachStatement() { | 2357 void test_deadCode_statementAfterContinue_inForEachStatement() { |
| 2308 Source source = addSource(EngineTestCase.createSource([ | 2358 Source source = addSource(r''' |
| 2309 "f() {", | 2359 f() { |
| 2310 " var list;", | 2360 var list; |
| 2311 " for(var l in list) {", | 2361 for(var l in list) { |
| 2312 " continue;", | 2362 continue; |
| 2313 " var a;", | 2363 var a; |
| 2314 " }", | 2364 } |
| 2315 "}"])); | 2365 }'''); |
| 2316 resolve(source); | 2366 resolve(source); |
| 2317 assertErrors(source, [HintCode.DEAD_CODE]); | 2367 assertErrors(source, [HintCode.DEAD_CODE]); |
| 2318 verify([source]); | 2368 verify([source]); |
| 2319 } | 2369 } |
| 2320 | 2370 |
| 2321 void test_deadCode_statementAfterContinue_inForStatement() { | 2371 void test_deadCode_statementAfterContinue_inForStatement() { |
| 2322 Source source = addSource(EngineTestCase.createSource([ | 2372 Source source = addSource(r''' |
| 2323 "f() {", | 2373 f() { |
| 2324 " for(;;) {", | 2374 for(;;) { |
| 2325 " continue;", | 2375 continue; |
| 2326 " var a;", | 2376 var a; |
| 2327 " }", | 2377 } |
| 2328 "}"])); | 2378 }'''); |
| 2329 resolve(source); | 2379 resolve(source); |
| 2330 assertErrors(source, [HintCode.DEAD_CODE]); | 2380 assertErrors(source, [HintCode.DEAD_CODE]); |
| 2331 verify([source]); | 2381 verify([source]); |
| 2332 } | 2382 } |
| 2333 | 2383 |
| 2334 void test_deadCode_statementAfterContinue_inWhileStatement() { | 2384 void test_deadCode_statementAfterContinue_inWhileStatement() { |
| 2335 Source source = addSource(EngineTestCase.createSource([ | 2385 Source source = addSource(r''' |
| 2336 "f(v) {", | 2386 f(v) { |
| 2337 " while(v) {", | 2387 while(v) { |
| 2338 " continue;", | 2388 continue; |
| 2339 " var a;", | 2389 var a; |
| 2340 " }", | 2390 } |
| 2341 "}"])); | 2391 }'''); |
| 2342 resolve(source); | 2392 resolve(source); |
| 2343 assertErrors(source, [HintCode.DEAD_CODE]); | 2393 assertErrors(source, [HintCode.DEAD_CODE]); |
| 2344 verify([source]); | 2394 verify([source]); |
| 2345 } | 2395 } |
| 2346 | 2396 |
| 2347 void test_deadCode_statementAfterReturn_function() { | 2397 void test_deadCode_statementAfterReturn_function() { |
| 2348 Source source = addSource(EngineTestCase.createSource([ | 2398 Source source = addSource(r''' |
| 2349 "f() {", | 2399 f() { |
| 2350 " var one = 1;", | 2400 var one = 1; |
| 2351 " return;", | 2401 return; |
| 2352 " var two = 2;", | 2402 var two = 2; |
| 2353 "}"])); | 2403 }'''); |
| 2354 resolve(source); | 2404 resolve(source); |
| 2355 assertErrors(source, [HintCode.DEAD_CODE]); | 2405 assertErrors(source, [HintCode.DEAD_CODE]); |
| 2356 verify([source]); | 2406 verify([source]); |
| 2357 } | 2407 } |
| 2358 | 2408 |
| 2359 void test_deadCode_statementAfterReturn_ifStatement() { | 2409 void test_deadCode_statementAfterReturn_ifStatement() { |
| 2360 Source source = addSource(EngineTestCase.createSource([ | 2410 Source source = addSource(r''' |
| 2361 "f(bool b) {", | 2411 f(bool b) { |
| 2362 " if(b) {", | 2412 if(b) { |
| 2363 " var one = 1;", | 2413 var one = 1; |
| 2364 " return;", | 2414 return; |
| 2365 " var two = 2;", | 2415 var two = 2; |
| 2366 " }", | 2416 } |
| 2367 "}"])); | 2417 }'''); |
| 2368 resolve(source); | 2418 resolve(source); |
| 2369 assertErrors(source, [HintCode.DEAD_CODE]); | 2419 assertErrors(source, [HintCode.DEAD_CODE]); |
| 2370 verify([source]); | 2420 verify([source]); |
| 2371 } | 2421 } |
| 2372 | 2422 |
| 2373 void test_deadCode_statementAfterReturn_method() { | 2423 void test_deadCode_statementAfterReturn_method() { |
| 2374 Source source = addSource(EngineTestCase.createSource([ | 2424 Source source = addSource(r''' |
| 2375 "class A {", | 2425 class A { |
| 2376 " m() {", | 2426 m() { |
| 2377 " var one = 1;", | 2427 var one = 1; |
| 2378 " return;", | 2428 return; |
| 2379 " var two = 2;", | 2429 var two = 2; |
| 2380 " }", | 2430 } |
| 2381 "}"])); | 2431 }'''); |
| 2382 resolve(source); | 2432 resolve(source); |
| 2383 assertErrors(source, [HintCode.DEAD_CODE]); | 2433 assertErrors(source, [HintCode.DEAD_CODE]); |
| 2384 verify([source]); | 2434 verify([source]); |
| 2385 } | 2435 } |
| 2386 | 2436 |
| 2387 void test_deadCode_statementAfterReturn_nested() { | 2437 void test_deadCode_statementAfterReturn_nested() { |
| 2388 Source source = addSource(EngineTestCase.createSource([ | 2438 Source source = addSource(r''' |
| 2389 "f() {", | 2439 f() { |
| 2390 " var one = 1;", | 2440 var one = 1; |
| 2391 " return;", | 2441 return; |
| 2392 " if(false) {}", | 2442 if(false) {} |
| 2393 "}"])); | 2443 }'''); |
| 2394 resolve(source); | 2444 resolve(source); |
| 2395 assertErrors(source, [HintCode.DEAD_CODE]); | 2445 assertErrors(source, [HintCode.DEAD_CODE]); |
| 2396 verify([source]); | 2446 verify([source]); |
| 2397 } | 2447 } |
| 2398 | 2448 |
| 2399 void test_deadCode_statementAfterReturn_twoReturns() { | 2449 void test_deadCode_statementAfterReturn_twoReturns() { |
| 2400 Source source = addSource(EngineTestCase.createSource([ | 2450 Source source = addSource(r''' |
| 2401 "f() {", | 2451 f() { |
| 2402 " var one = 1;", | 2452 var one = 1; |
| 2403 " return;", | 2453 return; |
| 2404 " var two = 2;", | 2454 var two = 2; |
| 2405 " return;", | 2455 return; |
| 2406 " var three = 3;", | 2456 var three = 3; |
| 2407 "}"])); | 2457 }'''); |
| 2408 resolve(source); | 2458 resolve(source); |
| 2409 assertErrors(source, [HintCode.DEAD_CODE]); | 2459 assertErrors(source, [HintCode.DEAD_CODE]); |
| 2410 verify([source]); | 2460 verify([source]); |
| 2411 } | 2461 } |
| 2412 | 2462 |
| 2413 void test_deprecatedAnnotationUse_assignment() { | 2463 void test_deprecatedAnnotationUse_assignment() { |
| 2414 Source source = addSource(EngineTestCase.createSource([ | 2464 Source source = addSource(r''' |
| 2415 "class A {", | 2465 class A { |
| 2416 " @deprecated", | 2466 @deprecated |
| 2417 " A operator+(A a) { return a; }", | 2467 A operator+(A a) { return a; } |
| 2418 "}", | 2468 } |
| 2419 "f(A a) {", | 2469 f(A a) { |
| 2420 " A b;", | 2470 A b; |
| 2421 " a += b;", | 2471 a += b; |
| 2422 "}"])); | 2472 }'''); |
| 2423 resolve(source); | 2473 resolve(source); |
| 2424 assertErrors(source, [HintCode.DEPRECATED_MEMBER_USE]); | 2474 assertErrors(source, [HintCode.DEPRECATED_MEMBER_USE]); |
| 2425 verify([source]); | 2475 verify([source]); |
| 2426 } | 2476 } |
| 2427 | 2477 |
| 2428 void test_deprecatedAnnotationUse_deprecated() { | 2478 void test_deprecatedAnnotationUse_deprecated() { |
| 2429 Source source = addSource(EngineTestCase.createSource([ | 2479 Source source = addSource(r''' |
| 2430 "class A {", | 2480 class A { |
| 2431 " @deprecated", | 2481 @deprecated |
| 2432 " m() {}", | 2482 m() {} |
| 2433 " n() {m();}", | 2483 n() {m();} |
| 2434 "}"])); | 2484 }'''); |
| 2435 resolve(source); | 2485 resolve(source); |
| 2436 assertErrors(source, [HintCode.DEPRECATED_MEMBER_USE]); | 2486 assertErrors(source, [HintCode.DEPRECATED_MEMBER_USE]); |
| 2437 verify([source]); | 2487 verify([source]); |
| 2438 } | 2488 } |
| 2439 | 2489 |
| 2440 void test_deprecatedAnnotationUse_Deprecated() { | 2490 void test_deprecatedAnnotationUse_Deprecated() { |
| 2441 Source source = addSource(EngineTestCase.createSource([ | 2491 Source source = addSource(r''' |
| 2442 "class A {", | 2492 class A { |
| 2443 " @Deprecated('0.9')", | 2493 @Deprecated('0.9') |
| 2444 " m() {}", | 2494 m() {} |
| 2445 " n() {m();}", | 2495 n() {m();} |
| 2446 "}"])); | 2496 }'''); |
| 2447 resolve(source); | 2497 resolve(source); |
| 2448 assertErrors(source, [HintCode.DEPRECATED_MEMBER_USE]); | 2498 assertErrors(source, [HintCode.DEPRECATED_MEMBER_USE]); |
| 2449 verify([source]); | 2499 verify([source]); |
| 2450 } | 2500 } |
| 2451 | 2501 |
| 2452 void test_deprecatedAnnotationUse_deprecatedMethodCalledOnUnionType() { | 2502 void test_deprecatedAnnotationUse_deprecatedMethodCalledOnUnionType() { |
| 2453 enableUnionTypes(false); | 2503 enableUnionTypes(false); |
| 2454 Source source = addSource(EngineTestCase.createSource([ | 2504 Source source = addSource(r''' |
| 2455 "class A {", | 2505 class A { |
| 2456 " @deprecated f() => 0;", | 2506 @deprecated f() => 0; |
| 2457 "}", | 2507 } |
| 2458 "class B extends A {}", | 2508 class B extends A {} |
| 2459 "main(A a, B b) {", | 2509 main(A a, B b) { |
| 2460 " var x;", | 2510 var x; |
| 2461 " if (0 < 1) {", | 2511 if (0 < 1) { |
| 2462 " x = a;", | 2512 x = a; |
| 2463 " } else {", | 2513 } else { |
| 2464 " x = b;", | 2514 x = b; |
| 2465 " }", | 2515 } |
| 2466 " x.f(); // Here [x] has type [{A,B}] but we still want the deprecation
warning.", | 2516 x.f(); // Here [x] has type [{A,B}] but we still want the deprecation warning. |
| 2467 "}"])); | 2517 }'''); |
| 2468 resolve(source); | 2518 resolve(source); |
| 2469 assertErrors(source, [HintCode.DEPRECATED_MEMBER_USE]); | 2519 assertErrors(source, [HintCode.DEPRECATED_MEMBER_USE]); |
| 2470 verify([source]); | 2520 verify([source]); |
| 2471 } | 2521 } |
| 2472 | 2522 |
| 2473 void test_deprecatedAnnotationUse_export() { | 2523 void test_deprecatedAnnotationUse_export() { |
| 2474 Source source = addSource(EngineTestCase.createSource(["export 'deprecated_l
ibrary.dart';"])); | 2524 Source source = addSource("export 'deprecated_library.dart';"); |
| 2475 addNamedSource("/deprecated_library.dart", EngineTestCase.createSource([ | 2525 addNamedSource("/deprecated_library.dart", r''' |
| 2476 "@deprecated", | 2526 @deprecated |
| 2477 "library deprecated_library;", | 2527 library deprecated_library; |
| 2478 "class A {}"])); | 2528 class A {}'''); |
| 2479 resolve(source); | 2529 resolve(source); |
| 2480 assertErrors(source, [HintCode.DEPRECATED_MEMBER_USE]); | 2530 assertErrors(source, [HintCode.DEPRECATED_MEMBER_USE]); |
| 2481 verify([source]); | 2531 verify([source]); |
| 2482 } | 2532 } |
| 2483 | 2533 |
| 2484 void test_deprecatedAnnotationUse_getter() { | 2534 void test_deprecatedAnnotationUse_getter() { |
| 2485 Source source = addSource(EngineTestCase.createSource([ | 2535 Source source = addSource(r''' |
| 2486 "class A {", | 2536 class A { |
| 2487 " @deprecated", | 2537 @deprecated |
| 2488 " get m => 1;", | 2538 get m => 1; |
| 2489 "}", | 2539 } |
| 2490 "f(A a) {", | 2540 f(A a) { |
| 2491 " return a.m;", | 2541 return a.m; |
| 2492 "}"])); | 2542 }'''); |
| 2493 resolve(source); | 2543 resolve(source); |
| 2494 assertErrors(source, [HintCode.DEPRECATED_MEMBER_USE]); | 2544 assertErrors(source, [HintCode.DEPRECATED_MEMBER_USE]); |
| 2495 verify([source]); | 2545 verify([source]); |
| 2496 } | 2546 } |
| 2497 | 2547 |
| 2498 void test_deprecatedAnnotationUse_import() { | 2548 void test_deprecatedAnnotationUse_import() { |
| 2499 Source source = addSource(EngineTestCase.createSource(["import 'deprecated_l
ibrary.dart';", "f(A a) {}"])); | 2549 Source source = addSource(r''' |
| 2500 addNamedSource("/deprecated_library.dart", EngineTestCase.createSource([ | 2550 import 'deprecated_library.dart'; |
| 2501 "@deprecated", | 2551 f(A a) {}'''); |
| 2502 "library deprecated_library;", | 2552 addNamedSource("/deprecated_library.dart", r''' |
| 2503 "class A {}"])); | 2553 @deprecated |
| 2554 library deprecated_library; |
| 2555 class A {}'''); |
| 2504 resolve(source); | 2556 resolve(source); |
| 2505 assertErrors(source, [HintCode.DEPRECATED_MEMBER_USE]); | 2557 assertErrors(source, [HintCode.DEPRECATED_MEMBER_USE]); |
| 2506 verify([source]); | 2558 verify([source]); |
| 2507 } | 2559 } |
| 2508 | 2560 |
| 2509 void test_deprecatedAnnotationUse_indexExpression() { | 2561 void test_deprecatedAnnotationUse_indexExpression() { |
| 2510 Source source = addSource(EngineTestCase.createSource([ | 2562 Source source = addSource(r''' |
| 2511 "class A {", | 2563 class A { |
| 2512 " @deprecated", | 2564 @deprecated |
| 2513 " operator[](int i) {}", | 2565 operator[](int i) {} |
| 2514 "}", | 2566 } |
| 2515 "f(A a) {", | 2567 f(A a) { |
| 2516 " return a[1];", | 2568 return a[1]; |
| 2517 "}"])); | 2569 }'''); |
| 2518 resolve(source); | 2570 resolve(source); |
| 2519 assertErrors(source, [HintCode.DEPRECATED_MEMBER_USE]); | 2571 assertErrors(source, [HintCode.DEPRECATED_MEMBER_USE]); |
| 2520 verify([source]); | 2572 verify([source]); |
| 2521 } | 2573 } |
| 2522 | 2574 |
| 2523 void test_deprecatedAnnotationUse_instanceCreation() { | 2575 void test_deprecatedAnnotationUse_instanceCreation() { |
| 2524 Source source = addSource(EngineTestCase.createSource([ | 2576 Source source = addSource(r''' |
| 2525 "class A {", | 2577 class A { |
| 2526 " @deprecated", | 2578 @deprecated |
| 2527 " A(int i) {}", | 2579 A(int i) {} |
| 2528 "}", | 2580 } |
| 2529 "f() {", | 2581 f() { |
| 2530 " A a = new A(1);", | 2582 A a = new A(1); |
| 2531 "}"])); | 2583 }'''); |
| 2532 resolve(source); | 2584 resolve(source); |
| 2533 assertErrors(source, [HintCode.DEPRECATED_MEMBER_USE]); | 2585 assertErrors(source, [HintCode.DEPRECATED_MEMBER_USE]); |
| 2534 verify([source]); | 2586 verify([source]); |
| 2535 } | 2587 } |
| 2536 | 2588 |
| 2537 void test_deprecatedAnnotationUse_instanceCreation_namedConstructor() { | 2589 void test_deprecatedAnnotationUse_instanceCreation_namedConstructor() { |
| 2538 Source source = addSource(EngineTestCase.createSource([ | 2590 Source source = addSource(r''' |
| 2539 "class A {", | 2591 class A { |
| 2540 " @deprecated", | 2592 @deprecated |
| 2541 " A.named(int i) {}", | 2593 A.named(int i) {} |
| 2542 "}", | 2594 } |
| 2543 "f() {", | 2595 f() { |
| 2544 " A a = new A.named(1);", | 2596 A a = new A.named(1); |
| 2545 "}"])); | 2597 }'''); |
| 2546 resolve(source); | 2598 resolve(source); |
| 2547 assertErrors(source, [HintCode.DEPRECATED_MEMBER_USE]); | 2599 assertErrors(source, [HintCode.DEPRECATED_MEMBER_USE]); |
| 2548 verify([source]); | 2600 verify([source]); |
| 2549 } | 2601 } |
| 2550 | 2602 |
| 2551 void test_deprecatedAnnotationUse_operator() { | 2603 void test_deprecatedAnnotationUse_operator() { |
| 2552 Source source = addSource(EngineTestCase.createSource([ | 2604 Source source = addSource(r''' |
| 2553 "class A {", | 2605 class A { |
| 2554 " @deprecated", | 2606 @deprecated |
| 2555 " operator+(A a) {}", | 2607 operator+(A a) {} |
| 2556 "}", | 2608 } |
| 2557 "f(A a) {", | 2609 f(A a) { |
| 2558 " A b;", | 2610 A b; |
| 2559 " return a + b;", | 2611 return a + b; |
| 2560 "}"])); | 2612 }'''); |
| 2561 resolve(source); | 2613 resolve(source); |
| 2562 assertErrors(source, [HintCode.DEPRECATED_MEMBER_USE]); | 2614 assertErrors(source, [HintCode.DEPRECATED_MEMBER_USE]); |
| 2563 verify([source]); | 2615 verify([source]); |
| 2564 } | 2616 } |
| 2565 | 2617 |
| 2566 void test_deprecatedAnnotationUse_setter() { | 2618 void test_deprecatedAnnotationUse_setter() { |
| 2567 Source source = addSource(EngineTestCase.createSource([ | 2619 Source source = addSource(r''' |
| 2568 "class A {", | 2620 class A { |
| 2569 " @deprecated", | 2621 @deprecated |
| 2570 " set s(v) {}", | 2622 set s(v) {} |
| 2571 "}", | 2623 } |
| 2572 "f(A a) {", | 2624 f(A a) { |
| 2573 " return a.s = 1;", | 2625 return a.s = 1; |
| 2574 "}"])); | 2626 }'''); |
| 2575 resolve(source); | 2627 resolve(source); |
| 2576 assertErrors(source, [HintCode.DEPRECATED_MEMBER_USE]); | 2628 assertErrors(source, [HintCode.DEPRECATED_MEMBER_USE]); |
| 2577 verify([source]); | 2629 verify([source]); |
| 2578 } | 2630 } |
| 2579 | 2631 |
| 2580 void test_deprecatedAnnotationUse_superConstructor() { | 2632 void test_deprecatedAnnotationUse_superConstructor() { |
| 2581 Source source = addSource(EngineTestCase.createSource([ | 2633 Source source = addSource(r''' |
| 2582 "class A {", | 2634 class A { |
| 2583 " @deprecated", | 2635 @deprecated |
| 2584 " A() {}", | 2636 A() {} |
| 2585 "}", | 2637 } |
| 2586 "class B extends A {", | 2638 class B extends A { |
| 2587 " B() : super() {}", | 2639 B() : super() {} |
| 2588 "}"])); | 2640 }'''); |
| 2589 resolve(source); | 2641 resolve(source); |
| 2590 assertErrors(source, [HintCode.DEPRECATED_MEMBER_USE]); | 2642 assertErrors(source, [HintCode.DEPRECATED_MEMBER_USE]); |
| 2591 verify([source]); | 2643 verify([source]); |
| 2592 } | 2644 } |
| 2593 | 2645 |
| 2594 void test_deprecatedAnnotationUse_superConstructor_namedConstructor() { | 2646 void test_deprecatedAnnotationUse_superConstructor_namedConstructor() { |
| 2595 Source source = addSource(EngineTestCase.createSource([ | 2647 Source source = addSource(r''' |
| 2596 "class A {", | 2648 class A { |
| 2597 " @deprecated", | 2649 @deprecated |
| 2598 " A.named() {}", | 2650 A.named() {} |
| 2599 "}", | 2651 } |
| 2600 "class B extends A {", | 2652 class B extends A { |
| 2601 " B() : super.named() {}", | 2653 B() : super.named() {} |
| 2602 "}"])); | 2654 }'''); |
| 2603 resolve(source); | 2655 resolve(source); |
| 2604 assertErrors(source, [HintCode.DEPRECATED_MEMBER_USE]); | 2656 assertErrors(source, [HintCode.DEPRECATED_MEMBER_USE]); |
| 2605 verify([source]); | 2657 verify([source]); |
| 2606 } | 2658 } |
| 2607 | 2659 |
| 2608 void test_divisionOptimization_double() { | 2660 void test_divisionOptimization_double() { |
| 2609 Source source = addSource(EngineTestCase.createSource([ | 2661 Source source = addSource(r''' |
| 2610 "f(double x, double y) {", | 2662 f(double x, double y) { |
| 2611 " var v = (x / y).toInt();", | 2663 var v = (x / y).toInt(); |
| 2612 "}"])); | 2664 }'''); |
| 2613 resolve(source); | 2665 resolve(source); |
| 2614 assertErrors(source, [HintCode.DIVISION_OPTIMIZATION]); | 2666 assertErrors(source, [HintCode.DIVISION_OPTIMIZATION]); |
| 2615 verify([source]); | 2667 verify([source]); |
| 2616 } | 2668 } |
| 2617 | 2669 |
| 2618 void test_divisionOptimization_int() { | 2670 void test_divisionOptimization_int() { |
| 2619 Source source = addSource(EngineTestCase.createSource(["f(int x, int y) {",
" var v = (x / y).toInt();", "}"])); | 2671 Source source = addSource(r''' |
| 2672 f(int x, int y) { |
| 2673 var v = (x / y).toInt(); |
| 2674 }'''); |
| 2620 resolve(source); | 2675 resolve(source); |
| 2621 assertErrors(source, [HintCode.DIVISION_OPTIMIZATION]); | 2676 assertErrors(source, [HintCode.DIVISION_OPTIMIZATION]); |
| 2622 verify([source]); | 2677 verify([source]); |
| 2623 } | 2678 } |
| 2624 | 2679 |
| 2625 void test_divisionOptimization_propagatedType() { | 2680 void test_divisionOptimization_propagatedType() { |
| 2626 // Tests the propagated type information of the '/' method | 2681 // Tests the propagated type information of the '/' method |
| 2627 Source source = addSource(EngineTestCase.createSource([ | 2682 Source source = addSource(r''' |
| 2628 "f(x, y) {", | 2683 f(x, y) { |
| 2629 " x = 1;", | 2684 x = 1; |
| 2630 " y = 1;", | 2685 y = 1; |
| 2631 " var v = (x / y).toInt();", | 2686 var v = (x / y).toInt(); |
| 2632 "}"])); | 2687 }'''); |
| 2633 resolve(source); | 2688 resolve(source); |
| 2634 assertErrors(source, [HintCode.DIVISION_OPTIMIZATION]); | 2689 assertErrors(source, [HintCode.DIVISION_OPTIMIZATION]); |
| 2635 verify([source]); | 2690 verify([source]); |
| 2636 } | 2691 } |
| 2637 | 2692 |
| 2638 void test_divisionOptimization_wrappedBinaryExpression() { | 2693 void test_divisionOptimization_wrappedBinaryExpression() { |
| 2639 Source source = addSource(EngineTestCase.createSource([ | 2694 Source source = addSource(r''' |
| 2640 "f(int x, int y) {", | 2695 f(int x, int y) { |
| 2641 " var v = (((x / y))).toInt();", | 2696 var v = (((x / y))).toInt(); |
| 2642 "}"])); | 2697 }'''); |
| 2643 resolve(source); | 2698 resolve(source); |
| 2644 assertErrors(source, [HintCode.DIVISION_OPTIMIZATION]); | 2699 assertErrors(source, [HintCode.DIVISION_OPTIMIZATION]); |
| 2645 verify([source]); | 2700 verify([source]); |
| 2646 } | 2701 } |
| 2647 | 2702 |
| 2648 void test_duplicateImport() { | 2703 void test_duplicateImport() { |
| 2649 Source source = addSource(EngineTestCase.createSource([ | 2704 Source source = addSource(r''' |
| 2650 "library L;", | 2705 library L; |
| 2651 "import 'lib1.dart';", | 2706 import 'lib1.dart'; |
| 2652 "import 'lib1.dart';", | 2707 import 'lib1.dart'; |
| 2653 "A a;"])); | 2708 A a;'''); |
| 2654 addNamedSource("/lib1.dart", EngineTestCase.createSource(["library lib1;", "
class A {}"])); | 2709 addNamedSource("/lib1.dart", r''' |
| 2710 library lib1; |
| 2711 class A {}'''); |
| 2655 resolve(source); | 2712 resolve(source); |
| 2656 assertErrors(source, [HintCode.DUPLICATE_IMPORT]); | 2713 assertErrors(source, [HintCode.DUPLICATE_IMPORT]); |
| 2657 verify([source]); | 2714 verify([source]); |
| 2658 } | 2715 } |
| 2659 | 2716 |
| 2660 void test_duplicateImport2() { | 2717 void test_duplicateImport2() { |
| 2661 Source source = addSource(EngineTestCase.createSource([ | 2718 Source source = addSource(r''' |
| 2662 "library L;", | 2719 library L; |
| 2663 "import 'lib1.dart';", | 2720 import 'lib1.dart'; |
| 2664 "import 'lib1.dart';", | 2721 import 'lib1.dart'; |
| 2665 "import 'lib1.dart';", | 2722 import 'lib1.dart'; |
| 2666 "A a;"])); | 2723 A a;'''); |
| 2667 addNamedSource("/lib1.dart", EngineTestCase.createSource(["library lib1;", "
class A {}"])); | 2724 addNamedSource("/lib1.dart", r''' |
| 2725 library lib1; |
| 2726 class A {}'''); |
| 2668 resolve(source); | 2727 resolve(source); |
| 2669 assertErrors(source, [HintCode.DUPLICATE_IMPORT, HintCode.DUPLICATE_IMPORT])
; | 2728 assertErrors(source, [HintCode.DUPLICATE_IMPORT, HintCode.DUPLICATE_IMPORT])
; |
| 2670 verify([source]); | 2729 verify([source]); |
| 2671 } | 2730 } |
| 2672 | 2731 |
| 2673 void test_duplicateImport3() { | 2732 void test_duplicateImport3() { |
| 2674 Source source = addSource(EngineTestCase.createSource([ | 2733 Source source = addSource(r''' |
| 2675 "library L;", | 2734 library L; |
| 2676 "import 'lib1.dart' as M show A hide B;", | 2735 import 'lib1.dart' as M show A hide B; |
| 2677 "import 'lib1.dart' as M show A hide B;", | 2736 import 'lib1.dart' as M show A hide B; |
| 2678 "M.A a;"])); | 2737 M.A a;'''); |
| 2679 addNamedSource("/lib1.dart", EngineTestCase.createSource(["library lib1;", "
class A {}", "class B {}"])); | 2738 addNamedSource("/lib1.dart", r''' |
| 2739 library lib1; |
| 2740 class A {} |
| 2741 class B {}'''); |
| 2680 resolve(source); | 2742 resolve(source); |
| 2681 assertErrors(source, [HintCode.DUPLICATE_IMPORT]); | 2743 assertErrors(source, [HintCode.DUPLICATE_IMPORT]); |
| 2682 verify([source]); | 2744 verify([source]); |
| 2683 } | 2745 } |
| 2684 | 2746 |
| 2685 void test_importDeferredLibraryWithLoadFunction() { | 2747 void test_importDeferredLibraryWithLoadFunction() { |
| 2686 resolveWithAndWithoutExperimental(<String> [ | 2748 resolveWithAndWithoutExperimental(<String> [ |
| 2687 EngineTestCase.createSource(["library lib1;", "loadLibrary() {}", "f() {
}"]), | 2749 r''' |
| 2688 EngineTestCase.createSource([ | 2750 library lib1; |
| 2689 "library root;", | 2751 loadLibrary() {} |
| 2690 "import 'lib1.dart' deferred as lib1;", | 2752 f() {}''', |
| 2691 "main() { lib1.f(); }"])], <ErrorCode> [ParserErrorCode.DEFERRED_IMPORTS
_NOT_SUPPORTED], <ErrorCode> [HintCode.IMPORT_DEFERRED_LIBRARY_WITH_LOAD_FUNCTIO
N]); | 2753 r''' |
| 2754 library root; |
| 2755 import 'lib1.dart' deferred as lib1; |
| 2756 main() { lib1.f(); }'''], <ErrorCode> [ParserErrorCode.DEFERRED_IMPORTS_NOT_SUPP
ORTED], <ErrorCode> [HintCode.IMPORT_DEFERRED_LIBRARY_WITH_LOAD_FUNCTION]); |
| 2692 } | 2757 } |
| 2693 | 2758 |
| 2694 void test_invalidAssignment_instanceVariable() { | 2759 void test_invalidAssignment_instanceVariable() { |
| 2695 Source source = addSource(EngineTestCase.createSource([ | 2760 Source source = addSource(r''' |
| 2696 "class A {", | 2761 class A { |
| 2697 " int x;", | 2762 int x; |
| 2698 "}", | 2763 } |
| 2699 "f(var y) {", | 2764 f(var y) { |
| 2700 " A a;", | 2765 A a; |
| 2701 " if(y is String) {", | 2766 if(y is String) { |
| 2702 " a.x = y;", | 2767 a.x = y; |
| 2703 " }", | 2768 } |
| 2704 "}"])); | 2769 }'''); |
| 2705 resolve(source); | 2770 resolve(source); |
| 2706 assertErrors(source, [HintCode.INVALID_ASSIGNMENT]); | 2771 assertErrors(source, [HintCode.INVALID_ASSIGNMENT]); |
| 2707 verify([source]); | 2772 verify([source]); |
| 2708 } | 2773 } |
| 2709 | 2774 |
| 2710 void test_invalidAssignment_localVariable() { | 2775 void test_invalidAssignment_localVariable() { |
| 2711 Source source = addSource(EngineTestCase.createSource([ | 2776 Source source = addSource(r''' |
| 2712 "f(var y) {", | 2777 f(var y) { |
| 2713 " if(y is String) {", | 2778 if(y is String) { |
| 2714 " int x = y;", | 2779 int x = y; |
| 2715 " }", | 2780 } |
| 2716 "}"])); | 2781 }'''); |
| 2717 resolve(source); | 2782 resolve(source); |
| 2718 assertErrors(source, [HintCode.INVALID_ASSIGNMENT]); | 2783 assertErrors(source, [HintCode.INVALID_ASSIGNMENT]); |
| 2719 verify([source]); | 2784 verify([source]); |
| 2720 } | 2785 } |
| 2721 | 2786 |
| 2722 void test_invalidAssignment_message() { | 2787 void test_invalidAssignment_message() { |
| 2723 // The implementation of HintCode.INVALID_ASSIGNMENT assumes that | 2788 // The implementation of HintCode.INVALID_ASSIGNMENT assumes that |
| 2724 // StaticTypeWarningCode.INVALID_ASSIGNMENT has the same message. | 2789 // StaticTypeWarningCode.INVALID_ASSIGNMENT has the same message. |
| 2725 JUnitTestCase.assertEquals(HintCode.INVALID_ASSIGNMENT.message, StaticTypeWa
rningCode.INVALID_ASSIGNMENT.message); | 2790 JUnitTestCase.assertEquals(HintCode.INVALID_ASSIGNMENT.message, StaticTypeWa
rningCode.INVALID_ASSIGNMENT.message); |
| 2726 } | 2791 } |
| 2727 | 2792 |
| 2728 void test_invalidAssignment_staticVariable() { | 2793 void test_invalidAssignment_staticVariable() { |
| 2729 Source source = addSource(EngineTestCase.createSource([ | 2794 Source source = addSource(r''' |
| 2730 "class A {", | 2795 class A { |
| 2731 " static int x;", | 2796 static int x; |
| 2732 "}", | 2797 } |
| 2733 "f(var y) {", | 2798 f(var y) { |
| 2734 " if(y is String) {", | 2799 if(y is String) { |
| 2735 " A.x = y;", | 2800 A.x = y; |
| 2736 " }", | 2801 } |
| 2737 "}"])); | 2802 }'''); |
| 2738 resolve(source); | 2803 resolve(source); |
| 2739 assertErrors(source, [HintCode.INVALID_ASSIGNMENT]); | 2804 assertErrors(source, [HintCode.INVALID_ASSIGNMENT]); |
| 2740 verify([source]); | 2805 verify([source]); |
| 2741 } | 2806 } |
| 2742 | 2807 |
| 2743 void test_invalidAssignment_variableDeclaration() { | 2808 void test_invalidAssignment_variableDeclaration() { |
| 2744 // 17971 | 2809 // 17971 |
| 2745 Source source = addSource(EngineTestCase.createSource([ | 2810 Source source = addSource(r''' |
| 2746 "class Point {", | 2811 class Point { |
| 2747 " final num x, y;", | 2812 final num x, y; |
| 2748 " Point(this.x, this.y);", | 2813 Point(this.x, this.y); |
| 2749 " Point operator +(Point other) {", | 2814 Point operator +(Point other) { |
| 2750 " return new Point(x+other.x, y+other.y);", | 2815 return new Point(x+other.x, y+other.y); |
| 2751 " }", | 2816 } |
| 2752 "}", | 2817 } |
| 2753 "main() {", | 2818 main() { |
| 2754 " var p1 = new Point(0, 0);", | 2819 var p1 = new Point(0, 0); |
| 2755 " var p2 = new Point(10, 10);", | 2820 var p2 = new Point(10, 10); |
| 2756 " int n = p1 + p2;", | 2821 int n = p1 + p2; |
| 2757 "}"])); | 2822 }'''); |
| 2758 resolve(source); | 2823 resolve(source); |
| 2759 assertErrors(source, [HintCode.INVALID_ASSIGNMENT]); | 2824 assertErrors(source, [HintCode.INVALID_ASSIGNMENT]); |
| 2760 verify([source]); | 2825 verify([source]); |
| 2761 } | 2826 } |
| 2762 | 2827 |
| 2763 void test_isDouble() { | 2828 void test_isDouble() { |
| 2764 Source source = addSource(EngineTestCase.createSource(["var v = 1 is double;
"])); | 2829 Source source = addSource("var v = 1 is double;"); |
| 2765 resolve(source); | 2830 resolve(source); |
| 2766 assertErrors(source, [HintCode.IS_DOUBLE]); | 2831 assertErrors(source, [HintCode.IS_DOUBLE]); |
| 2767 verify([source]); | 2832 verify([source]); |
| 2768 } | 2833 } |
| 2769 | 2834 |
| 2770 void test_isNotDouble() { | 2835 void test_isNotDouble() { |
| 2771 Source source = addSource(EngineTestCase.createSource(["var v = 1 is! double
;"])); | 2836 Source source = addSource("var v = 1 is! double;"); |
| 2772 resolve(source); | 2837 resolve(source); |
| 2773 assertErrors(source, [HintCode.IS_NOT_DOUBLE]); | 2838 assertErrors(source, [HintCode.IS_NOT_DOUBLE]); |
| 2774 verify([source]); | 2839 verify([source]); |
| 2775 } | 2840 } |
| 2776 | 2841 |
| 2777 void test_missingReturn_function() { | 2842 void test_missingReturn_function() { |
| 2778 Source source = addSource(EngineTestCase.createSource(["int f() {}"])); | 2843 Source source = addSource("int f() {}"); |
| 2779 resolve(source); | 2844 resolve(source); |
| 2780 assertErrors(source, [HintCode.MISSING_RETURN]); | 2845 assertErrors(source, [HintCode.MISSING_RETURN]); |
| 2781 verify([source]); | 2846 verify([source]); |
| 2782 } | 2847 } |
| 2783 | 2848 |
| 2784 void test_missingReturn_method() { | 2849 void test_missingReturn_method() { |
| 2785 Source source = addSource(EngineTestCase.createSource(["class A {", " int m
() {}", "}"])); | 2850 Source source = addSource(r''' |
| 2851 class A { |
| 2852 int m() {} |
| 2853 }'''); |
| 2786 resolve(source); | 2854 resolve(source); |
| 2787 assertErrors(source, [HintCode.MISSING_RETURN]); | 2855 assertErrors(source, [HintCode.MISSING_RETURN]); |
| 2788 verify([source]); | 2856 verify([source]); |
| 2789 } | 2857 } |
| 2790 | 2858 |
| 2791 void test_overrideOnNonOverridingGetter_invalid() { | 2859 void test_overrideOnNonOverridingGetter_invalid() { |
| 2792 Source source = addSource(EngineTestCase.createSource([ | 2860 Source source = addSource(r''' |
| 2793 "library dart.core;", | 2861 library dart.core; |
| 2794 "const override = null;", | 2862 const override = null; |
| 2795 "class A {", | 2863 class A { |
| 2796 "}", | 2864 } |
| 2797 "class B extends A {", | 2865 class B extends A { |
| 2798 " @override", | 2866 @override |
| 2799 " int get m => 1;", | 2867 int get m => 1; |
| 2800 "}"])); | 2868 }'''); |
| 2801 resolve(source); | 2869 resolve(source); |
| 2802 assertErrors(source, [HintCode.OVERRIDE_ON_NON_OVERRIDING_GETTER]); | 2870 assertErrors(source, [HintCode.OVERRIDE_ON_NON_OVERRIDING_GETTER]); |
| 2803 verify([source]); | 2871 verify([source]); |
| 2804 } | 2872 } |
| 2805 | 2873 |
| 2806 void test_overrideOnNonOverridingMethod_invalid() { | 2874 void test_overrideOnNonOverridingMethod_invalid() { |
| 2807 Source source = addSource(EngineTestCase.createSource([ | 2875 Source source = addSource(r''' |
| 2808 "library dart.core;", | 2876 library dart.core; |
| 2809 "const override = null;", | 2877 const override = null; |
| 2810 "class A {", | 2878 class A { |
| 2811 "}", | 2879 } |
| 2812 "class B extends A {", | 2880 class B extends A { |
| 2813 " @override", | 2881 @override |
| 2814 " int m() => 1;", | 2882 int m() => 1; |
| 2815 "}"])); | 2883 }'''); |
| 2816 resolve(source); | 2884 resolve(source); |
| 2817 assertErrors(source, [HintCode.OVERRIDE_ON_NON_OVERRIDING_METHOD]); | 2885 assertErrors(source, [HintCode.OVERRIDE_ON_NON_OVERRIDING_METHOD]); |
| 2818 verify([source]); | 2886 verify([source]); |
| 2819 } | 2887 } |
| 2820 | 2888 |
| 2821 void test_overrideOnNonOverridingSetter_invalid() { | 2889 void test_overrideOnNonOverridingSetter_invalid() { |
| 2822 Source source = addSource(EngineTestCase.createSource([ | 2890 Source source = addSource(r''' |
| 2823 "library dart.core;", | 2891 library dart.core; |
| 2824 "const override = null;", | 2892 const override = null; |
| 2825 "class A {", | 2893 class A { |
| 2826 "}", | 2894 } |
| 2827 "class B extends A {", | 2895 class B extends A { |
| 2828 " @override", | 2896 @override |
| 2829 " set m(int x) {}", | 2897 set m(int x) {} |
| 2830 "}"])); | 2898 }'''); |
| 2831 resolve(source); | 2899 resolve(source); |
| 2832 assertErrors(source, [HintCode.OVERRIDE_ON_NON_OVERRIDING_SETTER]); | 2900 assertErrors(source, [HintCode.OVERRIDE_ON_NON_OVERRIDING_SETTER]); |
| 2833 verify([source]); | 2901 verify([source]); |
| 2834 } | 2902 } |
| 2835 | 2903 |
| 2836 void test_typeCheck_type_is_Null() { | 2904 void test_typeCheck_type_is_Null() { |
| 2837 Source source = addSource(EngineTestCase.createSource(["m(i) {", " bool b =
i is Null;", "}"])); | 2905 Source source = addSource(r''' |
| 2906 m(i) { |
| 2907 bool b = i is Null; |
| 2908 }'''); |
| 2838 resolve(source); | 2909 resolve(source); |
| 2839 assertErrors(source, [HintCode.TYPE_CHECK_IS_NULL]); | 2910 assertErrors(source, [HintCode.TYPE_CHECK_IS_NULL]); |
| 2840 verify([source]); | 2911 verify([source]); |
| 2841 } | 2912 } |
| 2842 | 2913 |
| 2843 void test_typeCheck_type_not_Null() { | 2914 void test_typeCheck_type_not_Null() { |
| 2844 Source source = addSource(EngineTestCase.createSource(["m(i) {", " bool b =
i is! Null;", "}"])); | 2915 Source source = addSource(r''' |
| 2916 m(i) { |
| 2917 bool b = i is! Null; |
| 2918 }'''); |
| 2845 resolve(source); | 2919 resolve(source); |
| 2846 assertErrors(source, [HintCode.TYPE_CHECK_IS_NOT_NULL]); | 2920 assertErrors(source, [HintCode.TYPE_CHECK_IS_NOT_NULL]); |
| 2847 verify([source]); | 2921 verify([source]); |
| 2848 } | 2922 } |
| 2849 | 2923 |
| 2850 void test_undefinedGetter() { | 2924 void test_undefinedGetter() { |
| 2851 Source source = addSource(EngineTestCase.createSource([ | 2925 Source source = addSource(r''' |
| 2852 "class A {}", | 2926 class A {} |
| 2853 "f(var a) {", | 2927 f(var a) { |
| 2854 " if(a is A) {", | 2928 if(a is A) { |
| 2855 " return a.m;", | 2929 return a.m; |
| 2856 " }", | 2930 } |
| 2857 "}"])); | 2931 }'''); |
| 2858 resolve(source); | 2932 resolve(source); |
| 2859 assertErrors(source, [HintCode.UNDEFINED_GETTER]); | 2933 assertErrors(source, [HintCode.UNDEFINED_GETTER]); |
| 2860 } | 2934 } |
| 2861 | 2935 |
| 2862 void test_undefinedGetter_message() { | 2936 void test_undefinedGetter_message() { |
| 2863 // The implementation of HintCode.UNDEFINED_SETTER assumes that UNDEFINED_SE
TTER in | 2937 // The implementation of HintCode.UNDEFINED_SETTER assumes that UNDEFINED_SE
TTER in |
| 2864 // StaticTypeWarningCode and StaticWarningCode are the same, this verifies t
hat assumption. | 2938 // StaticTypeWarningCode and StaticWarningCode are the same, this verifies t
hat assumption. |
| 2865 JUnitTestCase.assertEquals(StaticTypeWarningCode.UNDEFINED_GETTER.message, S
taticWarningCode.UNDEFINED_GETTER.message); | 2939 JUnitTestCase.assertEquals(StaticTypeWarningCode.UNDEFINED_GETTER.message, S
taticWarningCode.UNDEFINED_GETTER.message); |
| 2866 } | 2940 } |
| 2867 | 2941 |
| 2868 void test_undefinedMethod() { | 2942 void test_undefinedMethod() { |
| 2869 Source source = addSource(EngineTestCase.createSource([ | 2943 Source source = addSource(r''' |
| 2870 "f() {", | 2944 f() { |
| 2871 " var a = 'str';", | 2945 var a = 'str'; |
| 2872 " a.notAMethodOnString();", | 2946 a.notAMethodOnString(); |
| 2873 "}"])); | 2947 }'''); |
| 2874 resolve(source); | 2948 resolve(source); |
| 2875 assertErrors(source, [HintCode.UNDEFINED_METHOD]); | 2949 assertErrors(source, [HintCode.UNDEFINED_METHOD]); |
| 2876 } | 2950 } |
| 2877 | 2951 |
| 2878 void test_undefinedMethod_assignmentExpression() { | 2952 void test_undefinedMethod_assignmentExpression() { |
| 2879 Source source = addSource(EngineTestCase.createSource([ | 2953 Source source = addSource(r''' |
| 2880 "class A {}", | 2954 class A {} |
| 2881 "class B {", | 2955 class B { |
| 2882 " f(var a, var a2) {", | 2956 f(var a, var a2) { |
| 2883 " a = new A();", | 2957 a = new A(); |
| 2884 " a2 = new A();", | 2958 a2 = new A(); |
| 2885 " a += a2;", | 2959 a += a2; |
| 2886 " }", | 2960 } |
| 2887 "}"])); | 2961 }'''); |
| 2888 resolve(source); | 2962 resolve(source); |
| 2889 assertErrors(source, [HintCode.UNDEFINED_METHOD]); | 2963 assertErrors(source, [HintCode.UNDEFINED_METHOD]); |
| 2890 } | 2964 } |
| 2891 | 2965 |
| 2892 void test_undefinedMethod_unionType_noSuchMethod() { | 2966 void test_undefinedMethod_unionType_noSuchMethod() { |
| 2893 enableUnionTypes(false); | 2967 enableUnionTypes(false); |
| 2894 Source source = addSource(EngineTestCase.createSource([ | 2968 Source source = addSource(r''' |
| 2895 "class A {", | 2969 class A { |
| 2896 " int m(int x) => 0;", | 2970 int m(int x) => 0; |
| 2897 "}", | 2971 } |
| 2898 "class B {", | 2972 class B { |
| 2899 " String m() => '0';", | 2973 String m() => '0'; |
| 2900 "}", | 2974 } |
| 2901 "f(A a, B b) {", | 2975 f(A a, B b) { |
| 2902 " var ab;", | 2976 var ab; |
| 2903 " if (0 < 1) {", | 2977 if (0 < 1) { |
| 2904 " ab = a;", | 2978 ab = a; |
| 2905 " } else {", | 2979 } else { |
| 2906 " ab = b;", | 2980 ab = b; |
| 2907 " }", | 2981 } |
| 2908 " ab.n();", | 2982 ab.n(); |
| 2909 "}"])); | 2983 }'''); |
| 2910 resolve(source); | 2984 resolve(source); |
| 2911 assertErrors(source, [HintCode.UNDEFINED_METHOD]); | 2985 assertErrors(source, [HintCode.UNDEFINED_METHOD]); |
| 2912 } | 2986 } |
| 2913 | 2987 |
| 2914 void test_undefinedOperator_binaryExpression() { | 2988 void test_undefinedOperator_binaryExpression() { |
| 2915 Source source = addSource(EngineTestCase.createSource([ | 2989 Source source = addSource(r''' |
| 2916 "class A {}", | 2990 class A {} |
| 2917 "f(var a) {", | 2991 f(var a) { |
| 2918 " if(a is A) {", | 2992 if(a is A) { |
| 2919 " a + 1;", | 2993 a + 1; |
| 2920 " }", | 2994 } |
| 2921 "}"])); | 2995 }'''); |
| 2922 resolve(source); | 2996 resolve(source); |
| 2923 assertErrors(source, [HintCode.UNDEFINED_OPERATOR]); | 2997 assertErrors(source, [HintCode.UNDEFINED_OPERATOR]); |
| 2924 } | 2998 } |
| 2925 | 2999 |
| 2926 void test_undefinedOperator_indexBoth() { | 3000 void test_undefinedOperator_indexBoth() { |
| 2927 Source source = addSource(EngineTestCase.createSource([ | 3001 Source source = addSource(r''' |
| 2928 "class A {}", | 3002 class A {} |
| 2929 "f(var a) {", | 3003 f(var a) { |
| 2930 " if(a is A) {", | 3004 if(a is A) { |
| 2931 " a[0]++;", | 3005 a[0]++; |
| 2932 " }", | 3006 } |
| 2933 "}"])); | 3007 }'''); |
| 2934 resolve(source); | 3008 resolve(source); |
| 2935 assertErrors(source, [HintCode.UNDEFINED_OPERATOR]); | 3009 assertErrors(source, [HintCode.UNDEFINED_OPERATOR]); |
| 2936 } | 3010 } |
| 2937 | 3011 |
| 2938 void test_undefinedOperator_indexGetter() { | 3012 void test_undefinedOperator_indexGetter() { |
| 2939 Source source = addSource(EngineTestCase.createSource([ | 3013 Source source = addSource(r''' |
| 2940 "class A {}", | 3014 class A {} |
| 2941 "f(var a) {", | 3015 f(var a) { |
| 2942 " if(a is A) {", | 3016 if(a is A) { |
| 2943 " a[0];", | 3017 a[0]; |
| 2944 " }", | 3018 } |
| 2945 "}"])); | 3019 }'''); |
| 2946 resolve(source); | 3020 resolve(source); |
| 2947 assertErrors(source, [HintCode.UNDEFINED_OPERATOR]); | 3021 assertErrors(source, [HintCode.UNDEFINED_OPERATOR]); |
| 2948 } | 3022 } |
| 2949 | 3023 |
| 2950 void test_undefinedOperator_indexSetter() { | 3024 void test_undefinedOperator_indexSetter() { |
| 2951 Source source = addSource(EngineTestCase.createSource([ | 3025 Source source = addSource(r''' |
| 2952 "class A {}", | 3026 class A {} |
| 2953 "f(var a) {", | 3027 f(var a) { |
| 2954 " if(a is A) {", | 3028 if(a is A) { |
| 2955 " a[0] = 1;", | 3029 a[0] = 1; |
| 2956 " }", | 3030 } |
| 2957 "}"])); | 3031 }'''); |
| 2958 resolve(source); | 3032 resolve(source); |
| 2959 assertErrors(source, [HintCode.UNDEFINED_OPERATOR]); | 3033 assertErrors(source, [HintCode.UNDEFINED_OPERATOR]); |
| 2960 } | 3034 } |
| 2961 | 3035 |
| 2962 void test_undefinedOperator_postfixExpression() { | 3036 void test_undefinedOperator_postfixExpression() { |
| 2963 Source source = addSource(EngineTestCase.createSource([ | 3037 Source source = addSource(r''' |
| 2964 "class A {}", | 3038 class A {} |
| 2965 "f(var a) {", | 3039 f(var a) { |
| 2966 " if(a is A) {", | 3040 if(a is A) { |
| 2967 " a++;", | 3041 a++; |
| 2968 " }", | 3042 } |
| 2969 "}"])); | 3043 }'''); |
| 2970 resolve(source); | 3044 resolve(source); |
| 2971 assertErrors(source, [HintCode.UNDEFINED_OPERATOR]); | 3045 assertErrors(source, [HintCode.UNDEFINED_OPERATOR]); |
| 2972 } | 3046 } |
| 2973 | 3047 |
| 2974 void test_undefinedOperator_prefixExpression() { | 3048 void test_undefinedOperator_prefixExpression() { |
| 2975 Source source = addSource(EngineTestCase.createSource([ | 3049 Source source = addSource(r''' |
| 2976 "class A {}", | 3050 class A {} |
| 2977 "f(var a) {", | 3051 f(var a) { |
| 2978 " if(a is A) {", | 3052 if(a is A) { |
| 2979 " ++a;", | 3053 ++a; |
| 2980 " }", | 3054 } |
| 2981 "}"])); | 3055 }'''); |
| 2982 resolve(source); | 3056 resolve(source); |
| 2983 assertErrors(source, [HintCode.UNDEFINED_OPERATOR]); | 3057 assertErrors(source, [HintCode.UNDEFINED_OPERATOR]); |
| 2984 } | 3058 } |
| 2985 | 3059 |
| 2986 void test_undefinedSetter() { | 3060 void test_undefinedSetter() { |
| 2987 Source source = addSource(EngineTestCase.createSource([ | 3061 Source source = addSource(r''' |
| 2988 "class A {}", | 3062 class A {} |
| 2989 "f(var a) {", | 3063 f(var a) { |
| 2990 " if(a is A) {", | 3064 if(a is A) { |
| 2991 " a.m = 0;", | 3065 a.m = 0; |
| 2992 " }", | 3066 } |
| 2993 "}"])); | 3067 }'''); |
| 2994 resolve(source); | 3068 resolve(source); |
| 2995 assertErrors(source, [HintCode.UNDEFINED_SETTER]); | 3069 assertErrors(source, [HintCode.UNDEFINED_SETTER]); |
| 2996 } | 3070 } |
| 2997 | 3071 |
| 2998 void test_undefinedSetter_message() { | 3072 void test_undefinedSetter_message() { |
| 2999 // The implementation of HintCode.UNDEFINED_SETTER assumes that UNDEFINED_SE
TTER in | 3073 // The implementation of HintCode.UNDEFINED_SETTER assumes that UNDEFINED_SE
TTER in |
| 3000 // StaticTypeWarningCode and StaticWarningCode are the same, this verifies t
hat assumption. | 3074 // StaticTypeWarningCode and StaticWarningCode are the same, this verifies t
hat assumption. |
| 3001 JUnitTestCase.assertEquals(StaticTypeWarningCode.UNDEFINED_SETTER.message, S
taticWarningCode.UNDEFINED_SETTER.message); | 3075 JUnitTestCase.assertEquals(StaticTypeWarningCode.UNDEFINED_SETTER.message, S
taticWarningCode.UNDEFINED_SETTER.message); |
| 3002 } | 3076 } |
| 3003 | 3077 |
| 3004 void test_unnecessaryCast_type_supertype() { | 3078 void test_unnecessaryCast_type_supertype() { |
| 3005 Source source = addSource(EngineTestCase.createSource(["m(int i) {", " var
b = i as Object;", "}"])); | 3079 Source source = addSource(r''' |
| 3080 m(int i) { |
| 3081 var b = i as Object; |
| 3082 }'''); |
| 3006 resolve(source); | 3083 resolve(source); |
| 3007 assertErrors(source, [HintCode.UNNECESSARY_CAST]); | 3084 assertErrors(source, [HintCode.UNNECESSARY_CAST]); |
| 3008 verify([source]); | 3085 verify([source]); |
| 3009 } | 3086 } |
| 3010 | 3087 |
| 3011 void test_unnecessaryCast_type_type() { | 3088 void test_unnecessaryCast_type_type() { |
| 3012 Source source = addSource(EngineTestCase.createSource(["m(num i) {", " var
b = i as num;", "}"])); | 3089 Source source = addSource(r''' |
| 3090 m(num i) { |
| 3091 var b = i as num; |
| 3092 }'''); |
| 3013 resolve(source); | 3093 resolve(source); |
| 3014 assertErrors(source, [HintCode.UNNECESSARY_CAST]); | 3094 assertErrors(source, [HintCode.UNNECESSARY_CAST]); |
| 3015 verify([source]); | 3095 verify([source]); |
| 3016 } | 3096 } |
| 3017 | 3097 |
| 3018 void test_unnecessaryTypeCheck_null_is_Null() { | 3098 void test_unnecessaryTypeCheck_null_is_Null() { |
| 3019 Source source = addSource(EngineTestCase.createSource(["bool b = null is Nul
l;"])); | 3099 Source source = addSource("bool b = null is Null;"); |
| 3020 resolve(source); | 3100 resolve(source); |
| 3021 assertErrors(source, [HintCode.UNNECESSARY_TYPE_CHECK_TRUE]); | 3101 assertErrors(source, [HintCode.UNNECESSARY_TYPE_CHECK_TRUE]); |
| 3022 verify([source]); | 3102 verify([source]); |
| 3023 } | 3103 } |
| 3024 | 3104 |
| 3025 void test_unnecessaryTypeCheck_null_not_Null() { | 3105 void test_unnecessaryTypeCheck_null_not_Null() { |
| 3026 Source source = addSource(EngineTestCase.createSource(["bool b = null is! Nu
ll;"])); | 3106 Source source = addSource("bool b = null is! Null;"); |
| 3027 resolve(source); | 3107 resolve(source); |
| 3028 assertErrors(source, [HintCode.UNNECESSARY_TYPE_CHECK_FALSE]); | 3108 assertErrors(source, [HintCode.UNNECESSARY_TYPE_CHECK_FALSE]); |
| 3029 verify([source]); | 3109 verify([source]); |
| 3030 } | 3110 } |
| 3031 | 3111 |
| 3032 void test_unnecessaryTypeCheck_type_is_dynamic() { | 3112 void test_unnecessaryTypeCheck_type_is_dynamic() { |
| 3033 Source source = addSource(EngineTestCase.createSource(["m(i) {", " bool b =
i is dynamic;", "}"])); | 3113 Source source = addSource(r''' |
| 3114 m(i) { |
| 3115 bool b = i is dynamic; |
| 3116 }'''); |
| 3034 resolve(source); | 3117 resolve(source); |
| 3035 assertErrors(source, [HintCode.UNNECESSARY_TYPE_CHECK_TRUE]); | 3118 assertErrors(source, [HintCode.UNNECESSARY_TYPE_CHECK_TRUE]); |
| 3036 verify([source]); | 3119 verify([source]); |
| 3037 } | 3120 } |
| 3038 | 3121 |
| 3039 void test_unnecessaryTypeCheck_type_is_object() { | 3122 void test_unnecessaryTypeCheck_type_is_object() { |
| 3040 Source source = addSource(EngineTestCase.createSource(["m(i) {", " bool b =
i is Object;", "}"])); | 3123 Source source = addSource(r''' |
| 3124 m(i) { |
| 3125 bool b = i is Object; |
| 3126 }'''); |
| 3041 resolve(source); | 3127 resolve(source); |
| 3042 assertErrors(source, [HintCode.UNNECESSARY_TYPE_CHECK_TRUE]); | 3128 assertErrors(source, [HintCode.UNNECESSARY_TYPE_CHECK_TRUE]); |
| 3043 verify([source]); | 3129 verify([source]); |
| 3044 } | 3130 } |
| 3045 | 3131 |
| 3046 void test_unnecessaryTypeCheck_type_not_dynamic() { | 3132 void test_unnecessaryTypeCheck_type_not_dynamic() { |
| 3047 Source source = addSource(EngineTestCase.createSource(["m(i) {", " bool b =
i is! dynamic;", "}"])); | 3133 Source source = addSource(r''' |
| 3134 m(i) { |
| 3135 bool b = i is! dynamic; |
| 3136 }'''); |
| 3048 resolve(source); | 3137 resolve(source); |
| 3049 assertErrors(source, [HintCode.UNNECESSARY_TYPE_CHECK_FALSE]); | 3138 assertErrors(source, [HintCode.UNNECESSARY_TYPE_CHECK_FALSE]); |
| 3050 verify([source]); | 3139 verify([source]); |
| 3051 } | 3140 } |
| 3052 | 3141 |
| 3053 void test_unnecessaryTypeCheck_type_not_object() { | 3142 void test_unnecessaryTypeCheck_type_not_object() { |
| 3054 Source source = addSource(EngineTestCase.createSource(["m(i) {", " bool b =
i is! Object;", "}"])); | 3143 Source source = addSource(r''' |
| 3144 m(i) { |
| 3145 bool b = i is! Object; |
| 3146 }'''); |
| 3055 resolve(source); | 3147 resolve(source); |
| 3056 assertErrors(source, [HintCode.UNNECESSARY_TYPE_CHECK_FALSE]); | 3148 assertErrors(source, [HintCode.UNNECESSARY_TYPE_CHECK_FALSE]); |
| 3057 verify([source]); | 3149 verify([source]); |
| 3058 } | 3150 } |
| 3059 | 3151 |
| 3060 void test_unusedImport() { | 3152 void test_unusedImport() { |
| 3061 Source source = addSource(EngineTestCase.createSource(["library L;", "import
'lib1.dart';"])); | 3153 Source source = addSource(r''' |
| 3062 Source source2 = addNamedSource("/lib1.dart", EngineTestCase.createSource(["
library lib1;"])); | 3154 library L; |
| 3155 import 'lib1.dart';'''); |
| 3156 Source source2 = addNamedSource("/lib1.dart", "library lib1;"); |
| 3063 resolve(source); | 3157 resolve(source); |
| 3064 assertErrors(source, [HintCode.UNUSED_IMPORT]); | 3158 assertErrors(source, [HintCode.UNUSED_IMPORT]); |
| 3065 assertNoErrors(source2); | 3159 assertNoErrors(source2); |
| 3066 verify([source, source2]); | 3160 verify([source, source2]); |
| 3067 } | 3161 } |
| 3068 | 3162 |
| 3069 void test_unusedImport_as() { | 3163 void test_unusedImport_as() { |
| 3070 Source source = addSource(EngineTestCase.createSource([ | 3164 Source source = addSource(r''' |
| 3071 "library L;", | 3165 library L; |
| 3072 "import 'lib1.dart';", | 3166 import 'lib1.dart'; |
| 3073 "import 'lib1.dart' as one;", | 3167 import 'lib1.dart' as one; |
| 3074 "one.A a;"])); | 3168 one.A a;'''); |
| 3075 Source source2 = addNamedSource("/lib1.dart", EngineTestCase.createSource(["
library lib1;", "class A {}"])); | 3169 Source source2 = addNamedSource("/lib1.dart", r''' |
| 3170 library lib1; |
| 3171 class A {}'''); |
| 3076 resolve(source); | 3172 resolve(source); |
| 3077 assertErrors(source, [HintCode.UNUSED_IMPORT]); | 3173 assertErrors(source, [HintCode.UNUSED_IMPORT]); |
| 3078 assertNoErrors(source2); | 3174 assertNoErrors(source2); |
| 3079 verify([source, source2]); | 3175 verify([source, source2]); |
| 3080 } | 3176 } |
| 3081 | 3177 |
| 3082 void test_unusedImport_hide() { | 3178 void test_unusedImport_hide() { |
| 3083 Source source = addSource(EngineTestCase.createSource([ | 3179 Source source = addSource(r''' |
| 3084 "library L;", | 3180 library L; |
| 3085 "import 'lib1.dart';", | 3181 import 'lib1.dart'; |
| 3086 "import 'lib1.dart' hide A;", | 3182 import 'lib1.dart' hide A; |
| 3087 "A a;"])); | 3183 A a;'''); |
| 3088 Source source2 = addNamedSource("/lib1.dart", EngineTestCase.createSource(["
library lib1;", "class A {}"])); | 3184 Source source2 = addNamedSource("/lib1.dart", r''' |
| 3185 library lib1; |
| 3186 class A {}'''); |
| 3089 resolve(source); | 3187 resolve(source); |
| 3090 assertErrors(source, [HintCode.UNUSED_IMPORT]); | 3188 assertErrors(source, [HintCode.UNUSED_IMPORT]); |
| 3091 assertNoErrors(source2); | 3189 assertNoErrors(source2); |
| 3092 verify([source, source2]); | 3190 verify([source, source2]); |
| 3093 } | 3191 } |
| 3094 | 3192 |
| 3095 void test_unusedImport_show() { | 3193 void test_unusedImport_show() { |
| 3096 Source source = addSource(EngineTestCase.createSource([ | 3194 Source source = addSource(r''' |
| 3097 "library L;", | 3195 library L; |
| 3098 "import 'lib1.dart' show A;", | 3196 import 'lib1.dart' show A; |
| 3099 "import 'lib1.dart' show B;", | 3197 import 'lib1.dart' show B; |
| 3100 "A a;"])); | 3198 A a;'''); |
| 3101 Source source2 = addNamedSource("/lib1.dart", EngineTestCase.createSource(["
library lib1;", "class A {}", "class B {}"])); | 3199 Source source2 = addNamedSource("/lib1.dart", r''' |
| 3200 library lib1; |
| 3201 class A {} |
| 3202 class B {}'''); |
| 3102 resolve(source); | 3203 resolve(source); |
| 3103 assertErrors(source, [HintCode.UNUSED_IMPORT]); | 3204 assertErrors(source, [HintCode.UNUSED_IMPORT]); |
| 3104 assertNoErrors(source2); | 3205 assertNoErrors(source2); |
| 3105 verify([source, source2]); | 3206 verify([source, source2]); |
| 3106 } | 3207 } |
| 3107 | 3208 |
| 3108 void test_useOfVoidResult_assignmentExpression_function() { | 3209 void test_useOfVoidResult_assignmentExpression_function() { |
| 3109 Source source = addSource(EngineTestCase.createSource([ | 3210 Source source = addSource(r''' |
| 3110 "void f() {}", | 3211 void f() {} |
| 3111 "class A {", | 3212 class A { |
| 3112 " n() {", | 3213 n() { |
| 3113 " var a;", | 3214 var a; |
| 3114 " a = f();", | 3215 a = f(); |
| 3115 " }", | 3216 } |
| 3116 "}"])); | 3217 }'''); |
| 3117 resolve(source); | 3218 resolve(source); |
| 3118 assertErrors(source, [HintCode.USE_OF_VOID_RESULT]); | 3219 assertErrors(source, [HintCode.USE_OF_VOID_RESULT]); |
| 3119 verify([source]); | 3220 verify([source]); |
| 3120 } | 3221 } |
| 3121 | 3222 |
| 3122 void test_useOfVoidResult_assignmentExpression_method() { | 3223 void test_useOfVoidResult_assignmentExpression_method() { |
| 3123 Source source = addSource(EngineTestCase.createSource([ | 3224 Source source = addSource(r''' |
| 3124 "class A {", | 3225 class A { |
| 3125 " void m() {}", | 3226 void m() {} |
| 3126 " n() {", | 3227 n() { |
| 3127 " var a;", | 3228 var a; |
| 3128 " a = m();", | 3229 a = m(); |
| 3129 " }", | 3230 } |
| 3130 "}"])); | 3231 }'''); |
| 3131 resolve(source); | 3232 resolve(source); |
| 3132 assertErrors(source, [HintCode.USE_OF_VOID_RESULT]); | 3233 assertErrors(source, [HintCode.USE_OF_VOID_RESULT]); |
| 3133 verify([source]); | 3234 verify([source]); |
| 3134 } | 3235 } |
| 3135 | 3236 |
| 3136 void test_useOfVoidResult_inForLoop() { | 3237 void test_useOfVoidResult_inForLoop() { |
| 3137 Source source = addSource(EngineTestCase.createSource([ | 3238 Source source = addSource(r''' |
| 3138 "class A {", | 3239 class A { |
| 3139 " void m() {}", | 3240 void m() {} |
| 3140 " n() {", | 3241 n() { |
| 3141 " for(var a = m();;) {}", | 3242 for(var a = m();;) {} |
| 3142 " }", | 3243 } |
| 3143 "}"])); | 3244 }'''); |
| 3144 resolve(source); | 3245 resolve(source); |
| 3145 assertErrors(source, [HintCode.USE_OF_VOID_RESULT]); | 3246 assertErrors(source, [HintCode.USE_OF_VOID_RESULT]); |
| 3146 verify([source]); | 3247 verify([source]); |
| 3147 } | 3248 } |
| 3148 | 3249 |
| 3149 void test_useOfVoidResult_variableDeclaration_function() { | 3250 void test_useOfVoidResult_variableDeclaration_function() { |
| 3150 Source source = addSource(EngineTestCase.createSource([ | 3251 Source source = addSource(r''' |
| 3151 "void f() {}", | 3252 void f() {} |
| 3152 "class A {", | 3253 class A { |
| 3153 " n() {", | 3254 n() { |
| 3154 " var a = f();", | 3255 var a = f(); |
| 3155 " }", | 3256 } |
| 3156 "}"])); | 3257 }'''); |
| 3157 resolve(source); | 3258 resolve(source); |
| 3158 assertErrors(source, [HintCode.USE_OF_VOID_RESULT]); | 3259 assertErrors(source, [HintCode.USE_OF_VOID_RESULT]); |
| 3159 verify([source]); | 3260 verify([source]); |
| 3160 } | 3261 } |
| 3161 | 3262 |
| 3162 void test_useOfVoidResult_variableDeclaration_method() { | 3263 void test_useOfVoidResult_variableDeclaration_method() { |
| 3163 Source source = addSource(EngineTestCase.createSource([ | 3264 Source source = addSource(r''' |
| 3164 "class A {", | 3265 class A { |
| 3165 " void m() {}", | 3266 void m() {} |
| 3166 " n() {", | 3267 n() { |
| 3167 " var a = m();", | 3268 var a = m(); |
| 3168 " }", | 3269 } |
| 3169 "}"])); | 3270 }'''); |
| 3170 resolve(source); | 3271 resolve(source); |
| 3171 assertErrors(source, [HintCode.USE_OF_VOID_RESULT]); | 3272 assertErrors(source, [HintCode.USE_OF_VOID_RESULT]); |
| 3172 verify([source]); | 3273 verify([source]); |
| 3173 } | 3274 } |
| 3174 | 3275 |
| 3175 void test_useOfVoidResult_variableDeclaration_method2() { | 3276 void test_useOfVoidResult_variableDeclaration_method2() { |
| 3176 Source source = addSource(EngineTestCase.createSource([ | 3277 Source source = addSource(r''' |
| 3177 "class A {", | 3278 class A { |
| 3178 " void m() {}", | 3279 void m() {} |
| 3179 " n() {", | 3280 n() { |
| 3180 " var a = m(), b = m();", | 3281 var a = m(), b = m(); |
| 3181 " }", | 3282 } |
| 3182 "}"])); | 3283 }'''); |
| 3183 resolve(source); | 3284 resolve(source); |
| 3184 assertErrors(source, [HintCode.USE_OF_VOID_RESULT, HintCode.USE_OF_VOID_RESU
LT]); | 3285 assertErrors(source, [HintCode.USE_OF_VOID_RESULT, HintCode.USE_OF_VOID_RESU
LT]); |
| 3185 verify([source]); | 3286 verify([source]); |
| 3186 } | 3287 } |
| 3187 } | 3288 } |
| 3188 | 3289 |
| 3189 class IncrementalResolverTest extends ResolverTestCase { | 3290 class IncrementalResolverTest extends ResolverTestCase { |
| 3190 void test_resolve() { | 3291 void test_resolve() { |
| 3191 MethodDeclaration method = _resolveMethod(EngineTestCase.createSource([ | 3292 MethodDeclaration method = _resolveMethod(r''' |
| 3192 "class C {", | 3293 class C { |
| 3193 " int m(int a) {", | 3294 int m(int a) { |
| 3194 " return a + a;", | 3295 return a + a; |
| 3195 " }", | 3296 } |
| 3196 "}"])); | 3297 }'''); |
| 3197 BlockFunctionBody body = method.body as BlockFunctionBody; | 3298 BlockFunctionBody body = method.body as BlockFunctionBody; |
| 3198 ReturnStatement statement = body.block.statements[0] as ReturnStatement; | 3299 ReturnStatement statement = body.block.statements[0] as ReturnStatement; |
| 3199 BinaryExpression expression = statement.expression as BinaryExpression; | 3300 BinaryExpression expression = statement.expression as BinaryExpression; |
| 3200 SimpleIdentifier left = expression.leftOperand as SimpleIdentifier; | 3301 SimpleIdentifier left = expression.leftOperand as SimpleIdentifier; |
| 3201 Element leftElement = left.staticElement; | 3302 Element leftElement = left.staticElement; |
| 3202 SimpleIdentifier right = expression.rightOperand as SimpleIdentifier; | 3303 SimpleIdentifier right = expression.rightOperand as SimpleIdentifier; |
| 3203 Element rightElement = right.staticElement; | 3304 Element rightElement = right.staticElement; |
| 3204 JUnitTestCase.assertNotNull(leftElement); | 3305 JUnitTestCase.assertNotNull(leftElement); |
| 3205 JUnitTestCase.assertSame(leftElement, rightElement); | 3306 JUnitTestCase.assertSame(leftElement, rightElement); |
| 3206 } | 3307 } |
| (...skipping 1030 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4237 @override | 4338 @override |
| 4238 void setUp() { | 4339 void setUp() { |
| 4239 SourceFactory sourceFactory = new SourceFactory([ | 4340 SourceFactory sourceFactory = new SourceFactory([ |
| 4240 new DartUriResolver(DirectoryBasedDartSdk.defaultSdk), | 4341 new DartUriResolver(DirectoryBasedDartSdk.defaultSdk), |
| 4241 new FileUriResolver()]); | 4342 new FileUriResolver()]); |
| 4242 _context = new AnalysisContextImpl(); | 4343 _context = new AnalysisContextImpl(); |
| 4243 _context.sourceFactory = sourceFactory; | 4344 _context.sourceFactory = sourceFactory; |
| 4244 } | 4345 } |
| 4245 | 4346 |
| 4246 void test_accessorsAcrossFiles() { | 4347 void test_accessorsAcrossFiles() { |
| 4247 Source librarySource = addSource("/lib.dart", EngineTestCase.createSource([ | 4348 Source librarySource = addSource("/lib.dart", r''' |
| 4248 "library lib;", | 4349 library lib; |
| 4249 "part 'first.dart';", | 4350 part 'first.dart'; |
| 4250 "part 'second.dart';"])); | 4351 part 'second.dart';'''); |
| 4251 addSource("/first.dart", EngineTestCase.createSource(["part of lib;", "int g
et V => 0;"])); | 4352 addSource("/first.dart", r''' |
| 4252 addSource("/second.dart", EngineTestCase.createSource(["part of lib;", "void
set V(int v) {}"])); | 4353 part of lib; |
| 4354 int get V => 0;'''); |
| 4355 addSource("/second.dart", r''' |
| 4356 part of lib; |
| 4357 void set V(int v) {}'''); |
| 4253 LibraryElement element = _buildLibrary(librarySource, []); | 4358 LibraryElement element = _buildLibrary(librarySource, []); |
| 4254 JUnitTestCase.assertNotNull(element); | 4359 JUnitTestCase.assertNotNull(element); |
| 4255 List<CompilationUnitElement> sourcedUnits = element.parts; | 4360 List<CompilationUnitElement> sourcedUnits = element.parts; |
| 4256 EngineTestCase.assertLength(2, sourcedUnits); | 4361 EngineTestCase.assertLength(2, sourcedUnits); |
| 4257 List<PropertyAccessorElement> firstAccessors = sourcedUnits[0].accessors; | 4362 List<PropertyAccessorElement> firstAccessors = sourcedUnits[0].accessors; |
| 4258 EngineTestCase.assertLength(1, firstAccessors); | 4363 EngineTestCase.assertLength(1, firstAccessors); |
| 4259 List<PropertyAccessorElement> secondAccessors = sourcedUnits[1].accessors; | 4364 List<PropertyAccessorElement> secondAccessors = sourcedUnits[1].accessors; |
| 4260 EngineTestCase.assertLength(1, secondAccessors); | 4365 EngineTestCase.assertLength(1, secondAccessors); |
| 4261 JUnitTestCase.assertSame(firstAccessors[0].variable, secondAccessors[0].vari
able); | 4366 JUnitTestCase.assertSame(firstAccessors[0].variable, secondAccessors[0].vari
able); |
| 4262 } | 4367 } |
| (...skipping 14 matching lines...) Expand all Loading... |
| 4277 JUnitTestCase.assertEquals("lib.dart", unit.name); | 4382 JUnitTestCase.assertEquals("lib.dart", unit.name); |
| 4278 JUnitTestCase.assertEquals(element, unit.library); | 4383 JUnitTestCase.assertEquals(element, unit.library); |
| 4279 EngineTestCase.assertLength(0, unit.accessors); | 4384 EngineTestCase.assertLength(0, unit.accessors); |
| 4280 EngineTestCase.assertLength(0, unit.functions); | 4385 EngineTestCase.assertLength(0, unit.functions); |
| 4281 EngineTestCase.assertLength(0, unit.functionTypeAliases); | 4386 EngineTestCase.assertLength(0, unit.functionTypeAliases); |
| 4282 EngineTestCase.assertLength(0, unit.types); | 4387 EngineTestCase.assertLength(0, unit.types); |
| 4283 EngineTestCase.assertLength(0, unit.topLevelVariables); | 4388 EngineTestCase.assertLength(0, unit.topLevelVariables); |
| 4284 } | 4389 } |
| 4285 | 4390 |
| 4286 void test_missingLibraryDirectiveWithPart() { | 4391 void test_missingLibraryDirectiveWithPart() { |
| 4287 addSource("/a.dart", EngineTestCase.createSource(["part of lib;"])); | 4392 addSource("/a.dart", "part of lib;"); |
| 4288 Source librarySource = addSource("/lib.dart", EngineTestCase.createSource(["
part 'a.dart';"])); | 4393 Source librarySource = addSource("/lib.dart", "part 'a.dart';"); |
| 4289 LibraryElement element = _buildLibrary(librarySource, [ResolverErrorCode.MIS
SING_LIBRARY_DIRECTIVE_WITH_PART]); | 4394 LibraryElement element = _buildLibrary(librarySource, [ResolverErrorCode.MIS
SING_LIBRARY_DIRECTIVE_WITH_PART]); |
| 4290 JUnitTestCase.assertNotNull(element); | 4395 JUnitTestCase.assertNotNull(element); |
| 4291 } | 4396 } |
| 4292 | 4397 |
| 4293 void test_missingPartOfDirective() { | 4398 void test_missingPartOfDirective() { |
| 4294 addSource("/a.dart", "class A {}"); | 4399 addSource("/a.dart", "class A {}"); |
| 4295 Source librarySource = addSource("/lib.dart", EngineTestCase.createSource(["
library lib;", "", "part 'a.dart';"])); | 4400 Source librarySource = addSource("/lib.dart", r''' |
| 4401 library lib; |
| 4402 |
| 4403 part 'a.dart';'''); |
| 4296 LibraryElement element = _buildLibrary(librarySource, [CompileTimeErrorCode.
PART_OF_NON_PART]); | 4404 LibraryElement element = _buildLibrary(librarySource, [CompileTimeErrorCode.
PART_OF_NON_PART]); |
| 4297 JUnitTestCase.assertNotNull(element); | 4405 JUnitTestCase.assertNotNull(element); |
| 4298 } | 4406 } |
| 4299 | 4407 |
| 4300 void test_multipleFiles() { | 4408 void test_multipleFiles() { |
| 4301 Source librarySource = addSource("/lib.dart", EngineTestCase.createSource([ | 4409 Source librarySource = addSource("/lib.dart", r''' |
| 4302 "library lib;", | 4410 library lib; |
| 4303 "part 'first.dart';", | 4411 part 'first.dart'; |
| 4304 "part 'second.dart';", | 4412 part 'second.dart'; |
| 4305 "", | 4413 |
| 4306 "class A {}"])); | 4414 class A {}'''); |
| 4307 addSource("/first.dart", EngineTestCase.createSource(["part of lib;", "class
B {}"])); | 4415 addSource("/first.dart", r''' |
| 4308 addSource("/second.dart", EngineTestCase.createSource(["part of lib;", "clas
s C {}"])); | 4416 part of lib; |
| 4417 class B {}'''); |
| 4418 addSource("/second.dart", r''' |
| 4419 part of lib; |
| 4420 class C {}'''); |
| 4309 LibraryElement element = _buildLibrary(librarySource, []); | 4421 LibraryElement element = _buildLibrary(librarySource, []); |
| 4310 JUnitTestCase.assertNotNull(element); | 4422 JUnitTestCase.assertNotNull(element); |
| 4311 List<CompilationUnitElement> sourcedUnits = element.parts; | 4423 List<CompilationUnitElement> sourcedUnits = element.parts; |
| 4312 EngineTestCase.assertLength(2, sourcedUnits); | 4424 EngineTestCase.assertLength(2, sourcedUnits); |
| 4313 _assertTypes(element.definingCompilationUnit, ["A"]); | 4425 _assertTypes(element.definingCompilationUnit, ["A"]); |
| 4314 if (sourcedUnits[0].name == "first.dart") { | 4426 if (sourcedUnits[0].name == "first.dart") { |
| 4315 _assertTypes(sourcedUnits[0], ["B"]); | 4427 _assertTypes(sourcedUnits[0], ["B"]); |
| 4316 _assertTypes(sourcedUnits[1], ["C"]); | 4428 _assertTypes(sourcedUnits[1], ["C"]); |
| 4317 } else { | 4429 } else { |
| 4318 _assertTypes(sourcedUnits[0], ["C"]); | 4430 _assertTypes(sourcedUnits[0], ["C"]); |
| 4319 _assertTypes(sourcedUnits[1], ["B"]); | 4431 _assertTypes(sourcedUnits[1], ["B"]); |
| 4320 } | 4432 } |
| 4321 } | 4433 } |
| 4322 | 4434 |
| 4323 void test_singleFile() { | 4435 void test_singleFile() { |
| 4324 Source librarySource = addSource("/lib.dart", EngineTestCase.createSource(["
library lib;", "", "class A {}"])); | 4436 Source librarySource = addSource("/lib.dart", r''' |
| 4437 library lib; |
| 4438 |
| 4439 class A {}'''); |
| 4325 LibraryElement element = _buildLibrary(librarySource, []); | 4440 LibraryElement element = _buildLibrary(librarySource, []); |
| 4326 JUnitTestCase.assertNotNull(element); | 4441 JUnitTestCase.assertNotNull(element); |
| 4327 _assertTypes(element.definingCompilationUnit, ["A"]); | 4442 _assertTypes(element.definingCompilationUnit, ["A"]); |
| 4328 } | 4443 } |
| 4329 | 4444 |
| 4330 /** | 4445 /** |
| 4331 * Add a source file to the content provider. The file path should be absolute
. | 4446 * Add a source file to the content provider. The file path should be absolute
. |
| 4332 * | 4447 * |
| 4333 * @param filePath the path of the file being added | 4448 * @param filePath the path of the file being added |
| 4334 * @param contents the contents to be returned by the content provider for the
specified file | 4449 * @param contents the contents to be returned by the content provider for the
specified file |
| (...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4540 Source _coreLibrarySource; | 4655 Source _coreLibrarySource; |
| 4541 | 4656 |
| 4542 @override | 4657 @override |
| 4543 void setUp() { | 4658 void setUp() { |
| 4544 super.setUp(); | 4659 super.setUp(); |
| 4545 _resolver = new LibraryResolver2(analysisContext2); | 4660 _resolver = new LibraryResolver2(analysisContext2); |
| 4546 _coreLibrarySource = analysisContext2.sourceFactory.forUri(DartSdk.DART_CORE
); | 4661 _coreLibrarySource = analysisContext2.sourceFactory.forUri(DartSdk.DART_CORE
); |
| 4547 } | 4662 } |
| 4548 | 4663 |
| 4549 void test_imports_relative() { | 4664 void test_imports_relative() { |
| 4550 Source sourceA = addSource(EngineTestCase.createSource(["library libA;", "im
port 'libB.dart';", "class A {}"])); | 4665 Source sourceA = addSource(r''' |
| 4551 Source sourceB = addNamedSource("/libB.dart", EngineTestCase.createSource(["
library libB;", "import 'test.dart", "class B {}"])); | 4666 library libA; |
| 4667 import 'libB.dart'; |
| 4668 class A {}'''); |
| 4669 Source sourceB = addNamedSource("/libB.dart", r''' |
| 4670 library libB; |
| 4671 import 'test.dart |
| 4672 class B {}'''); |
| 4552 List<ResolvableLibrary> cycle = new List<ResolvableLibrary>(); | 4673 List<ResolvableLibrary> cycle = new List<ResolvableLibrary>(); |
| 4553 ResolvableLibrary coreLib = _createResolvableLibrary(_coreLibrarySource); | 4674 ResolvableLibrary coreLib = _createResolvableLibrary(_coreLibrarySource); |
| 4554 coreLib.libraryElement = analysisContext2.computeLibraryElement(_coreLibrary
Source) as LibraryElementImpl; | 4675 coreLib.libraryElement = analysisContext2.computeLibraryElement(_coreLibrary
Source) as LibraryElementImpl; |
| 4555 ResolvableLibrary libA = _createResolvableLibrary(sourceA); | 4676 ResolvableLibrary libA = _createResolvableLibrary(sourceA); |
| 4556 ResolvableLibrary libB = _createResolvableLibrary(sourceB); | 4677 ResolvableLibrary libB = _createResolvableLibrary(sourceB); |
| 4557 libA.importedLibraries = <ResolvableLibrary> [coreLib, libB]; | 4678 libA.importedLibraries = <ResolvableLibrary> [coreLib, libB]; |
| 4558 libB.importedLibraries = <ResolvableLibrary> [coreLib, libA]; | 4679 libB.importedLibraries = <ResolvableLibrary> [coreLib, libA]; |
| 4559 cycle.add(libA); | 4680 cycle.add(libA); |
| 4560 cycle.add(libB); | 4681 cycle.add(libB); |
| 4561 LibraryElement library = _resolver.resolveLibrary(sourceA, cycle); | 4682 LibraryElement library = _resolver.resolveLibrary(sourceA, cycle); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 4576 class LibraryResolverTest extends ResolverTestCase { | 4697 class LibraryResolverTest extends ResolverTestCase { |
| 4577 LibraryResolver _resolver; | 4698 LibraryResolver _resolver; |
| 4578 | 4699 |
| 4579 @override | 4700 @override |
| 4580 void setUp() { | 4701 void setUp() { |
| 4581 super.setUp(); | 4702 super.setUp(); |
| 4582 _resolver = new LibraryResolver(analysisContext2); | 4703 _resolver = new LibraryResolver(analysisContext2); |
| 4583 } | 4704 } |
| 4584 | 4705 |
| 4585 void test_imports_dart_html() { | 4706 void test_imports_dart_html() { |
| 4586 Source source = addSource(EngineTestCase.createSource(["library libA;", "imp
ort 'dart:html';", "class A {}"])); | 4707 Source source = addSource(r''' |
| 4708 library libA; |
| 4709 import 'dart:html'; |
| 4710 class A {}'''); |
| 4587 LibraryElement library = _resolver.resolveLibrary(source, true); | 4711 LibraryElement library = _resolver.resolveLibrary(source, true); |
| 4588 List<LibraryElement> importedLibraries = library.importedLibraries; | 4712 List<LibraryElement> importedLibraries = library.importedLibraries; |
| 4589 assertNamedElements(importedLibraries, ["dart.core", "dart.dom.html"]); | 4713 assertNamedElements(importedLibraries, ["dart.core", "dart.dom.html"]); |
| 4590 } | 4714 } |
| 4591 | 4715 |
| 4592 void test_imports_none() { | 4716 void test_imports_none() { |
| 4593 Source source = addSource(EngineTestCase.createSource(["library libA;", "cla
ss A {}"])); | 4717 Source source = addSource(r''' |
| 4718 library libA; |
| 4719 class A {}'''); |
| 4594 LibraryElement library = _resolver.resolveLibrary(source, true); | 4720 LibraryElement library = _resolver.resolveLibrary(source, true); |
| 4595 List<LibraryElement> importedLibraries = library.importedLibraries; | 4721 List<LibraryElement> importedLibraries = library.importedLibraries; |
| 4596 assertNamedElements(importedLibraries, ["dart.core"]); | 4722 assertNamedElements(importedLibraries, ["dart.core"]); |
| 4597 } | 4723 } |
| 4598 | 4724 |
| 4599 void test_imports_relative() { | 4725 void test_imports_relative() { |
| 4600 addNamedSource("/libB.dart", "library libB;"); | 4726 addNamedSource("/libB.dart", "library libB;"); |
| 4601 Source source = addSource(EngineTestCase.createSource(["library libA;", "imp
ort 'libB.dart';", "class A {}"])); | 4727 Source source = addSource(r''' |
| 4728 library libA; |
| 4729 import 'libB.dart'; |
| 4730 class A {}'''); |
| 4602 LibraryElement library = _resolver.resolveLibrary(source, true); | 4731 LibraryElement library = _resolver.resolveLibrary(source, true); |
| 4603 List<LibraryElement> importedLibraries = library.importedLibraries; | 4732 List<LibraryElement> importedLibraries = library.importedLibraries; |
| 4604 assertNamedElements(importedLibraries, ["dart.core", "libB"]); | 4733 assertNamedElements(importedLibraries, ["dart.core", "libB"]); |
| 4605 } | 4734 } |
| 4606 } | 4735 } |
| 4607 | 4736 |
| 4608 class LibraryScopeTest extends ResolverTestCase { | 4737 class LibraryScopeTest extends ResolverTestCase { |
| 4609 void test_creation_empty() { | 4738 void test_creation_empty() { |
| 4610 LibraryElement definingLibrary = createDefaultTestLibrary(); | 4739 LibraryElement definingLibrary = createDefaultTestLibrary(); |
| 4611 GatheringErrorListener errorListener = new GatheringErrorListener(); | 4740 GatheringErrorListener errorListener = new GatheringErrorListener(); |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4783 MemberMap map = new MemberMap(); | 4912 MemberMap map = new MemberMap(); |
| 4784 JUnitTestCase.assertEquals(0, map.size); | 4913 JUnitTestCase.assertEquals(0, map.size); |
| 4785 map.put(m1.name, m1); | 4914 map.put(m1.name, m1); |
| 4786 JUnitTestCase.assertEquals(1, map.size); | 4915 JUnitTestCase.assertEquals(1, map.size); |
| 4787 JUnitTestCase.assertEquals(m1, map.get("m1")); | 4916 JUnitTestCase.assertEquals(m1, map.get("m1")); |
| 4788 } | 4917 } |
| 4789 } | 4918 } |
| 4790 | 4919 |
| 4791 class NonHintCodeTest extends ResolverTestCase { | 4920 class NonHintCodeTest extends ResolverTestCase { |
| 4792 void test_deadCode_deadBlock_conditionalElse_debugConst() { | 4921 void test_deadCode_deadBlock_conditionalElse_debugConst() { |
| 4793 Source source = addSource(EngineTestCase.createSource([ | 4922 Source source = addSource(r''' |
| 4794 "const bool DEBUG = true;", | 4923 const bool DEBUG = true; |
| 4795 "f() {", | 4924 f() { |
| 4796 " DEBUG ? 1 : 2;", | 4925 DEBUG ? 1 : 2; |
| 4797 "}"])); | 4926 }'''); |
| 4798 resolve(source); | 4927 resolve(source); |
| 4799 assertNoErrors(source); | 4928 assertNoErrors(source); |
| 4800 verify([source]); | 4929 verify([source]); |
| 4801 } | 4930 } |
| 4802 | 4931 |
| 4803 void test_deadCode_deadBlock_conditionalIf_debugConst() { | 4932 void test_deadCode_deadBlock_conditionalIf_debugConst() { |
| 4804 Source source = addSource(EngineTestCase.createSource([ | 4933 Source source = addSource(r''' |
| 4805 "const bool DEBUG = false;", | 4934 const bool DEBUG = false; |
| 4806 "f() {", | 4935 f() { |
| 4807 " DEBUG ? 1 : 2;", | 4936 DEBUG ? 1 : 2; |
| 4808 "}"])); | 4937 }'''); |
| 4809 resolve(source); | 4938 resolve(source); |
| 4810 assertNoErrors(source); | 4939 assertNoErrors(source); |
| 4811 verify([source]); | 4940 verify([source]); |
| 4812 } | 4941 } |
| 4813 | 4942 |
| 4814 void test_deadCode_deadBlock_else() { | 4943 void test_deadCode_deadBlock_else() { |
| 4815 Source source = addSource(EngineTestCase.createSource([ | 4944 Source source = addSource(r''' |
| 4816 "const bool DEBUG = true;", | 4945 const bool DEBUG = true; |
| 4817 "f() {", | 4946 f() { |
| 4818 " if(DEBUG) {} else {}", | 4947 if(DEBUG) {} else {} |
| 4819 "}"])); | 4948 }'''); |
| 4820 resolve(source); | 4949 resolve(source); |
| 4821 assertNoErrors(source); | 4950 assertNoErrors(source); |
| 4822 verify([source]); | 4951 verify([source]); |
| 4823 } | 4952 } |
| 4824 | 4953 |
| 4825 void test_deadCode_deadBlock_if_debugConst_prefixedIdentifier() { | 4954 void test_deadCode_deadBlock_if_debugConst_prefixedIdentifier() { |
| 4826 Source source = addSource(EngineTestCase.createSource([ | 4955 Source source = addSource(r''' |
| 4827 "class A {", | 4956 class A { |
| 4828 " static const bool DEBUG = false;", | 4957 static const bool DEBUG = false; |
| 4829 "}", | 4958 } |
| 4830 "f() {", | 4959 f() { |
| 4831 " if(A.DEBUG) {}", | 4960 if(A.DEBUG) {} |
| 4832 "}"])); | 4961 }'''); |
| 4833 resolve(source); | 4962 resolve(source); |
| 4834 assertNoErrors(source); | 4963 assertNoErrors(source); |
| 4835 verify([source]); | 4964 verify([source]); |
| 4836 } | 4965 } |
| 4837 | 4966 |
| 4838 void test_deadCode_deadBlock_if_debugConst_prefixedIdentifier2() { | 4967 void test_deadCode_deadBlock_if_debugConst_prefixedIdentifier2() { |
| 4839 Source source = addSource(EngineTestCase.createSource([ | 4968 Source source = addSource(r''' |
| 4840 "library L;", | 4969 library L; |
| 4841 "import 'lib2.dart';", | 4970 import 'lib2.dart'; |
| 4842 "f() {", | 4971 f() { |
| 4843 " if(A.DEBUG) {}", | 4972 if(A.DEBUG) {} |
| 4844 "}"])); | 4973 }'''); |
| 4845 addNamedSource("/lib2.dart", EngineTestCase.createSource([ | 4974 addNamedSource("/lib2.dart", r''' |
| 4846 "library lib2;", | 4975 library lib2; |
| 4847 "class A {", | 4976 class A { |
| 4848 " static const bool DEBUG = false;", | 4977 static const bool DEBUG = false; |
| 4849 "}"])); | 4978 }'''); |
| 4850 resolve(source); | 4979 resolve(source); |
| 4851 assertNoErrors(source); | 4980 assertNoErrors(source); |
| 4852 verify([source]); | 4981 verify([source]); |
| 4853 } | 4982 } |
| 4854 | 4983 |
| 4855 void test_deadCode_deadBlock_if_debugConst_propertyAccessor() { | 4984 void test_deadCode_deadBlock_if_debugConst_propertyAccessor() { |
| 4856 Source source = addSource(EngineTestCase.createSource([ | 4985 Source source = addSource(r''' |
| 4857 "library L;", | 4986 library L; |
| 4858 "import 'lib2.dart' as LIB;", | 4987 import 'lib2.dart' as LIB; |
| 4859 "f() {", | 4988 f() { |
| 4860 " if(LIB.A.DEBUG) {}", | 4989 if(LIB.A.DEBUG) {} |
| 4861 "}"])); | 4990 }'''); |
| 4862 addNamedSource("/lib2.dart", EngineTestCase.createSource([ | 4991 addNamedSource("/lib2.dart", r''' |
| 4863 "library lib2;", | 4992 library lib2; |
| 4864 "class A {", | 4993 class A { |
| 4865 " static const bool DEBUG = false;", | 4994 static const bool DEBUG = false; |
| 4866 "}"])); | 4995 }'''); |
| 4867 resolve(source); | 4996 resolve(source); |
| 4868 assertNoErrors(source); | 4997 assertNoErrors(source); |
| 4869 verify([source]); | 4998 verify([source]); |
| 4870 } | 4999 } |
| 4871 | 5000 |
| 4872 void test_deadCode_deadBlock_if_debugConst_simpleIdentifier() { | 5001 void test_deadCode_deadBlock_if_debugConst_simpleIdentifier() { |
| 4873 Source source = addSource(EngineTestCase.createSource([ | 5002 Source source = addSource(r''' |
| 4874 "const bool DEBUG = false;", | 5003 const bool DEBUG = false; |
| 4875 "f() {", | 5004 f() { |
| 4876 " if(DEBUG) {}", | 5005 if(DEBUG) {} |
| 4877 "}"])); | 5006 }'''); |
| 4878 resolve(source); | 5007 resolve(source); |
| 4879 assertNoErrors(source); | 5008 assertNoErrors(source); |
| 4880 verify([source]); | 5009 verify([source]); |
| 4881 } | 5010 } |
| 4882 | 5011 |
| 4883 void test_deadCode_deadBlock_while_debugConst() { | 5012 void test_deadCode_deadBlock_while_debugConst() { |
| 4884 Source source = addSource(EngineTestCase.createSource([ | 5013 Source source = addSource(r''' |
| 4885 "const bool DEBUG = false;", | 5014 const bool DEBUG = false; |
| 4886 "f() {", | 5015 f() { |
| 4887 " while(DEBUG) {}", | 5016 while(DEBUG) {} |
| 4888 "}"])); | 5017 }'''); |
| 4889 resolve(source); | 5018 resolve(source); |
| 4890 assertNoErrors(source); | 5019 assertNoErrors(source); |
| 4891 verify([source]); | 5020 verify([source]); |
| 4892 } | 5021 } |
| 4893 | 5022 |
| 4894 void test_deadCode_deadCatch_onCatchSubtype() { | 5023 void test_deadCode_deadCatch_onCatchSubtype() { |
| 4895 Source source = addSource(EngineTestCase.createSource([ | 5024 Source source = addSource(r''' |
| 4896 "class A {}", | 5025 class A {} |
| 4897 "class B extends A {}", | 5026 class B extends A {} |
| 4898 "f() {", | 5027 f() { |
| 4899 " try {} on B catch (e) {} on A catch (e) {} catch (e) {}", | 5028 try {} on B catch (e) {} on A catch (e) {} catch (e) {} |
| 4900 "}"])); | 5029 }'''); |
| 4901 resolve(source); | 5030 resolve(source); |
| 4902 assertNoErrors(source); | 5031 assertNoErrors(source); |
| 4903 verify([source]); | 5032 verify([source]); |
| 4904 } | 5033 } |
| 4905 | 5034 |
| 4906 void test_deadCode_deadOperandLHS_and_debugConst() { | 5035 void test_deadCode_deadOperandLHS_and_debugConst() { |
| 4907 Source source = addSource(EngineTestCase.createSource([ | 5036 Source source = addSource(r''' |
| 4908 "const bool DEBUG = false;", | 5037 const bool DEBUG = false; |
| 4909 "f() {", | 5038 f() { |
| 4910 " bool b = DEBUG && false;", | 5039 bool b = DEBUG && false; |
| 4911 "}"])); | 5040 }'''); |
| 4912 resolve(source); | 5041 resolve(source); |
| 4913 assertNoErrors(source); | 5042 assertNoErrors(source); |
| 4914 verify([source]); | 5043 verify([source]); |
| 4915 } | 5044 } |
| 4916 | 5045 |
| 4917 void test_deadCode_deadOperandLHS_or_debugConst() { | 5046 void test_deadCode_deadOperandLHS_or_debugConst() { |
| 4918 Source source = addSource(EngineTestCase.createSource([ | 5047 Source source = addSource(r''' |
| 4919 "const bool DEBUG = true;", | 5048 const bool DEBUG = true; |
| 4920 "f() {", | 5049 f() { |
| 4921 " bool b = DEBUG || true;", | 5050 bool b = DEBUG || true; |
| 4922 "}"])); | 5051 }'''); |
| 4923 resolve(source); | 5052 resolve(source); |
| 4924 assertNoErrors(source); | 5053 assertNoErrors(source); |
| 4925 verify([source]); | 5054 verify([source]); |
| 4926 } | 5055 } |
| 4927 | 5056 |
| 4928 void test_divisionOptimization() { | 5057 void test_divisionOptimization() { |
| 4929 Source source = addSource(EngineTestCase.createSource(["f(int x, int y) {",
" var v = x / y.toInt();", "}"])); | 5058 Source source = addSource(r''' |
| 5059 f(int x, int y) { |
| 5060 var v = x / y.toInt(); |
| 5061 }'''); |
| 4930 resolve(source); | 5062 resolve(source); |
| 4931 assertNoErrors(source); | 5063 assertNoErrors(source); |
| 4932 verify([source]); | 5064 verify([source]); |
| 4933 } | 5065 } |
| 4934 | 5066 |
| 4935 void test_divisionOptimization_supressIfDivisionNotDefinedInCore() { | 5067 void test_divisionOptimization_supressIfDivisionNotDefinedInCore() { |
| 4936 Source source = addSource(EngineTestCase.createSource(["f(x, y) {", " var v
= (x / y).toInt();", "}"])); | 5068 Source source = addSource(r''' |
| 5069 f(x, y) { |
| 5070 var v = (x / y).toInt(); |
| 5071 }'''); |
| 4937 resolve(source); | 5072 resolve(source); |
| 4938 assertNoErrors(source); | 5073 assertNoErrors(source); |
| 4939 verify([source]); | 5074 verify([source]); |
| 4940 } | 5075 } |
| 4941 | 5076 |
| 4942 void test_divisionOptimization_supressIfDivisionOverridden() { | 5077 void test_divisionOptimization_supressIfDivisionOverridden() { |
| 4943 Source source = addSource(EngineTestCase.createSource([ | 5078 Source source = addSource(r''' |
| 4944 "class A {", | 5079 class A { |
| 4945 " num operator /(x) { return x; }", | 5080 num operator /(x) { return x; } |
| 4946 "}", | 5081 } |
| 4947 "f(A x, A y) {", | 5082 f(A x, A y) { |
| 4948 " var v = (x / y).toInt();", | 5083 var v = (x / y).toInt(); |
| 4949 "}"])); | 5084 }'''); |
| 4950 resolve(source); | 5085 resolve(source); |
| 4951 assertNoErrors(source); | 5086 assertNoErrors(source); |
| 4952 verify([source]); | 5087 verify([source]); |
| 4953 } | 5088 } |
| 4954 | 5089 |
| 4955 void test_duplicateImport_as() { | 5090 void test_duplicateImport_as() { |
| 4956 Source source = addSource(EngineTestCase.createSource([ | 5091 Source source = addSource(r''' |
| 4957 "library L;", | 5092 library L; |
| 4958 "import 'lib1.dart';", | 5093 import 'lib1.dart'; |
| 4959 "import 'lib1.dart' as one;", | 5094 import 'lib1.dart' as one; |
| 4960 "A a;", | 5095 A a; |
| 4961 "one.A a2;"])); | 5096 one.A a2;'''); |
| 4962 addNamedSource("/lib1.dart", EngineTestCase.createSource(["library lib1;", "
class A {}"])); | 5097 addNamedSource("/lib1.dart", r''' |
| 5098 library lib1; |
| 5099 class A {}'''); |
| 4963 resolve(source); | 5100 resolve(source); |
| 4964 assertNoErrors(source); | 5101 assertNoErrors(source); |
| 4965 verify([source]); | 5102 verify([source]); |
| 4966 } | 5103 } |
| 4967 | 5104 |
| 4968 void test_duplicateImport_hide() { | 5105 void test_duplicateImport_hide() { |
| 4969 Source source = addSource(EngineTestCase.createSource([ | 5106 Source source = addSource(r''' |
| 4970 "library L;", | 5107 library L; |
| 4971 "import 'lib1.dart';", | 5108 import 'lib1.dart'; |
| 4972 "import 'lib1.dart' hide A;", | 5109 import 'lib1.dart' hide A; |
| 4973 "A a;", | 5110 A a; |
| 4974 "B b;"])); | 5111 B b;'''); |
| 4975 addNamedSource("/lib1.dart", EngineTestCase.createSource(["library lib1;", "
class A {}", "class B {}"])); | 5112 addNamedSource("/lib1.dart", r''' |
| 5113 library lib1; |
| 5114 class A {} |
| 5115 class B {}'''); |
| 4976 resolve(source); | 5116 resolve(source); |
| 4977 assertNoErrors(source); | 5117 assertNoErrors(source); |
| 4978 verify([source]); | 5118 verify([source]); |
| 4979 } | 5119 } |
| 4980 | 5120 |
| 4981 void test_duplicateImport_show() { | 5121 void test_duplicateImport_show() { |
| 4982 Source source = addSource(EngineTestCase.createSource([ | 5122 Source source = addSource(r''' |
| 4983 "library L;", | 5123 library L; |
| 4984 "import 'lib1.dart';", | 5124 import 'lib1.dart'; |
| 4985 "import 'lib1.dart' show A;", | 5125 import 'lib1.dart' show A; |
| 4986 "A a;", | 5126 A a; |
| 4987 "B b;"])); | 5127 B b;'''); |
| 4988 addNamedSource("/lib1.dart", EngineTestCase.createSource(["library lib1;", "
class A {}", "class B {}"])); | 5128 addNamedSource("/lib1.dart", r''' |
| 4989 resolve(source); | 5129 library lib1; |
| 4990 assertNoErrors(source); | 5130 class A {} |
| 4991 verify([source]); | 5131 class B {}'''); |
| 5132 resolve(source); |
| 5133 assertNoErrors(source); |
| 5134 verify([source]); |
| 4992 } | 5135 } |
| 4993 | 5136 |
| 4994 void test_importDeferredLibraryWithLoadFunction() { | 5137 void test_importDeferredLibraryWithLoadFunction() { |
| 4995 resolveWithAndWithoutExperimental(<String> [ | 5138 resolveWithAndWithoutExperimental(<String> [ |
| 4996 EngineTestCase.createSource(["library lib1;", "f() {}"]), | 5139 r''' |
| 4997 EngineTestCase.createSource([ | 5140 library lib1; |
| 4998 "library root;", | 5141 f() {}''', |
| 4999 "import 'lib1.dart' deferred as lib1;", | 5142 r''' |
| 5000 "main() { lib1.f(); }"])], <ErrorCode> [ParserErrorCode.DEFERRED_IMPORTS
_NOT_SUPPORTED], <ErrorCode> []); | 5143 library root; |
| 5144 import 'lib1.dart' deferred as lib1; |
| 5145 main() { lib1.f(); }'''], <ErrorCode> [ParserErrorCode.DEFERRED_IMPORTS_NOT_SUPP
ORTED], <ErrorCode> []); |
| 5001 } | 5146 } |
| 5002 | 5147 |
| 5003 void test_issue20904BuggyTypePromotionAtIfJoin_1() { | 5148 void test_issue20904BuggyTypePromotionAtIfJoin_1() { |
| 5004 // https://code.google.com/p/dart/issues/detail?id=20904 | 5149 // https://code.google.com/p/dart/issues/detail?id=20904 |
| 5005 Source source = addSource(EngineTestCase.createSource([ | 5150 Source source = addSource(r''' |
| 5006 "f(var message, var dynamic_) {", | 5151 f(var message, var dynamic_) { |
| 5007 " if (message is Function) {", | 5152 if (message is Function) { |
| 5008 " message = dynamic_;", | 5153 message = dynamic_; |
| 5009 " }", | 5154 } |
| 5010 " int s = message;", | 5155 int s = message; |
| 5011 "}"])); | 5156 }'''); |
| 5012 resolve(source); | 5157 resolve(source); |
| 5013 assertNoErrors(source); | 5158 assertNoErrors(source); |
| 5014 verify([source]); | 5159 verify([source]); |
| 5015 } | 5160 } |
| 5016 | 5161 |
| 5017 void test_issue20904BuggyTypePromotionAtIfJoin_2() { | 5162 void test_issue20904BuggyTypePromotionAtIfJoin_2() { |
| 5018 // https://code.google.com/p/dart/issues/detail?id=20904 | 5163 // https://code.google.com/p/dart/issues/detail?id=20904 |
| 5019 enableUnionTypes(false); | 5164 enableUnionTypes(false); |
| 5020 Source source = addSource(EngineTestCase.createSource([ | 5165 Source source = addSource(r''' |
| 5021 "f(var message) {", | 5166 f(var message) { |
| 5022 " if (message is Function) {", | 5167 if (message is Function) { |
| 5023 " message = '';", | 5168 message = ''; |
| 5024 " }", | 5169 } |
| 5025 " int s = message;", | 5170 int s = message; |
| 5026 "}"])); | 5171 }'''); |
| 5027 resolve(source); | 5172 resolve(source); |
| 5028 assertNoErrors(source); | 5173 assertNoErrors(source); |
| 5029 verify([source]); | 5174 verify([source]); |
| 5030 } | 5175 } |
| 5031 | 5176 |
| 5032 void test_issue20904BuggyTypePromotionAtIfJoin_3() { | 5177 void test_issue20904BuggyTypePromotionAtIfJoin_3() { |
| 5033 // https://code.google.com/p/dart/issues/detail?id=20904 | 5178 // https://code.google.com/p/dart/issues/detail?id=20904 |
| 5034 Source source = addSource(EngineTestCase.createSource([ | 5179 Source source = addSource(r''' |
| 5035 "f(var message) {", | 5180 f(var message) { |
| 5036 " var dynamic_;", | 5181 var dynamic_; |
| 5037 " if (message is Function) {", | 5182 if (message is Function) { |
| 5038 " message = dynamic_;", | 5183 message = dynamic_; |
| 5039 " } else {", | 5184 } else { |
| 5040 " return;", | 5185 return; |
| 5041 " }", | 5186 } |
| 5042 " int s = message;", | 5187 int s = message; |
| 5043 "}"])); | 5188 }'''); |
| 5044 resolve(source); | 5189 resolve(source); |
| 5045 assertNoErrors(source); | 5190 assertNoErrors(source); |
| 5046 verify([source]); | 5191 verify([source]); |
| 5047 } | 5192 } |
| 5048 | 5193 |
| 5049 void test_issue20904BuggyTypePromotionAtIfJoin_4() { | 5194 void test_issue20904BuggyTypePromotionAtIfJoin_4() { |
| 5050 // https://code.google.com/p/dart/issues/detail?id=20904 | 5195 // https://code.google.com/p/dart/issues/detail?id=20904 |
| 5051 Source source = addSource(EngineTestCase.createSource([ | 5196 Source source = addSource(r''' |
| 5052 "f(var message) {", | 5197 f(var message) { |
| 5053 " if (message is Function) {", | 5198 if (message is Function) { |
| 5054 " message = '';", | 5199 message = ''; |
| 5055 " } else {", | 5200 } else { |
| 5056 " return;", | 5201 return; |
| 5057 " }", | 5202 } |
| 5058 " String s = message;", | 5203 String s = message; |
| 5059 "}"])); | 5204 }'''); |
| 5060 resolve(source); | 5205 resolve(source); |
| 5061 assertNoErrors(source); | 5206 assertNoErrors(source); |
| 5062 verify([source]); | 5207 verify([source]); |
| 5063 } | 5208 } |
| 5064 | 5209 |
| 5065 void test_missingReturn_emptyFunctionBody() { | 5210 void test_missingReturn_emptyFunctionBody() { |
| 5066 Source source = addSource(EngineTestCase.createSource(["abstract class A {",
" int m();", "}"])); | 5211 Source source = addSource(r''' |
| 5212 abstract class A { |
| 5213 int m(); |
| 5214 }'''); |
| 5067 resolve(source); | 5215 resolve(source); |
| 5068 assertNoErrors(source); | 5216 assertNoErrors(source); |
| 5069 verify([source]); | 5217 verify([source]); |
| 5070 } | 5218 } |
| 5071 | 5219 |
| 5072 void test_missingReturn_expressionFunctionBody() { | 5220 void test_missingReturn_expressionFunctionBody() { |
| 5073 Source source = addSource(EngineTestCase.createSource(["int f() => 0;"])); | 5221 Source source = addSource("int f() => 0;"); |
| 5074 resolve(source); | 5222 resolve(source); |
| 5075 assertNoErrors(source); | 5223 assertNoErrors(source); |
| 5076 verify([source]); | 5224 verify([source]); |
| 5077 } | 5225 } |
| 5078 | 5226 |
| 5079 void test_missingReturn_noReturnType() { | 5227 void test_missingReturn_noReturnType() { |
| 5080 Source source = addSource(EngineTestCase.createSource(["f() {}"])); | 5228 Source source = addSource("f() {}"); |
| 5081 resolve(source); | 5229 resolve(source); |
| 5082 assertNoErrors(source); | 5230 assertNoErrors(source); |
| 5083 verify([source]); | 5231 verify([source]); |
| 5084 } | 5232 } |
| 5085 | 5233 |
| 5086 void test_missingReturn_voidReturnType() { | 5234 void test_missingReturn_voidReturnType() { |
| 5087 Source source = addSource(EngineTestCase.createSource(["void f() {}"])); | 5235 Source source = addSource("void f() {}"); |
| 5088 resolve(source); | 5236 resolve(source); |
| 5089 assertNoErrors(source); | 5237 assertNoErrors(source); |
| 5090 verify([source]); | 5238 verify([source]); |
| 5091 } | 5239 } |
| 5092 | 5240 |
| 5093 void test_overrideEqualsButNotHashCode() { | 5241 void test_overrideEqualsButNotHashCode() { |
| 5094 Source source = addSource(EngineTestCase.createSource([ | 5242 Source source = addSource(r''' |
| 5095 "class A {", | 5243 class A { |
| 5096 " bool operator ==(x) { return x; }", | 5244 bool operator ==(x) { return x; } |
| 5097 " get hashCode => 0;", | 5245 get hashCode => 0; |
| 5098 "}"])); | 5246 }'''); |
| 5099 resolve(source); | 5247 resolve(source); |
| 5100 assertNoErrors(source); | 5248 assertNoErrors(source); |
| 5101 verify([source]); | 5249 verify([source]); |
| 5102 } | 5250 } |
| 5103 | 5251 |
| 5104 void test_overrideOnNonOverridingGetter_inInterface() { | 5252 void test_overrideOnNonOverridingGetter_inInterface() { |
| 5105 Source source = addSource(EngineTestCase.createSource([ | 5253 Source source = addSource(r''' |
| 5106 "library dart.core;", | 5254 library dart.core; |
| 5107 "const override = null;", | 5255 const override = null; |
| 5108 "class A {", | 5256 class A { |
| 5109 " int get m => 0;", | 5257 int get m => 0; |
| 5110 "}", | 5258 } |
| 5111 "class B implements A {", | 5259 class B implements A { |
| 5112 " @override", | 5260 @override |
| 5113 " int get m => 1;", | 5261 int get m => 1; |
| 5114 "}"])); | 5262 }'''); |
| 5115 resolve(source); | 5263 resolve(source); |
| 5116 assertNoErrors(source); | 5264 assertNoErrors(source); |
| 5117 verify([source]); | 5265 verify([source]); |
| 5118 } | 5266 } |
| 5119 | 5267 |
| 5120 void test_overrideOnNonOverridingGetter_inSuperclass() { | 5268 void test_overrideOnNonOverridingGetter_inSuperclass() { |
| 5121 Source source = addSource(EngineTestCase.createSource([ | 5269 Source source = addSource(r''' |
| 5122 "library dart.core;", | 5270 library dart.core; |
| 5123 "const override = null;", | 5271 const override = null; |
| 5124 "class A {", | 5272 class A { |
| 5125 " int get m => 0;", | 5273 int get m => 0; |
| 5126 "}", | 5274 } |
| 5127 "class B extends A {", | 5275 class B extends A { |
| 5128 " @override", | 5276 @override |
| 5129 " int get m => 1;", | 5277 int get m => 1; |
| 5130 "}"])); | 5278 }'''); |
| 5131 resolve(source); | 5279 resolve(source); |
| 5132 assertNoErrors(source); | 5280 assertNoErrors(source); |
| 5133 verify([source]); | 5281 verify([source]); |
| 5134 } | 5282 } |
| 5135 | 5283 |
| 5136 void test_overrideOnNonOverridingMethod_inInterface() { | 5284 void test_overrideOnNonOverridingMethod_inInterface() { |
| 5137 Source source = addSource(EngineTestCase.createSource([ | 5285 Source source = addSource(r''' |
| 5138 "library dart.core;", | 5286 library dart.core; |
| 5139 "const override = null;", | 5287 const override = null; |
| 5140 "class A {", | 5288 class A { |
| 5141 " int m() => 0;", | 5289 int m() => 0; |
| 5142 "}", | 5290 } |
| 5143 "class B implements A {", | 5291 class B implements A { |
| 5144 " @override", | 5292 @override |
| 5145 " int m() => 1;", | 5293 int m() => 1; |
| 5146 "}"])); | 5294 }'''); |
| 5147 resolve(source); | 5295 resolve(source); |
| 5148 assertNoErrors(source); | 5296 assertNoErrors(source); |
| 5149 verify([source]); | 5297 verify([source]); |
| 5150 } | 5298 } |
| 5151 | 5299 |
| 5152 void test_overrideOnNonOverridingMethod_inSuperclass() { | 5300 void test_overrideOnNonOverridingMethod_inSuperclass() { |
| 5153 Source source = addSource(EngineTestCase.createSource([ | 5301 Source source = addSource(r''' |
| 5154 "library dart.core;", | 5302 library dart.core; |
| 5155 "const override = null;", | 5303 const override = null; |
| 5156 "class A {", | 5304 class A { |
| 5157 " int m() => 0;", | 5305 int m() => 0; |
| 5158 "}", | 5306 } |
| 5159 "class B extends A {", | 5307 class B extends A { |
| 5160 " @override", | 5308 @override |
| 5161 " int m() => 1;", | 5309 int m() => 1; |
| 5162 "}"])); | 5310 }'''); |
| 5163 resolve(source); | 5311 resolve(source); |
| 5164 assertNoErrors(source); | 5312 assertNoErrors(source); |
| 5165 verify([source]); | 5313 verify([source]); |
| 5166 } | 5314 } |
| 5167 | 5315 |
| 5168 void test_overrideOnNonOverridingSetter_inInterface() { | 5316 void test_overrideOnNonOverridingSetter_inInterface() { |
| 5169 Source source = addSource(EngineTestCase.createSource([ | 5317 Source source = addSource(r''' |
| 5170 "library dart.core;", | 5318 library dart.core; |
| 5171 "const override = null;", | 5319 const override = null; |
| 5172 "class A {", | 5320 class A { |
| 5173 " set m(int x) {}", | 5321 set m(int x) {} |
| 5174 "}", | 5322 } |
| 5175 "class B implements A {", | 5323 class B implements A { |
| 5176 " @override", | 5324 @override |
| 5177 " set m(int x) {}", | 5325 set m(int x) {} |
| 5178 "}"])); | 5326 }'''); |
| 5179 resolve(source); | 5327 resolve(source); |
| 5180 assertNoErrors(source); | 5328 assertNoErrors(source); |
| 5181 verify([source]); | 5329 verify([source]); |
| 5182 } | 5330 } |
| 5183 | 5331 |
| 5184 void test_overrideOnNonOverridingSetter_inSuperclass() { | 5332 void test_overrideOnNonOverridingSetter_inSuperclass() { |
| 5185 Source source = addSource(EngineTestCase.createSource([ | 5333 Source source = addSource(r''' |
| 5186 "library dart.core;", | 5334 library dart.core; |
| 5187 "const override = null;", | 5335 const override = null; |
| 5188 "class A {", | 5336 class A { |
| 5189 " set m(int x) {}", | 5337 set m(int x) {} |
| 5190 "}", | 5338 } |
| 5191 "class B extends A {", | 5339 class B extends A { |
| 5192 " @override", | 5340 @override |
| 5193 " set m(int x) {}", | 5341 set m(int x) {} |
| 5194 "}"])); | 5342 }'''); |
| 5195 resolve(source); | 5343 resolve(source); |
| 5196 assertNoErrors(source); | 5344 assertNoErrors(source); |
| 5197 verify([source]); | 5345 verify([source]); |
| 5198 } | 5346 } |
| 5199 | 5347 |
| 5200 void test_propagatedFieldType() { | 5348 void test_propagatedFieldType() { |
| 5201 // From dartbug.com/20019 | 5349 // From dartbug.com/20019 |
| 5202 Source source = addSource(EngineTestCase.createSource([ | 5350 Source source = addSource(r''' |
| 5203 "class A { }", | 5351 class A { } |
| 5204 "class X<T> {", | 5352 class X<T> { |
| 5205 " final x = new List<T>();", | 5353 final x = new List<T>(); |
| 5206 "}", | 5354 } |
| 5207 "class Z {", | 5355 class Z { |
| 5208 " final X<A> y = new X<A>();", | 5356 final X<A> y = new X<A>(); |
| 5209 " foo() {", | 5357 foo() { |
| 5210 " y.x.add(new A());", | 5358 y.x.add(new A()); |
| 5211 " }", | 5359 } |
| 5212 "}"])); | 5360 }'''); |
| 5213 resolve(source); | 5361 resolve(source); |
| 5214 assertNoErrors(source); | 5362 assertNoErrors(source); |
| 5215 verify([source]); | 5363 verify([source]); |
| 5216 } | 5364 } |
| 5217 | 5365 |
| 5218 void test_proxy_annotation_prefixed() { | 5366 void test_proxy_annotation_prefixed() { |
| 5219 Source source = addSource(EngineTestCase.createSource([ | 5367 Source source = addSource(r''' |
| 5220 "library L;", | 5368 library L; |
| 5221 "@proxy", | 5369 @proxy |
| 5222 "class A {}", | 5370 class A {} |
| 5223 "f(var a) {", | 5371 f(var a) { |
| 5224 " a = new A();", | 5372 a = new A(); |
| 5225 " a.m();", | 5373 a.m(); |
| 5226 " var x = a.g;", | 5374 var x = a.g; |
| 5227 " a.s = 1;", | 5375 a.s = 1; |
| 5228 " var y = a + a;", | 5376 var y = a + a; |
| 5229 " a++;", | 5377 a++; |
| 5230 " ++a;", | 5378 ++a; |
| 5231 "}"])); | 5379 }'''); |
| 5232 resolve(source); | 5380 resolve(source); |
| 5233 assertNoErrors(source); | 5381 assertNoErrors(source); |
| 5234 } | 5382 } |
| 5235 | 5383 |
| 5236 void test_proxy_annotation_prefixed2() { | 5384 void test_proxy_annotation_prefixed2() { |
| 5237 Source source = addSource(EngineTestCase.createSource([ | 5385 Source source = addSource(r''' |
| 5238 "library L;", | 5386 library L; |
| 5239 "@proxy", | 5387 @proxy |
| 5240 "class A {}", | 5388 class A {} |
| 5241 "class B {", | 5389 class B { |
| 5242 " f(var a) {", | 5390 f(var a) { |
| 5243 " a = new A();", | 5391 a = new A(); |
| 5244 " a.m();", | 5392 a.m(); |
| 5245 " var x = a.g;", | 5393 var x = a.g; |
| 5246 " a.s = 1;", | 5394 a.s = 1; |
| 5247 " var y = a + a;", | 5395 var y = a + a; |
| 5248 " a++;", | 5396 a++; |
| 5249 " ++a;", | 5397 ++a; |
| 5250 " }", | 5398 } |
| 5251 "}"])); | 5399 }'''); |
| 5252 resolve(source); | 5400 resolve(source); |
| 5253 assertNoErrors(source); | 5401 assertNoErrors(source); |
| 5254 } | 5402 } |
| 5255 | 5403 |
| 5256 void test_proxy_annotation_prefixed3() { | 5404 void test_proxy_annotation_prefixed3() { |
| 5257 Source source = addSource(EngineTestCase.createSource([ | 5405 Source source = addSource(r''' |
| 5258 "library L;", | 5406 library L; |
| 5259 "class B {", | 5407 class B { |
| 5260 " f(var a) {", | 5408 f(var a) { |
| 5261 " a = new A();", | 5409 a = new A(); |
| 5262 " a.m();", | 5410 a.m(); |
| 5263 " var x = a.g;", | 5411 var x = a.g; |
| 5264 " a.s = 1;", | 5412 a.s = 1; |
| 5265 " var y = a + a;", | 5413 var y = a + a; |
| 5266 " a++;", | 5414 a++; |
| 5267 " ++a;", | 5415 ++a; |
| 5268 " }", | 5416 } |
| 5269 "}", | 5417 } |
| 5270 "@proxy", | 5418 @proxy |
| 5271 "class A {}"])); | 5419 class A {}'''); |
| 5272 resolve(source); | 5420 resolve(source); |
| 5273 assertNoErrors(source); | 5421 assertNoErrors(source); |
| 5274 } | 5422 } |
| 5275 | 5423 |
| 5276 void test_undefinedGetter_inSubtype() { | 5424 void test_undefinedGetter_inSubtype() { |
| 5277 Source source = addSource(EngineTestCase.createSource([ | 5425 Source source = addSource(r''' |
| 5278 "class A {}", | 5426 class A {} |
| 5279 "class B extends A {", | 5427 class B extends A { |
| 5280 " get b => 0;", | 5428 get b => 0; |
| 5281 "}", | 5429 } |
| 5282 "f(var a) {", | 5430 f(var a) { |
| 5283 " if(a is A) {", | 5431 if(a is A) { |
| 5284 " return a.b;", | 5432 return a.b; |
| 5285 " }", | 5433 } |
| 5286 "}"])); | 5434 }'''); |
| 5287 resolve(source); | 5435 resolve(source); |
| 5288 assertNoErrors(source); | 5436 assertNoErrors(source); |
| 5289 } | 5437 } |
| 5290 | 5438 |
| 5291 void test_undefinedMethod_assignmentExpression_inSubtype() { | 5439 void test_undefinedMethod_assignmentExpression_inSubtype() { |
| 5292 Source source = addSource(EngineTestCase.createSource([ | 5440 Source source = addSource(r''' |
| 5293 "class A {}", | 5441 class A {} |
| 5294 "class B extends A {", | 5442 class B extends A { |
| 5295 " operator +(B b) {return new B();}", | 5443 operator +(B b) {return new B();} |
| 5296 "}", | 5444 } |
| 5297 "f(var a, var a2) {", | 5445 f(var a, var a2) { |
| 5298 " a = new A();", | 5446 a = new A(); |
| 5299 " a2 = new A();", | 5447 a2 = new A(); |
| 5300 " a += a2;", | 5448 a += a2; |
| 5301 "}"])); | 5449 }'''); |
| 5302 resolve(source); | 5450 resolve(source); |
| 5303 assertNoErrors(source); | 5451 assertNoErrors(source); |
| 5304 } | 5452 } |
| 5305 | 5453 |
| 5306 void test_undefinedMethod_inSubtype() { | 5454 void test_undefinedMethod_inSubtype() { |
| 5307 Source source = addSource(EngineTestCase.createSource([ | 5455 Source source = addSource(r''' |
| 5308 "class A {}", | 5456 class A {} |
| 5309 "class B extends A {", | 5457 class B extends A { |
| 5310 " b() {}", | 5458 b() {} |
| 5311 "}", | 5459 } |
| 5312 "f() {", | 5460 f() { |
| 5313 " var a = new A();", | 5461 var a = new A(); |
| 5314 " a.b();", | 5462 a.b(); |
| 5315 "}"])); | 5463 }'''); |
| 5316 resolve(source); | 5464 resolve(source); |
| 5317 assertNoErrors(source); | 5465 assertNoErrors(source); |
| 5318 } | 5466 } |
| 5319 | 5467 |
| 5320 void test_undefinedMethod_unionType_all() { | 5468 void test_undefinedMethod_unionType_all() { |
| 5321 Source source = addSource(EngineTestCase.createSource([ | 5469 Source source = addSource(r''' |
| 5322 "class A {", | 5470 class A { |
| 5323 " int m(int x) => 0;", | 5471 int m(int x) => 0; |
| 5324 "}", | 5472 } |
| 5325 "class B {", | 5473 class B { |
| 5326 " String m() => '0';", | 5474 String m() => '0'; |
| 5327 "}", | 5475 } |
| 5328 "f(A a, B b) {", | 5476 f(A a, B b) { |
| 5329 " var ab;", | 5477 var ab; |
| 5330 " if (0 < 1) {", | 5478 if (0 < 1) { |
| 5331 " ab = a;", | 5479 ab = a; |
| 5332 " } else {", | 5480 } else { |
| 5333 " ab = b;", | 5481 ab = b; |
| 5334 " }", | 5482 } |
| 5335 " ab.m();", | 5483 ab.m(); |
| 5336 "}"])); | 5484 }'''); |
| 5337 resolve(source); | 5485 resolve(source); |
| 5338 assertNoErrors(source); | 5486 assertNoErrors(source); |
| 5339 } | 5487 } |
| 5340 | 5488 |
| 5341 void test_undefinedMethod_unionType_some() { | 5489 void test_undefinedMethod_unionType_some() { |
| 5342 Source source = addSource(EngineTestCase.createSource([ | 5490 Source source = addSource(r''' |
| 5343 "class A {", | 5491 class A { |
| 5344 " int m(int x) => 0;", | 5492 int m(int x) => 0; |
| 5345 "}", | 5493 } |
| 5346 "class B {}", | 5494 class B {} |
| 5347 "f(A a, B b) {", | 5495 f(A a, B b) { |
| 5348 " var ab;", | 5496 var ab; |
| 5349 " if (0 < 1) {", | 5497 if (0 < 1) { |
| 5350 " ab = a;", | 5498 ab = a; |
| 5351 " } else {", | 5499 } else { |
| 5352 " ab = b;", | 5500 ab = b; |
| 5353 " }", | 5501 } |
| 5354 " ab.m(0);", | 5502 ab.m(0); |
| 5355 "}"])); | 5503 }'''); |
| 5356 resolve(source); | 5504 resolve(source); |
| 5357 assertNoErrors(source); | 5505 assertNoErrors(source); |
| 5358 } | 5506 } |
| 5359 | 5507 |
| 5360 void test_undefinedOperator_binaryExpression_inSubtype() { | 5508 void test_undefinedOperator_binaryExpression_inSubtype() { |
| 5361 Source source = addSource(EngineTestCase.createSource([ | 5509 Source source = addSource(r''' |
| 5362 "class A {}", | 5510 class A {} |
| 5363 "class B extends A {", | 5511 class B extends A { |
| 5364 " operator +(B b) {}", | 5512 operator +(B b) {} |
| 5365 "}", | 5513 } |
| 5366 "f(var a) {", | 5514 f(var a) { |
| 5367 " if(a is A) {", | 5515 if(a is A) { |
| 5368 " a + 1;", | 5516 a + 1; |
| 5369 " }", | 5517 } |
| 5370 "}"])); | 5518 }'''); |
| 5371 resolve(source); | 5519 resolve(source); |
| 5372 assertNoErrors(source); | 5520 assertNoErrors(source); |
| 5373 } | 5521 } |
| 5374 | 5522 |
| 5375 void test_undefinedOperator_indexBoth_inSubtype() { | 5523 void test_undefinedOperator_indexBoth_inSubtype() { |
| 5376 Source source = addSource(EngineTestCase.createSource([ | 5524 Source source = addSource(r''' |
| 5377 "class A {}", | 5525 class A {} |
| 5378 "class B extends A {", | 5526 class B extends A { |
| 5379 " operator [](int index) {}", | 5527 operator [](int index) {} |
| 5380 "}", | 5528 } |
| 5381 "f(var a) {", | 5529 f(var a) { |
| 5382 " if(a is A) {", | 5530 if(a is A) { |
| 5383 " a[0]++;", | 5531 a[0]++; |
| 5384 " }", | 5532 } |
| 5385 "}"])); | 5533 }'''); |
| 5386 resolve(source); | 5534 resolve(source); |
| 5387 assertNoErrors(source); | 5535 assertNoErrors(source); |
| 5388 } | 5536 } |
| 5389 | 5537 |
| 5390 void test_undefinedOperator_indexGetter_inSubtype() { | 5538 void test_undefinedOperator_indexGetter_inSubtype() { |
| 5391 Source source = addSource(EngineTestCase.createSource([ | 5539 Source source = addSource(r''' |
| 5392 "class A {}", | 5540 class A {} |
| 5393 "class B extends A {", | 5541 class B extends A { |
| 5394 " operator [](int index) {}", | 5542 operator [](int index) {} |
| 5395 "}", | 5543 } |
| 5396 "f(var a) {", | 5544 f(var a) { |
| 5397 " if(a is A) {", | 5545 if(a is A) { |
| 5398 " a[0];", | 5546 a[0]; |
| 5399 " }", | 5547 } |
| 5400 "}"])); | 5548 }'''); |
| 5401 resolve(source); | 5549 resolve(source); |
| 5402 assertNoErrors(source); | 5550 assertNoErrors(source); |
| 5403 } | 5551 } |
| 5404 | 5552 |
| 5405 void test_undefinedOperator_indexSetter_inSubtype() { | 5553 void test_undefinedOperator_indexSetter_inSubtype() { |
| 5406 Source source = addSource(EngineTestCase.createSource([ | 5554 Source source = addSource(r''' |
| 5407 "class A {}", | 5555 class A {} |
| 5408 "class B extends A {", | 5556 class B extends A { |
| 5409 " operator []=(i, v) {}", | 5557 operator []=(i, v) {} |
| 5410 "}", | 5558 } |
| 5411 "f(var a) {", | 5559 f(var a) { |
| 5412 " if(a is A) {", | 5560 if(a is A) { |
| 5413 " a[0] = 1;", | 5561 a[0] = 1; |
| 5414 " }", | 5562 } |
| 5415 "}"])); | 5563 }'''); |
| 5416 resolve(source); | 5564 resolve(source); |
| 5417 assertNoErrors(source); | 5565 assertNoErrors(source); |
| 5418 } | 5566 } |
| 5419 | 5567 |
| 5420 void test_undefinedOperator_postfixExpression() { | 5568 void test_undefinedOperator_postfixExpression() { |
| 5421 Source source = addSource(EngineTestCase.createSource([ | 5569 Source source = addSource(r''' |
| 5422 "class A {}", | 5570 class A {} |
| 5423 "class B extends A {", | 5571 class B extends A { |
| 5424 " operator +(B b) {return new B();}", | 5572 operator +(B b) {return new B();} |
| 5425 "}", | 5573 } |
| 5426 "f(var a) {", | 5574 f(var a) { |
| 5427 " if(a is A) {", | 5575 if(a is A) { |
| 5428 " a++;", | 5576 a++; |
| 5429 " }", | 5577 } |
| 5430 "}"])); | 5578 }'''); |
| 5431 resolve(source); | 5579 resolve(source); |
| 5432 assertNoErrors(source); | 5580 assertNoErrors(source); |
| 5433 } | 5581 } |
| 5434 | 5582 |
| 5435 void test_undefinedOperator_prefixExpression() { | 5583 void test_undefinedOperator_prefixExpression() { |
| 5436 Source source = addSource(EngineTestCase.createSource([ | 5584 Source source = addSource(r''' |
| 5437 "class A {}", | 5585 class A {} |
| 5438 "class B extends A {", | 5586 class B extends A { |
| 5439 " operator +(B b) {return new B();}", | 5587 operator +(B b) {return new B();} |
| 5440 "}", | 5588 } |
| 5441 "f(var a) {", | 5589 f(var a) { |
| 5442 " if(a is A) {", | 5590 if(a is A) { |
| 5443 " ++a;", | 5591 ++a; |
| 5444 " }", | 5592 } |
| 5445 "}"])); | 5593 }'''); |
| 5446 resolve(source); | 5594 resolve(source); |
| 5447 assertNoErrors(source); | 5595 assertNoErrors(source); |
| 5448 } | 5596 } |
| 5449 | 5597 |
| 5450 void test_undefinedSetter_inSubtype() { | 5598 void test_undefinedSetter_inSubtype() { |
| 5451 Source source = addSource(EngineTestCase.createSource([ | 5599 Source source = addSource(r''' |
| 5452 "class A {}", | 5600 class A {} |
| 5453 "class B extends A {", | 5601 class B extends A { |
| 5454 " set b(x) {}", | 5602 set b(x) {} |
| 5455 "}", | 5603 } |
| 5456 "f(var a) {", | 5604 f(var a) { |
| 5457 " if(a is A) {", | 5605 if(a is A) { |
| 5458 " a.b = 0;", | 5606 a.b = 0; |
| 5459 " }", | 5607 } |
| 5460 "}"])); | 5608 }'''); |
| 5461 resolve(source); | 5609 resolve(source); |
| 5462 assertNoErrors(source); | 5610 assertNoErrors(source); |
| 5463 } | 5611 } |
| 5464 | 5612 |
| 5465 void test_unnecessaryCast_13855_parameter_A() { | 5613 void test_unnecessaryCast_13855_parameter_A() { |
| 5466 // dartbug.com/13855, dartbug.com/13732 | 5614 // dartbug.com/13855, dartbug.com/13732 |
| 5467 Source source = addSource(EngineTestCase.createSource([ | 5615 Source source = addSource(r''' |
| 5468 "class A{", | 5616 class A{ |
| 5469 " a() {}", | 5617 a() {} |
| 5470 "}", | 5618 } |
| 5471 "class B<E> {", | 5619 class B<E> { |
| 5472 " E e;", | 5620 E e; |
| 5473 " m() {", | 5621 m() { |
| 5474 " (e as A).a();", | 5622 (e as A).a(); |
| 5475 " }", | 5623 } |
| 5476 "}"])); | 5624 }'''); |
| 5477 resolve(source); | 5625 resolve(source); |
| 5478 assertNoErrors(source); | 5626 assertNoErrors(source); |
| 5479 verify([source]); | 5627 verify([source]); |
| 5480 } | 5628 } |
| 5481 | 5629 |
| 5482 void test_unnecessaryCast_dynamic_type() { | 5630 void test_unnecessaryCast_dynamic_type() { |
| 5483 Source source = addSource(EngineTestCase.createSource(["m(v) {", " var b =
v as Object;", "}"])); | 5631 Source source = addSource(r''' |
| 5632 m(v) { |
| 5633 var b = v as Object; |
| 5634 }'''); |
| 5484 resolve(source); | 5635 resolve(source); |
| 5485 assertNoErrors(source); | 5636 assertNoErrors(source); |
| 5486 verify([source]); | 5637 verify([source]); |
| 5487 } | 5638 } |
| 5488 | 5639 |
| 5489 void test_unnecessaryCast_generics() { | 5640 void test_unnecessaryCast_generics() { |
| 5490 // dartbug.com/18953 | 5641 // dartbug.com/18953 |
| 5491 Source source = addSource(EngineTestCase.createSource([ | 5642 Source source = addSource(r''' |
| 5492 "import 'dart:async';", | 5643 import 'dart:async'; |
| 5493 "Future<int> f() => new Future.value(0);", | 5644 Future<int> f() => new Future.value(0); |
| 5494 "void g(bool c) {", | 5645 void g(bool c) { |
| 5495 " (c ? f(): new Future.value(0) as Future<int>).then((int value) {});", | 5646 (c ? f(): new Future.value(0) as Future<int>).then((int value) {}); |
| 5496 "}"])); | 5647 }'''); |
| 5497 resolve(source); | 5648 resolve(source); |
| 5498 assertNoErrors(source); | 5649 assertNoErrors(source); |
| 5499 verify([source]); | 5650 verify([source]); |
| 5500 } | 5651 } |
| 5501 | 5652 |
| 5502 void test_unnecessaryCast_type_dynamic() { | 5653 void test_unnecessaryCast_type_dynamic() { |
| 5503 Source source = addSource(EngineTestCase.createSource(["m(v) {", " var b =
Object as dynamic;", "}"])); | 5654 Source source = addSource(r''' |
| 5655 m(v) { |
| 5656 var b = Object as dynamic; |
| 5657 }'''); |
| 5504 resolve(source); | 5658 resolve(source); |
| 5505 assertNoErrors(source); | 5659 assertNoErrors(source); |
| 5506 verify([source]); | 5660 verify([source]); |
| 5507 } | 5661 } |
| 5508 | 5662 |
| 5509 void test_unusedImport_annotationOnDirective() { | 5663 void test_unusedImport_annotationOnDirective() { |
| 5510 Source source = addSource(EngineTestCase.createSource(["library L;", "@A()",
"import 'lib1.dart';"])); | 5664 Source source = addSource(r''' |
| 5511 Source source2 = addNamedSource("/lib1.dart", EngineTestCase.createSource(["
library lib1;", "class A {", " const A() {}", "}"])); | 5665 library L; |
| 5666 @A() |
| 5667 import 'lib1.dart';'''); |
| 5668 Source source2 = addNamedSource("/lib1.dart", r''' |
| 5669 library lib1; |
| 5670 class A { |
| 5671 const A() {} |
| 5672 }'''); |
| 5512 resolve(source); | 5673 resolve(source); |
| 5513 assertErrors(source, []); | 5674 assertErrors(source, []); |
| 5514 verify([source, source2]); | 5675 verify([source, source2]); |
| 5515 } | 5676 } |
| 5516 | 5677 |
| 5517 void test_unusedImport_as_equalPrefixes() { | 5678 void test_unusedImport_as_equalPrefixes() { |
| 5518 // 18818 | 5679 // 18818 |
| 5519 Source source = addSource(EngineTestCase.createSource([ | 5680 Source source = addSource(r''' |
| 5520 "library L;", | 5681 library L; |
| 5521 "import 'lib1.dart' as one;", | 5682 import 'lib1.dart' as one; |
| 5522 "import 'lib2.dart' as one;", | 5683 import 'lib2.dart' as one; |
| 5523 "one.A a;", | 5684 one.A a; |
| 5524 "one.B b;"])); | 5685 one.B b;'''); |
| 5525 Source source2 = addNamedSource("/lib1.dart", EngineTestCase.createSource(["
library lib1;", "class A {}"])); | 5686 Source source2 = addNamedSource("/lib1.dart", r''' |
| 5526 Source source3 = addNamedSource("/lib2.dart", EngineTestCase.createSource(["
library lib2;", "class B {}"])); | 5687 library lib1; |
| 5688 class A {}'''); |
| 5689 Source source3 = addNamedSource("/lib2.dart", r''' |
| 5690 library lib2; |
| 5691 class B {}'''); |
| 5527 resolve(source); | 5692 resolve(source); |
| 5528 assertErrors(source, []); | 5693 assertErrors(source, []); |
| 5529 assertNoErrors(source2); | 5694 assertNoErrors(source2); |
| 5530 assertNoErrors(source3); | 5695 assertNoErrors(source3); |
| 5531 verify([source, source2, source3]); | 5696 verify([source, source2, source3]); |
| 5532 } | 5697 } |
| 5533 | 5698 |
| 5534 void test_unusedImport_core_library() { | 5699 void test_unusedImport_core_library() { |
| 5535 Source source = addSource(EngineTestCase.createSource(["library L;", "import
'dart:core';"])); | 5700 Source source = addSource(r''' |
| 5701 library L; |
| 5702 import 'dart:core';'''); |
| 5536 resolve(source); | 5703 resolve(source); |
| 5537 assertNoErrors(source); | 5704 assertNoErrors(source); |
| 5538 verify([source]); | 5705 verify([source]); |
| 5539 } | 5706 } |
| 5540 | 5707 |
| 5541 void test_unusedImport_export() { | 5708 void test_unusedImport_export() { |
| 5542 Source source = addSource(EngineTestCase.createSource(["library L;", "import
'lib1.dart';", "Two two;"])); | 5709 Source source = addSource(r''' |
| 5543 addNamedSource("/lib1.dart", EngineTestCase.createSource(["library lib1;", "
export 'lib2.dart';", "class One {}"])); | 5710 library L; |
| 5544 addNamedSource("/lib2.dart", EngineTestCase.createSource(["library lib2;", "
class Two {}"])); | 5711 import 'lib1.dart'; |
| 5712 Two two;'''); |
| 5713 addNamedSource("/lib1.dart", r''' |
| 5714 library lib1; |
| 5715 export 'lib2.dart'; |
| 5716 class One {}'''); |
| 5717 addNamedSource("/lib2.dart", r''' |
| 5718 library lib2; |
| 5719 class Two {}'''); |
| 5545 resolve(source); | 5720 resolve(source); |
| 5546 assertNoErrors(source); | 5721 assertNoErrors(source); |
| 5547 verify([source]); | 5722 verify([source]); |
| 5548 } | 5723 } |
| 5549 | 5724 |
| 5550 void test_unusedImport_export_infiniteLoop() { | 5725 void test_unusedImport_export_infiniteLoop() { |
| 5551 Source source = addSource(EngineTestCase.createSource(["library L;", "import
'lib1.dart';", "Two two;"])); | 5726 Source source = addSource(r''' |
| 5552 addNamedSource("/lib1.dart", EngineTestCase.createSource(["library lib1;", "
export 'lib2.dart';", "class One {}"])); | 5727 library L; |
| 5553 addNamedSource("/lib2.dart", EngineTestCase.createSource(["library lib2;", "
export 'lib3.dart';", "class Two {}"])); | 5728 import 'lib1.dart'; |
| 5554 addNamedSource("/lib3.dart", EngineTestCase.createSource(["library lib3;", "
export 'lib2.dart';", "class Three {}"])); | 5729 Two two;'''); |
| 5730 addNamedSource("/lib1.dart", r''' |
| 5731 library lib1; |
| 5732 export 'lib2.dart'; |
| 5733 class One {}'''); |
| 5734 addNamedSource("/lib2.dart", r''' |
| 5735 library lib2; |
| 5736 export 'lib3.dart'; |
| 5737 class Two {}'''); |
| 5738 addNamedSource("/lib3.dart", r''' |
| 5739 library lib3; |
| 5740 export 'lib2.dart'; |
| 5741 class Three {}'''); |
| 5555 resolve(source); | 5742 resolve(source); |
| 5556 assertNoErrors(source); | 5743 assertNoErrors(source); |
| 5557 verify([source]); | 5744 verify([source]); |
| 5558 } | 5745 } |
| 5559 | 5746 |
| 5560 void test_unusedImport_export2() { | 5747 void test_unusedImport_export2() { |
| 5561 Source source = addSource(EngineTestCase.createSource(["library L;", "import
'lib1.dart';", "Three three;"])); | 5748 Source source = addSource(r''' |
| 5562 addNamedSource("/lib1.dart", EngineTestCase.createSource(["library lib1;", "
export 'lib2.dart';", "class One {}"])); | 5749 library L; |
| 5563 addNamedSource("/lib2.dart", EngineTestCase.createSource(["library lib2;", "
export 'lib3.dart';", "class Two {}"])); | 5750 import 'lib1.dart'; |
| 5564 addNamedSource("/lib3.dart", EngineTestCase.createSource(["library lib3;", "
class Three {}"])); | 5751 Three three;'''); |
| 5752 addNamedSource("/lib1.dart", r''' |
| 5753 library lib1; |
| 5754 export 'lib2.dart'; |
| 5755 class One {}'''); |
| 5756 addNamedSource("/lib2.dart", r''' |
| 5757 library lib2; |
| 5758 export 'lib3.dart'; |
| 5759 class Two {}'''); |
| 5760 addNamedSource("/lib3.dart", r''' |
| 5761 library lib3; |
| 5762 class Three {}'''); |
| 5565 resolve(source); | 5763 resolve(source); |
| 5566 assertNoErrors(source); | 5764 assertNoErrors(source); |
| 5567 verify([source]); | 5765 verify([source]); |
| 5568 } | 5766 } |
| 5569 | 5767 |
| 5570 void test_unusedImport_metadata() { | 5768 void test_unusedImport_metadata() { |
| 5571 Source source = addSource(EngineTestCase.createSource([ | 5769 Source source = addSource(r''' |
| 5572 "library L;", | 5770 library L; |
| 5573 "@A(x)", | 5771 @A(x) |
| 5574 "import 'lib1.dart';", | 5772 import 'lib1.dart'; |
| 5575 "class A {", | 5773 class A { |
| 5576 " final int value;", | 5774 final int value; |
| 5577 " const A(this.value);", | 5775 const A(this.value); |
| 5578 "}"])); | 5776 }'''); |
| 5579 addNamedSource("/lib1.dart", EngineTestCase.createSource(["library lib1;", "
const x = 0;"])); | 5777 addNamedSource("/lib1.dart", r''' |
| 5778 library lib1; |
| 5779 const x = 0;'''); |
| 5580 resolve(source); | 5780 resolve(source); |
| 5581 assertNoErrors(source); | 5781 assertNoErrors(source); |
| 5582 verify([source]); | 5782 verify([source]); |
| 5583 } | 5783 } |
| 5584 | 5784 |
| 5585 void test_unusedImport_prefix_topLevelFunction() { | 5785 void test_unusedImport_prefix_topLevelFunction() { |
| 5586 Source source = addSource(EngineTestCase.createSource([ | 5786 Source source = addSource(r''' |
| 5587 "library L;", | 5787 library L; |
| 5588 "import 'lib1.dart' hide topLevelFunction;", | 5788 import 'lib1.dart' hide topLevelFunction; |
| 5589 "import 'lib1.dart' as one show topLevelFunction;", | 5789 import 'lib1.dart' as one show topLevelFunction; |
| 5590 "class A {", | 5790 class A { |
| 5591 " static void x() {", | 5791 static void x() { |
| 5592 " One o;", | 5792 One o; |
| 5593 " one.topLevelFunction();", | 5793 one.topLevelFunction(); |
| 5594 " }", | 5794 } |
| 5595 "}"])); | 5795 }'''); |
| 5596 addNamedSource("/lib1.dart", EngineTestCase.createSource(["library lib1;", "
class One {}", "topLevelFunction() {}"])); | 5796 addNamedSource("/lib1.dart", r''' |
| 5797 library lib1; |
| 5798 class One {} |
| 5799 topLevelFunction() {}'''); |
| 5597 resolve(source); | 5800 resolve(source); |
| 5598 assertNoErrors(source); | 5801 assertNoErrors(source); |
| 5599 verify([source]); | 5802 verify([source]); |
| 5600 } | 5803 } |
| 5601 | 5804 |
| 5602 void test_useOfVoidResult_implicitReturnValue() { | 5805 void test_useOfVoidResult_implicitReturnValue() { |
| 5603 Source source = addSource(EngineTestCase.createSource([ | 5806 Source source = addSource(r''' |
| 5604 "f() {}", | 5807 f() {} |
| 5605 "class A {", | 5808 class A { |
| 5606 " n() {", | 5809 n() { |
| 5607 " var a = f();", | 5810 var a = f(); |
| 5608 " }", | 5811 } |
| 5609 "}"])); | 5812 }'''); |
| 5610 resolve(source); | 5813 resolve(source); |
| 5611 assertNoErrors(source); | 5814 assertNoErrors(source); |
| 5612 verify([source]); | 5815 verify([source]); |
| 5613 } | 5816 } |
| 5614 | 5817 |
| 5615 void test_useOfVoidResult_nonVoidReturnValue() { | 5818 void test_useOfVoidResult_nonVoidReturnValue() { |
| 5616 Source source = addSource(EngineTestCase.createSource(["int f() => 1;", "g()
{", " var a = f();", "}"])); | 5819 Source source = addSource(r''' |
| 5820 int f() => 1; |
| 5821 g() { |
| 5822 var a = f(); |
| 5823 }'''); |
| 5617 resolve(source); | 5824 resolve(source); |
| 5618 assertNoErrors(source); | 5825 assertNoErrors(source); |
| 5619 verify([source]); | 5826 verify([source]); |
| 5620 } | 5827 } |
| 5621 } | 5828 } |
| 5622 | 5829 |
| 5623 class PubSuggestionCodeTest extends ResolverTestCase { | 5830 class PubSuggestionCodeTest extends ResolverTestCase { |
| 5624 void test_import_package() { | 5831 void test_import_package() { |
| 5625 Source source = addSource(EngineTestCase.createSource(["import 'package:some
package/other.dart';"])); | 5832 Source source = addSource("import 'package:somepackage/other.dart';"); |
| 5626 resolve(source); | 5833 resolve(source); |
| 5627 assertErrors(source, [CompileTimeErrorCode.URI_DOES_NOT_EXIST]); | 5834 assertErrors(source, [CompileTimeErrorCode.URI_DOES_NOT_EXIST]); |
| 5628 } | 5835 } |
| 5629 | 5836 |
| 5630 void test_import_packageWithDotDot() { | 5837 void test_import_packageWithDotDot() { |
| 5631 Source source = addSource(EngineTestCase.createSource(["import 'package:some
package/../other.dart';"])); | 5838 Source source = addSource("import 'package:somepackage/../other.dart';"); |
| 5632 resolve(source); | 5839 resolve(source); |
| 5633 assertErrors(source, [ | 5840 assertErrors(source, [ |
| 5634 CompileTimeErrorCode.URI_DOES_NOT_EXIST, | 5841 CompileTimeErrorCode.URI_DOES_NOT_EXIST, |
| 5635 HintCode.PACKAGE_IMPORT_CONTAINS_DOT_DOT]); | 5842 HintCode.PACKAGE_IMPORT_CONTAINS_DOT_DOT]); |
| 5636 } | 5843 } |
| 5637 | 5844 |
| 5638 void test_import_packageWithLeadingDotDot() { | 5845 void test_import_packageWithLeadingDotDot() { |
| 5639 Source source = addSource(EngineTestCase.createSource(["import 'package:../o
ther.dart';"])); | 5846 Source source = addSource("import 'package:../other.dart';"); |
| 5640 resolve(source); | 5847 resolve(source); |
| 5641 assertErrors(source, [ | 5848 assertErrors(source, [ |
| 5642 CompileTimeErrorCode.URI_DOES_NOT_EXIST, | 5849 CompileTimeErrorCode.URI_DOES_NOT_EXIST, |
| 5643 HintCode.PACKAGE_IMPORT_CONTAINS_DOT_DOT]); | 5850 HintCode.PACKAGE_IMPORT_CONTAINS_DOT_DOT]); |
| 5644 } | 5851 } |
| 5645 | 5852 |
| 5646 void test_import_referenceIntoLibDirectory() { | 5853 void test_import_referenceIntoLibDirectory() { |
| 5647 cacheSource("/myproj/pubspec.yaml", ""); | 5854 cacheSource("/myproj/pubspec.yaml", ""); |
| 5648 cacheSource("/myproj/lib/other.dart", ""); | 5855 cacheSource("/myproj/lib/other.dart", ""); |
| 5649 Source source = addNamedSource("/myproj/web/test.dart", EngineTestCase.creat
eSource(["import '../lib/other.dart';"])); | 5856 Source source = addNamedSource("/myproj/web/test.dart", "import '../lib/othe
r.dart';"); |
| 5650 resolve(source); | 5857 resolve(source); |
| 5651 assertErrors(source, [HintCode.FILE_IMPORT_OUTSIDE_LIB_REFERENCES_FILE_INSID
E]); | 5858 assertErrors(source, [HintCode.FILE_IMPORT_OUTSIDE_LIB_REFERENCES_FILE_INSID
E]); |
| 5652 } | 5859 } |
| 5653 | 5860 |
| 5654 void test_import_referenceIntoLibDirectory_no_pubspec() { | 5861 void test_import_referenceIntoLibDirectory_no_pubspec() { |
| 5655 cacheSource("/myproj/lib/other.dart", ""); | 5862 cacheSource("/myproj/lib/other.dart", ""); |
| 5656 Source source = addNamedSource("/myproj/web/test.dart", EngineTestCase.creat
eSource(["import '../lib/other.dart';"])); | 5863 Source source = addNamedSource("/myproj/web/test.dart", "import '../lib/othe
r.dart';"); |
| 5657 resolve(source); | 5864 resolve(source); |
| 5658 assertNoErrors(source); | 5865 assertNoErrors(source); |
| 5659 } | 5866 } |
| 5660 | 5867 |
| 5661 void test_import_referenceOutOfLibDirectory() { | 5868 void test_import_referenceOutOfLibDirectory() { |
| 5662 cacheSource("/myproj/pubspec.yaml", ""); | 5869 cacheSource("/myproj/pubspec.yaml", ""); |
| 5663 cacheSource("/myproj/web/other.dart", ""); | 5870 cacheSource("/myproj/web/other.dart", ""); |
| 5664 Source source = addNamedSource("/myproj/lib/test.dart", EngineTestCase.creat
eSource(["import '../web/other.dart';"])); | 5871 Source source = addNamedSource("/myproj/lib/test.dart", "import '../web/othe
r.dart';"); |
| 5665 resolve(source); | 5872 resolve(source); |
| 5666 assertErrors(source, [HintCode.FILE_IMPORT_INSIDE_LIB_REFERENCES_FILE_OUTSID
E]); | 5873 assertErrors(source, [HintCode.FILE_IMPORT_INSIDE_LIB_REFERENCES_FILE_OUTSID
E]); |
| 5667 } | 5874 } |
| 5668 | 5875 |
| 5669 void test_import_referenceOutOfLibDirectory_no_pubspec() { | 5876 void test_import_referenceOutOfLibDirectory_no_pubspec() { |
| 5670 cacheSource("/myproj/web/other.dart", ""); | 5877 cacheSource("/myproj/web/other.dart", ""); |
| 5671 Source source = addNamedSource("/myproj/lib/test.dart", EngineTestCase.creat
eSource(["import '../web/other.dart';"])); | 5878 Source source = addNamedSource("/myproj/lib/test.dart", "import '../web/othe
r.dart';"); |
| 5672 resolve(source); | 5879 resolve(source); |
| 5673 assertNoErrors(source); | 5880 assertNoErrors(source); |
| 5674 } | 5881 } |
| 5675 | 5882 |
| 5676 void test_import_valid_inside_lib1() { | 5883 void test_import_valid_inside_lib1() { |
| 5677 cacheSource("/myproj/pubspec.yaml", ""); | 5884 cacheSource("/myproj/pubspec.yaml", ""); |
| 5678 cacheSource("/myproj/lib/other.dart", ""); | 5885 cacheSource("/myproj/lib/other.dart", ""); |
| 5679 Source source = addNamedSource("/myproj/lib/test.dart", EngineTestCase.creat
eSource(["import 'other.dart';"])); | 5886 Source source = addNamedSource("/myproj/lib/test.dart", "import 'other.dart'
;"); |
| 5680 resolve(source); | 5887 resolve(source); |
| 5681 assertNoErrors(source); | 5888 assertNoErrors(source); |
| 5682 } | 5889 } |
| 5683 | 5890 |
| 5684 void test_import_valid_inside_lib2() { | 5891 void test_import_valid_inside_lib2() { |
| 5685 cacheSource("/myproj/pubspec.yaml", ""); | 5892 cacheSource("/myproj/pubspec.yaml", ""); |
| 5686 cacheSource("/myproj/lib/bar/other.dart", ""); | 5893 cacheSource("/myproj/lib/bar/other.dart", ""); |
| 5687 Source source = addNamedSource("/myproj/lib/foo/test.dart", EngineTestCase.c
reateSource(["import '../bar/other.dart';"])); | 5894 Source source = addNamedSource("/myproj/lib/foo/test.dart", "import '../bar/
other.dart';"); |
| 5688 resolve(source); | 5895 resolve(source); |
| 5689 assertNoErrors(source); | 5896 assertNoErrors(source); |
| 5690 } | 5897 } |
| 5691 | 5898 |
| 5692 void test_import_valid_outside_lib() { | 5899 void test_import_valid_outside_lib() { |
| 5693 cacheSource("/myproj/pubspec.yaml", ""); | 5900 cacheSource("/myproj/pubspec.yaml", ""); |
| 5694 cacheSource("/myproj/web/other.dart", ""); | 5901 cacheSource("/myproj/web/other.dart", ""); |
| 5695 Source source = addNamedSource("/myproj/lib2/test.dart", EngineTestCase.crea
teSource(["import '../web/other.dart';"])); | 5902 Source source = addNamedSource("/myproj/lib2/test.dart", "import '../web/oth
er.dart';"); |
| 5696 resolve(source); | 5903 resolve(source); |
| 5697 assertNoErrors(source); | 5904 assertNoErrors(source); |
| 5698 } | 5905 } |
| 5699 } | 5906 } |
| 5700 | 5907 |
| 5701 class RecursiveAstVisitor_SimpleResolverTest_test_localVariable_types_invoked ex
tends RecursiveAstVisitor<Object> { | 5908 class RecursiveAstVisitor_SimpleResolverTest_test_localVariable_types_invoked ex
tends RecursiveAstVisitor<Object> { |
| 5702 final SimpleResolverTest SimpleResolverTest_this; | 5909 final SimpleResolverTest SimpleResolverTest_this; |
| 5703 | 5910 |
| 5704 List<bool> found; | 5911 List<bool> found; |
| 5705 | 5912 |
| (...skipping 796 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6502 | 6709 |
| 6503 @override | 6710 @override |
| 6504 AnalysisErrorListener get errorListener => listener; | 6711 AnalysisErrorListener get errorListener => listener; |
| 6505 | 6712 |
| 6506 @override | 6713 @override |
| 6507 Element internalLookup(Identifier identifier, String name, LibraryElement refe
rencingLibrary) => null; | 6714 Element internalLookup(Identifier identifier, String name, LibraryElement refe
rencingLibrary) => null; |
| 6508 } | 6715 } |
| 6509 | 6716 |
| 6510 class SimpleResolverTest extends ResolverTestCase { | 6717 class SimpleResolverTest extends ResolverTestCase { |
| 6511 void fail_staticInvocation() { | 6718 void fail_staticInvocation() { |
| 6512 Source source = addSource(EngineTestCase.createSource([ | 6719 Source source = addSource(r''' |
| 6513 "class A {", | 6720 class A { |
| 6514 " static int get g => (a,b) => 0;", | 6721 static int get g => (a,b) => 0; |
| 6515 "}", | 6722 } |
| 6516 "class B {", | 6723 class B { |
| 6517 " f() {", | 6724 f() { |
| 6518 " A.g(1,0);", | 6725 A.g(1,0); |
| 6519 " }", | 6726 } |
| 6520 "}"])); | 6727 }'''); |
| 6521 resolve(source); | 6728 resolve(source); |
| 6522 assertNoErrors(source); | 6729 assertNoErrors(source); |
| 6523 verify([source]); | 6730 verify([source]); |
| 6524 } | 6731 } |
| 6525 | 6732 |
| 6526 void test_argumentResolution_required_matching() { | 6733 void test_argumentResolution_required_matching() { |
| 6527 Source source = addSource(EngineTestCase.createSource([ | 6734 Source source = addSource(r''' |
| 6528 "class A {", | 6735 class A { |
| 6529 " void f() {", | 6736 void f() { |
| 6530 " g(1, 2, 3);", | 6737 g(1, 2, 3); |
| 6531 " }", | 6738 } |
| 6532 " void g(a, b, c) {}", | 6739 void g(a, b, c) {} |
| 6533 "}"])); | 6740 }'''); |
| 6534 _validateArgumentResolution(source, [0, 1, 2]); | 6741 _validateArgumentResolution(source, [0, 1, 2]); |
| 6535 } | 6742 } |
| 6536 | 6743 |
| 6537 void test_argumentResolution_required_tooFew() { | 6744 void test_argumentResolution_required_tooFew() { |
| 6538 Source source = addSource(EngineTestCase.createSource([ | 6745 Source source = addSource(r''' |
| 6539 "class A {", | 6746 class A { |
| 6540 " void f() {", | 6747 void f() { |
| 6541 " g(1, 2);", | 6748 g(1, 2); |
| 6542 " }", | 6749 } |
| 6543 " void g(a, b, c) {}", | 6750 void g(a, b, c) {} |
| 6544 "}"])); | 6751 }'''); |
| 6545 _validateArgumentResolution(source, [0, 1]); | 6752 _validateArgumentResolution(source, [0, 1]); |
| 6546 } | 6753 } |
| 6547 | 6754 |
| 6548 void test_argumentResolution_required_tooMany() { | 6755 void test_argumentResolution_required_tooMany() { |
| 6549 Source source = addSource(EngineTestCase.createSource([ | 6756 Source source = addSource(r''' |
| 6550 "class A {", | 6757 class A { |
| 6551 " void f() {", | 6758 void f() { |
| 6552 " g(1, 2, 3);", | 6759 g(1, 2, 3); |
| 6553 " }", | 6760 } |
| 6554 " void g(a, b) {}", | 6761 void g(a, b) {} |
| 6555 "}"])); | 6762 }'''); |
| 6556 _validateArgumentResolution(source, [0, 1, -1]); | 6763 _validateArgumentResolution(source, [0, 1, -1]); |
| 6557 } | 6764 } |
| 6558 | 6765 |
| 6559 void test_argumentResolution_requiredAndNamed_extra() { | 6766 void test_argumentResolution_requiredAndNamed_extra() { |
| 6560 Source source = addSource(EngineTestCase.createSource([ | 6767 Source source = addSource(r''' |
| 6561 "class A {", | 6768 class A { |
| 6562 " void f() {", | 6769 void f() { |
| 6563 " g(1, 2, c: 3, d: 4);", | 6770 g(1, 2, c: 3, d: 4); |
| 6564 " }", | 6771 } |
| 6565 " void g(a, b, {c}) {}", | 6772 void g(a, b, {c}) {} |
| 6566 "}"])); | 6773 }'''); |
| 6567 _validateArgumentResolution(source, [0, 1, 2, -1]); | 6774 _validateArgumentResolution(source, [0, 1, 2, -1]); |
| 6568 } | 6775 } |
| 6569 | 6776 |
| 6570 void test_argumentResolution_requiredAndNamed_matching() { | 6777 void test_argumentResolution_requiredAndNamed_matching() { |
| 6571 Source source = addSource(EngineTestCase.createSource([ | 6778 Source source = addSource(r''' |
| 6572 "class A {", | 6779 class A { |
| 6573 " void f() {", | 6780 void f() { |
| 6574 " g(1, 2, c: 3);", | 6781 g(1, 2, c: 3); |
| 6575 " }", | 6782 } |
| 6576 " void g(a, b, {c}) {}", | 6783 void g(a, b, {c}) {} |
| 6577 "}"])); | 6784 }'''); |
| 6578 _validateArgumentResolution(source, [0, 1, 2]); | 6785 _validateArgumentResolution(source, [0, 1, 2]); |
| 6579 } | 6786 } |
| 6580 | 6787 |
| 6581 void test_argumentResolution_requiredAndNamed_missing() { | 6788 void test_argumentResolution_requiredAndNamed_missing() { |
| 6582 Source source = addSource(EngineTestCase.createSource([ | 6789 Source source = addSource(r''' |
| 6583 "class A {", | 6790 class A { |
| 6584 " void f() {", | 6791 void f() { |
| 6585 " g(1, 2, d: 3);", | 6792 g(1, 2, d: 3); |
| 6586 " }", | 6793 } |
| 6587 " void g(a, b, {c, d}) {}", | 6794 void g(a, b, {c, d}) {} |
| 6588 "}"])); | 6795 }'''); |
| 6589 _validateArgumentResolution(source, [0, 1, 3]); | 6796 _validateArgumentResolution(source, [0, 1, 3]); |
| 6590 } | 6797 } |
| 6591 | 6798 |
| 6592 void test_argumentResolution_requiredAndPositional_fewer() { | 6799 void test_argumentResolution_requiredAndPositional_fewer() { |
| 6593 Source source = addSource(EngineTestCase.createSource([ | 6800 Source source = addSource(r''' |
| 6594 "class A {", | 6801 class A { |
| 6595 " void f() {", | 6802 void f() { |
| 6596 " g(1, 2, 3);", | 6803 g(1, 2, 3); |
| 6597 " }", | 6804 } |
| 6598 " void g(a, b, [c, d]) {}", | 6805 void g(a, b, [c, d]) {} |
| 6599 "}"])); | 6806 }'''); |
| 6600 _validateArgumentResolution(source, [0, 1, 2]); | 6807 _validateArgumentResolution(source, [0, 1, 2]); |
| 6601 } | 6808 } |
| 6602 | 6809 |
| 6603 void test_argumentResolution_requiredAndPositional_matching() { | 6810 void test_argumentResolution_requiredAndPositional_matching() { |
| 6604 Source source = addSource(EngineTestCase.createSource([ | 6811 Source source = addSource(r''' |
| 6605 "class A {", | 6812 class A { |
| 6606 " void f() {", | 6813 void f() { |
| 6607 " g(1, 2, 3, 4);", | 6814 g(1, 2, 3, 4); |
| 6608 " }", | 6815 } |
| 6609 " void g(a, b, [c, d]) {}", | 6816 void g(a, b, [c, d]) {} |
| 6610 "}"])); | 6817 }'''); |
| 6611 _validateArgumentResolution(source, [0, 1, 2, 3]); | 6818 _validateArgumentResolution(source, [0, 1, 2, 3]); |
| 6612 } | 6819 } |
| 6613 | 6820 |
| 6614 void test_argumentResolution_requiredAndPositional_more() { | 6821 void test_argumentResolution_requiredAndPositional_more() { |
| 6615 Source source = addSource(EngineTestCase.createSource([ | 6822 Source source = addSource(r''' |
| 6616 "class A {", | 6823 class A { |
| 6617 " void f() {", | 6824 void f() { |
| 6618 " g(1, 2, 3, 4);", | 6825 g(1, 2, 3, 4); |
| 6619 " }", | 6826 } |
| 6620 " void g(a, b, [c]) {}", | 6827 void g(a, b, [c]) {} |
| 6621 "}"])); | 6828 }'''); |
| 6622 _validateArgumentResolution(source, [0, 1, 2, -1]); | 6829 _validateArgumentResolution(source, [0, 1, 2, -1]); |
| 6623 } | 6830 } |
| 6624 | 6831 |
| 6625 void test_argumentResolution_setter_propagated() { | 6832 void test_argumentResolution_setter_propagated() { |
| 6626 Source source = addSource(EngineTestCase.createSource([ | 6833 Source source = addSource(r''' |
| 6627 "main() {", | 6834 main() { |
| 6628 " var a = new A();", | 6835 var a = new A(); |
| 6629 " a.sss = 0;", | 6836 a.sss = 0; |
| 6630 "}", | 6837 } |
| 6631 "class A {", | 6838 class A { |
| 6632 " set sss(x) {}", | 6839 set sss(x) {} |
| 6633 "}"])); | 6840 }'''); |
| 6634 LibraryElement library = resolve(source); | 6841 LibraryElement library = resolve(source); |
| 6635 CompilationUnitElement unit = library.definingCompilationUnit; | 6842 CompilationUnitElement unit = library.definingCompilationUnit; |
| 6636 // find "a.sss = 0" | 6843 // find "a.sss = 0" |
| 6637 AssignmentExpression assignment; | 6844 AssignmentExpression assignment; |
| 6638 { | 6845 { |
| 6639 FunctionElement mainElement = unit.functions[0]; | 6846 FunctionElement mainElement = unit.functions[0]; |
| 6640 FunctionBody mainBody = mainElement.node.functionExpression.body; | 6847 FunctionBody mainBody = mainElement.node.functionExpression.body; |
| 6641 Statement statement = (mainBody as BlockFunctionBody).block.statements[1]; | 6848 Statement statement = (mainBody as BlockFunctionBody).block.statements[1]; |
| 6642 ExpressionStatement expressionStatement = statement as ExpressionStatement
; | 6849 ExpressionStatement expressionStatement = statement as ExpressionStatement
; |
| 6643 assignment = expressionStatement.expression as AssignmentExpression; | 6850 assignment = expressionStatement.expression as AssignmentExpression; |
| 6644 } | 6851 } |
| 6645 // get parameter | 6852 // get parameter |
| 6646 Expression rhs = assignment.rightHandSide; | 6853 Expression rhs = assignment.rightHandSide; |
| 6647 JUnitTestCase.assertNull(rhs.staticParameterElement); | 6854 JUnitTestCase.assertNull(rhs.staticParameterElement); |
| 6648 ParameterElement parameter = rhs.propagatedParameterElement; | 6855 ParameterElement parameter = rhs.propagatedParameterElement; |
| 6649 JUnitTestCase.assertNotNull(parameter); | 6856 JUnitTestCase.assertNotNull(parameter); |
| 6650 JUnitTestCase.assertEquals("x", parameter.displayName); | 6857 JUnitTestCase.assertEquals("x", parameter.displayName); |
| 6651 // validate | 6858 // validate |
| 6652 ClassElement classA = unit.types[0]; | 6859 ClassElement classA = unit.types[0]; |
| 6653 PropertyAccessorElement setter = classA.accessors[0]; | 6860 PropertyAccessorElement setter = classA.accessors[0]; |
| 6654 JUnitTestCase.assertSame(parameter, setter.parameters[0]); | 6861 JUnitTestCase.assertSame(parameter, setter.parameters[0]); |
| 6655 } | 6862 } |
| 6656 | 6863 |
| 6657 void test_argumentResolution_setter_propagated_propertyAccess() { | 6864 void test_argumentResolution_setter_propagated_propertyAccess() { |
| 6658 Source source = addSource(EngineTestCase.createSource([ | 6865 Source source = addSource(r''' |
| 6659 "main() {", | 6866 main() { |
| 6660 " var a = new A();", | 6867 var a = new A(); |
| 6661 " a.b.sss = 0;", | 6868 a.b.sss = 0; |
| 6662 "}", | 6869 } |
| 6663 "class A {", | 6870 class A { |
| 6664 " B b = new B();", | 6871 B b = new B(); |
| 6665 "}", | 6872 } |
| 6666 "class B {", | 6873 class B { |
| 6667 " set sss(x) {}", | 6874 set sss(x) {} |
| 6668 "}"])); | 6875 }'''); |
| 6669 LibraryElement library = resolve(source); | 6876 LibraryElement library = resolve(source); |
| 6670 CompilationUnitElement unit = library.definingCompilationUnit; | 6877 CompilationUnitElement unit = library.definingCompilationUnit; |
| 6671 // find "a.b.sss = 0" | 6878 // find "a.b.sss = 0" |
| 6672 AssignmentExpression assignment; | 6879 AssignmentExpression assignment; |
| 6673 { | 6880 { |
| 6674 FunctionElement mainElement = unit.functions[0]; | 6881 FunctionElement mainElement = unit.functions[0]; |
| 6675 FunctionBody mainBody = mainElement.node.functionExpression.body; | 6882 FunctionBody mainBody = mainElement.node.functionExpression.body; |
| 6676 Statement statement = (mainBody as BlockFunctionBody).block.statements[1]; | 6883 Statement statement = (mainBody as BlockFunctionBody).block.statements[1]; |
| 6677 ExpressionStatement expressionStatement = statement as ExpressionStatement
; | 6884 ExpressionStatement expressionStatement = statement as ExpressionStatement
; |
| 6678 assignment = expressionStatement.expression as AssignmentExpression; | 6885 assignment = expressionStatement.expression as AssignmentExpression; |
| 6679 } | 6886 } |
| 6680 // get parameter | 6887 // get parameter |
| 6681 Expression rhs = assignment.rightHandSide; | 6888 Expression rhs = assignment.rightHandSide; |
| 6682 JUnitTestCase.assertNull(rhs.staticParameterElement); | 6889 JUnitTestCase.assertNull(rhs.staticParameterElement); |
| 6683 ParameterElement parameter = rhs.propagatedParameterElement; | 6890 ParameterElement parameter = rhs.propagatedParameterElement; |
| 6684 JUnitTestCase.assertNotNull(parameter); | 6891 JUnitTestCase.assertNotNull(parameter); |
| 6685 JUnitTestCase.assertEquals("x", parameter.displayName); | 6892 JUnitTestCase.assertEquals("x", parameter.displayName); |
| 6686 // validate | 6893 // validate |
| 6687 ClassElement classB = unit.types[1]; | 6894 ClassElement classB = unit.types[1]; |
| 6688 PropertyAccessorElement setter = classB.accessors[0]; | 6895 PropertyAccessorElement setter = classB.accessors[0]; |
| 6689 JUnitTestCase.assertSame(parameter, setter.parameters[0]); | 6896 JUnitTestCase.assertSame(parameter, setter.parameters[0]); |
| 6690 } | 6897 } |
| 6691 | 6898 |
| 6692 void test_argumentResolution_setter_static() { | 6899 void test_argumentResolution_setter_static() { |
| 6693 Source source = addSource(EngineTestCase.createSource([ | 6900 Source source = addSource(r''' |
| 6694 "main() {", | 6901 main() { |
| 6695 " A a = new A();", | 6902 A a = new A(); |
| 6696 " a.sss = 0;", | 6903 a.sss = 0; |
| 6697 "}", | 6904 } |
| 6698 "class A {", | 6905 class A { |
| 6699 " set sss(x) {}", | 6906 set sss(x) {} |
| 6700 "}"])); | 6907 }'''); |
| 6701 LibraryElement library = resolve(source); | 6908 LibraryElement library = resolve(source); |
| 6702 CompilationUnitElement unit = library.definingCompilationUnit; | 6909 CompilationUnitElement unit = library.definingCompilationUnit; |
| 6703 // find "a.sss = 0" | 6910 // find "a.sss = 0" |
| 6704 AssignmentExpression assignment; | 6911 AssignmentExpression assignment; |
| 6705 { | 6912 { |
| 6706 FunctionElement mainElement = unit.functions[0]; | 6913 FunctionElement mainElement = unit.functions[0]; |
| 6707 FunctionBody mainBody = mainElement.node.functionExpression.body; | 6914 FunctionBody mainBody = mainElement.node.functionExpression.body; |
| 6708 Statement statement = (mainBody as BlockFunctionBody).block.statements[1]; | 6915 Statement statement = (mainBody as BlockFunctionBody).block.statements[1]; |
| 6709 ExpressionStatement expressionStatement = statement as ExpressionStatement
; | 6916 ExpressionStatement expressionStatement = statement as ExpressionStatement
; |
| 6710 assignment = expressionStatement.expression as AssignmentExpression; | 6917 assignment = expressionStatement.expression as AssignmentExpression; |
| 6711 } | 6918 } |
| 6712 // get parameter | 6919 // get parameter |
| 6713 Expression rhs = assignment.rightHandSide; | 6920 Expression rhs = assignment.rightHandSide; |
| 6714 ParameterElement parameter = rhs.staticParameterElement; | 6921 ParameterElement parameter = rhs.staticParameterElement; |
| 6715 JUnitTestCase.assertNotNull(parameter); | 6922 JUnitTestCase.assertNotNull(parameter); |
| 6716 JUnitTestCase.assertEquals("x", parameter.displayName); | 6923 JUnitTestCase.assertEquals("x", parameter.displayName); |
| 6717 // validate | 6924 // validate |
| 6718 ClassElement classA = unit.types[0]; | 6925 ClassElement classA = unit.types[0]; |
| 6719 PropertyAccessorElement setter = classA.accessors[0]; | 6926 PropertyAccessorElement setter = classA.accessors[0]; |
| 6720 JUnitTestCase.assertSame(parameter, setter.parameters[0]); | 6927 JUnitTestCase.assertSame(parameter, setter.parameters[0]); |
| 6721 } | 6928 } |
| 6722 | 6929 |
| 6723 void test_argumentResolution_setter_static_propertyAccess() { | 6930 void test_argumentResolution_setter_static_propertyAccess() { |
| 6724 Source source = addSource(EngineTestCase.createSource([ | 6931 Source source = addSource(r''' |
| 6725 "main() {", | 6932 main() { |
| 6726 " A a = new A();", | 6933 A a = new A(); |
| 6727 " a.b.sss = 0;", | 6934 a.b.sss = 0; |
| 6728 "}", | 6935 } |
| 6729 "class A {", | 6936 class A { |
| 6730 " B b = new B();", | 6937 B b = new B(); |
| 6731 "}", | 6938 } |
| 6732 "class B {", | 6939 class B { |
| 6733 " set sss(x) {}", | 6940 set sss(x) {} |
| 6734 "}"])); | 6941 }'''); |
| 6735 LibraryElement library = resolve(source); | 6942 LibraryElement library = resolve(source); |
| 6736 CompilationUnitElement unit = library.definingCompilationUnit; | 6943 CompilationUnitElement unit = library.definingCompilationUnit; |
| 6737 // find "a.b.sss = 0" | 6944 // find "a.b.sss = 0" |
| 6738 AssignmentExpression assignment; | 6945 AssignmentExpression assignment; |
| 6739 { | 6946 { |
| 6740 FunctionElement mainElement = unit.functions[0]; | 6947 FunctionElement mainElement = unit.functions[0]; |
| 6741 FunctionBody mainBody = mainElement.node.functionExpression.body; | 6948 FunctionBody mainBody = mainElement.node.functionExpression.body; |
| 6742 Statement statement = (mainBody as BlockFunctionBody).block.statements[1]; | 6949 Statement statement = (mainBody as BlockFunctionBody).block.statements[1]; |
| 6743 ExpressionStatement expressionStatement = statement as ExpressionStatement
; | 6950 ExpressionStatement expressionStatement = statement as ExpressionStatement
; |
| 6744 assignment = expressionStatement.expression as AssignmentExpression; | 6951 assignment = expressionStatement.expression as AssignmentExpression; |
| 6745 } | 6952 } |
| 6746 // get parameter | 6953 // get parameter |
| 6747 Expression rhs = assignment.rightHandSide; | 6954 Expression rhs = assignment.rightHandSide; |
| 6748 ParameterElement parameter = rhs.staticParameterElement; | 6955 ParameterElement parameter = rhs.staticParameterElement; |
| 6749 JUnitTestCase.assertNotNull(parameter); | 6956 JUnitTestCase.assertNotNull(parameter); |
| 6750 JUnitTestCase.assertEquals("x", parameter.displayName); | 6957 JUnitTestCase.assertEquals("x", parameter.displayName); |
| 6751 // validate | 6958 // validate |
| 6752 ClassElement classB = unit.types[1]; | 6959 ClassElement classB = unit.types[1]; |
| 6753 PropertyAccessorElement setter = classB.accessors[0]; | 6960 PropertyAccessorElement setter = classB.accessors[0]; |
| 6754 JUnitTestCase.assertSame(parameter, setter.parameters[0]); | 6961 JUnitTestCase.assertSame(parameter, setter.parameters[0]); |
| 6755 } | 6962 } |
| 6756 | 6963 |
| 6757 void test_class_definesCall() { | 6964 void test_class_definesCall() { |
| 6758 Source source = addSource(EngineTestCase.createSource([ | 6965 Source source = addSource(r''' |
| 6759 "class A {", | 6966 class A { |
| 6760 " int call(int x) { return x; }", | 6967 int call(int x) { return x; } |
| 6761 "}", | 6968 } |
| 6762 "int f(A a) {", | 6969 int f(A a) { |
| 6763 " return a(0);", | 6970 return a(0); |
| 6764 "}"])); | 6971 }'''); |
| 6765 resolve(source); | 6972 resolve(source); |
| 6766 assertNoErrors(source); | 6973 assertNoErrors(source); |
| 6767 verify([source]); | 6974 verify([source]); |
| 6768 } | 6975 } |
| 6769 | 6976 |
| 6770 void test_class_extends_implements() { | 6977 void test_class_extends_implements() { |
| 6771 Source source = addSource(EngineTestCase.createSource([ | 6978 Source source = addSource(r''' |
| 6772 "class A extends B implements C {}", | 6979 class A extends B implements C {} |
| 6773 "class B {}", | 6980 class B {} |
| 6774 "class C {}"])); | 6981 class C {}'''); |
| 6775 resolve(source); | 6982 resolve(source); |
| 6776 assertNoErrors(source); | 6983 assertNoErrors(source); |
| 6777 verify([source]); | 6984 verify([source]); |
| 6778 } | 6985 } |
| 6779 | 6986 |
| 6780 void test_commentReference_class() { | 6987 void test_commentReference_class() { |
| 6781 Source source = addSource(EngineTestCase.createSource([ | 6988 Source source = addSource(r''' |
| 6782 "f() {}", | 6989 f() {} |
| 6783 "/** [A] [new A] [A.n] [new A.n] [m] [f] */", | 6990 /** [A] [new A] [A.n] [new A.n] [m] [f] */ |
| 6784 "class A {", | 6991 class A { |
| 6785 " A() {}", | 6992 A() {} |
| 6786 " A.n() {}", | 6993 A.n() {} |
| 6787 " m() {}", | 6994 m() {} |
| 6788 "}"])); | 6995 }'''); |
| 6789 resolve(source); | 6996 resolve(source); |
| 6790 assertNoErrors(source); | 6997 assertNoErrors(source); |
| 6791 verify([source]); | 6998 verify([source]); |
| 6792 } | 6999 } |
| 6793 | 7000 |
| 6794 void test_commentReference_parameter() { | 7001 void test_commentReference_parameter() { |
| 6795 Source source = addSource(EngineTestCase.createSource([ | 7002 Source source = addSource(r''' |
| 6796 "class A {", | 7003 class A { |
| 6797 " A() {}", | 7004 A() {} |
| 6798 " A.n() {}", | 7005 A.n() {} |
| 6799 " /** [e] [f] */", | 7006 /** [e] [f] */ |
| 6800 " m(e, f()) {}", | 7007 m(e, f()) {} |
| 6801 "}"])); | 7008 }'''); |
| 6802 resolve(source); | 7009 resolve(source); |
| 6803 assertNoErrors(source); | 7010 assertNoErrors(source); |
| 6804 verify([source]); | 7011 verify([source]); |
| 6805 } | 7012 } |
| 6806 | 7013 |
| 6807 void test_commentReference_singleLine() { | 7014 void test_commentReference_singleLine() { |
| 6808 Source source = addSource(EngineTestCase.createSource(["/// [A]", "class A {
}"])); | 7015 Source source = addSource(r''' |
| 7016 /// [A] |
| 7017 class A {}'''); |
| 6809 resolve(source); | 7018 resolve(source); |
| 6810 assertNoErrors(source); | 7019 assertNoErrors(source); |
| 6811 verify([source]); | 7020 verify([source]); |
| 6812 } | 7021 } |
| 6813 | 7022 |
| 6814 void test_empty() { | 7023 void test_empty() { |
| 6815 Source source = addSource(""); | 7024 Source source = addSource(""); |
| 6816 resolve(source); | 7025 resolve(source); |
| 6817 assertNoErrors(source); | 7026 assertNoErrors(source); |
| 6818 verify([source]); | 7027 verify([source]); |
| 6819 } | 7028 } |
| 6820 | 7029 |
| 6821 void test_entryPoint_exported() { | 7030 void test_entryPoint_exported() { |
| 6822 addNamedSource("/two.dart", EngineTestCase.createSource(["library two;", "ma
in() {}"])); | 7031 addNamedSource("/two.dart", r''' |
| 6823 Source source = addNamedSource("/one.dart", EngineTestCase.createSource(["li
brary one;", "export 'two.dart';"])); | 7032 library two; |
| 7033 main() {}'''); |
| 7034 Source source = addNamedSource("/one.dart", r''' |
| 7035 library one; |
| 7036 export 'two.dart';'''); |
| 6824 LibraryElement library = resolve(source); | 7037 LibraryElement library = resolve(source); |
| 6825 JUnitTestCase.assertNotNull(library); | 7038 JUnitTestCase.assertNotNull(library); |
| 6826 FunctionElement main = library.entryPoint; | 7039 FunctionElement main = library.entryPoint; |
| 6827 JUnitTestCase.assertNotNull(main); | 7040 JUnitTestCase.assertNotNull(main); |
| 6828 JUnitTestCase.assertNotSame(library, main.library); | 7041 JUnitTestCase.assertNotSame(library, main.library); |
| 6829 assertNoErrors(source); | 7042 assertNoErrors(source); |
| 6830 verify([source]); | 7043 verify([source]); |
| 6831 } | 7044 } |
| 6832 | 7045 |
| 6833 void test_entryPoint_local() { | 7046 void test_entryPoint_local() { |
| 6834 Source source = addNamedSource("/one.dart", EngineTestCase.createSource(["li
brary one;", "main() {}"])); | 7047 Source source = addNamedSource("/one.dart", r''' |
| 7048 library one; |
| 7049 main() {}'''); |
| 6835 LibraryElement library = resolve(source); | 7050 LibraryElement library = resolve(source); |
| 6836 JUnitTestCase.assertNotNull(library); | 7051 JUnitTestCase.assertNotNull(library); |
| 6837 FunctionElement main = library.entryPoint; | 7052 FunctionElement main = library.entryPoint; |
| 6838 JUnitTestCase.assertNotNull(main); | 7053 JUnitTestCase.assertNotNull(main); |
| 6839 JUnitTestCase.assertSame(library, main.library); | 7054 JUnitTestCase.assertSame(library, main.library); |
| 6840 assertNoErrors(source); | 7055 assertNoErrors(source); |
| 6841 verify([source]); | 7056 verify([source]); |
| 6842 } | 7057 } |
| 6843 | 7058 |
| 6844 void test_entryPoint_none() { | 7059 void test_entryPoint_none() { |
| 6845 Source source = addNamedSource("/one.dart", EngineTestCase.createSource(["li
brary one;"])); | 7060 Source source = addNamedSource("/one.dart", "library one;"); |
| 6846 LibraryElement library = resolve(source); | 7061 LibraryElement library = resolve(source); |
| 6847 JUnitTestCase.assertNotNull(library); | 7062 JUnitTestCase.assertNotNull(library); |
| 6848 JUnitTestCase.assertNull(library.entryPoint); | 7063 JUnitTestCase.assertNull(library.entryPoint); |
| 6849 assertNoErrors(source); | 7064 assertNoErrors(source); |
| 6850 verify([source]); | 7065 verify([source]); |
| 6851 } | 7066 } |
| 6852 | 7067 |
| 6853 void test_extractedMethodAsConstant() { | 7068 void test_extractedMethodAsConstant() { |
| 6854 Source source = addSource(EngineTestCase.createSource([ | 7069 Source source = addSource(r''' |
| 6855 "abstract class Comparable<T> {", | 7070 abstract class Comparable<T> { |
| 6856 " int compareTo(T other);", | 7071 int compareTo(T other); |
| 6857 " static int compare(Comparable a, Comparable b) => a.compareTo(b);", | 7072 static int compare(Comparable a, Comparable b) => a.compareTo(b); |
| 6858 "}", | 7073 } |
| 6859 "class A {", | 7074 class A { |
| 6860 " void sort([compare = Comparable.compare]) {}", | 7075 void sort([compare = Comparable.compare]) {} |
| 6861 "}"])); | 7076 }'''); |
| 6862 resolve(source); | 7077 resolve(source); |
| 6863 assertNoErrors(source); | 7078 assertNoErrors(source); |
| 6864 verify([source]); | 7079 verify([source]); |
| 6865 } | 7080 } |
| 6866 | 7081 |
| 6867 void test_fieldFormalParameter() { | 7082 void test_fieldFormalParameter() { |
| 6868 Source source = addSource(EngineTestCase.createSource(["class A {", " int x
;", " A(this.x) {}", "}"])); | 7083 Source source = addSource(r''' |
| 7084 class A { |
| 7085 int x; |
| 7086 A(this.x) {} |
| 7087 }'''); |
| 6869 resolve(source); | 7088 resolve(source); |
| 6870 assertNoErrors(source); | 7089 assertNoErrors(source); |
| 6871 verify([source]); | 7090 verify([source]); |
| 6872 } | 7091 } |
| 6873 | 7092 |
| 6874 void test_forEachLoops_nonConflicting() { | 7093 void test_forEachLoops_nonConflicting() { |
| 6875 Source source = addSource(EngineTestCase.createSource([ | 7094 Source source = addSource(r''' |
| 6876 "f() {", | 7095 f() { |
| 6877 " List list = [1,2,3];", | 7096 List list = [1,2,3]; |
| 6878 " for (int x in list) {}", | 7097 for (int x in list) {} |
| 6879 " for (int x in list) {}", | 7098 for (int x in list) {} |
| 6880 "}"])); | 7099 }'''); |
| 6881 resolve(source); | 7100 resolve(source); |
| 6882 assertNoErrors(source); | 7101 assertNoErrors(source); |
| 6883 verify([source]); | 7102 verify([source]); |
| 6884 } | 7103 } |
| 6885 | 7104 |
| 6886 void test_forLoops_nonConflicting() { | 7105 void test_forLoops_nonConflicting() { |
| 6887 Source source = addSource(EngineTestCase.createSource([ | 7106 Source source = addSource(r''' |
| 6888 "f() {", | 7107 f() { |
| 6889 " for (int i = 0; i < 3; i++) {", | 7108 for (int i = 0; i < 3; i++) { |
| 6890 " }", | 7109 } |
| 6891 " for (int i = 0; i < 3; i++) {", | 7110 for (int i = 0; i < 3; i++) { |
| 6892 " }", | 7111 } |
| 6893 "}"])); | 7112 }'''); |
| 6894 resolve(source); | 7113 resolve(source); |
| 6895 assertNoErrors(source); | 7114 assertNoErrors(source); |
| 6896 verify([source]); | 7115 verify([source]); |
| 6897 } | 7116 } |
| 6898 | 7117 |
| 6899 void test_functionTypeAlias() { | 7118 void test_functionTypeAlias() { |
| 6900 Source source = addSource(EngineTestCase.createSource([ | 7119 Source source = addSource(r''' |
| 6901 "typedef bool P(e);", | 7120 typedef bool P(e); |
| 6902 "class A {", | 7121 class A { |
| 6903 " P p;", | 7122 P p; |
| 6904 " m(e) {", | 7123 m(e) { |
| 6905 " if (p(e)) {}", | 7124 if (p(e)) {} |
| 6906 " }", | 7125 } |
| 6907 "}"])); | 7126 }'''); |
| 6908 resolve(source); | 7127 resolve(source); |
| 6909 assertNoErrors(source); | 7128 assertNoErrors(source); |
| 6910 verify([source]); | 7129 verify([source]); |
| 6911 } | 7130 } |
| 6912 | 7131 |
| 6913 void test_getterAndSetterWithDifferentTypes() { | 7132 void test_getterAndSetterWithDifferentTypes() { |
| 6914 Source source = addSource(EngineTestCase.createSource([ | 7133 Source source = addSource(r''' |
| 6915 "class A {", | 7134 class A { |
| 6916 " int get f => 0;", | 7135 int get f => 0; |
| 6917 " void set f(String s) {}", | 7136 void set f(String s) {} |
| 6918 "}", | 7137 } |
| 6919 "g (A a) {", | 7138 g (A a) { |
| 6920 " a.f = a.f.toString();", | 7139 a.f = a.f.toString(); |
| 6921 "}"])); | 7140 }'''); |
| 6922 resolve(source); | 7141 resolve(source); |
| 6923 assertErrors(source, [StaticWarningCode.MISMATCHED_GETTER_AND_SETTER_TYPES])
; | 7142 assertErrors(source, [StaticWarningCode.MISMATCHED_GETTER_AND_SETTER_TYPES])
; |
| 6924 verify([source]); | 7143 verify([source]); |
| 6925 } | 7144 } |
| 6926 | 7145 |
| 6927 void test_hasReferenceToSuper() { | 7146 void test_hasReferenceToSuper() { |
| 6928 Source source = addSource(EngineTestCase.createSource(["class A {}", "class
B {toString() => super.toString();}"])); | 7147 Source source = addSource(r''' |
| 7148 class A {} |
| 7149 class B {toString() => super.toString();}'''); |
| 6929 LibraryElement library = resolve(source); | 7150 LibraryElement library = resolve(source); |
| 6930 JUnitTestCase.assertNotNull(library); | 7151 JUnitTestCase.assertNotNull(library); |
| 6931 CompilationUnitElement unit = library.definingCompilationUnit; | 7152 CompilationUnitElement unit = library.definingCompilationUnit; |
| 6932 JUnitTestCase.assertNotNull(unit); | 7153 JUnitTestCase.assertNotNull(unit); |
| 6933 List<ClassElement> classes = unit.types; | 7154 List<ClassElement> classes = unit.types; |
| 6934 EngineTestCase.assertLength(2, classes); | 7155 EngineTestCase.assertLength(2, classes); |
| 6935 JUnitTestCase.assertFalse(classes[0].hasReferenceToSuper); | 7156 JUnitTestCase.assertFalse(classes[0].hasReferenceToSuper); |
| 6936 JUnitTestCase.assertTrue(classes[1].hasReferenceToSuper); | 7157 JUnitTestCase.assertTrue(classes[1].hasReferenceToSuper); |
| 6937 assertNoErrors(source); | 7158 assertNoErrors(source); |
| 6938 verify([source]); | 7159 verify([source]); |
| 6939 } | 7160 } |
| 6940 | 7161 |
| 6941 void test_import_hide() { | 7162 void test_import_hide() { |
| 6942 addNamedSource("lib1.dart", EngineTestCase.createSource(["library lib1;", "s
et foo(value) {}", "class A {}"])); | 7163 addNamedSource("lib1.dart", r''' |
| 6943 addNamedSource("lib2.dart", EngineTestCase.createSource(["library lib2;", "s
et foo(value) {}"])); | 7164 library lib1; |
| 6944 Source source = addNamedSource("lib3.dart", EngineTestCase.createSource([ | 7165 set foo(value) {} |
| 6945 "import 'lib1.dart' hide foo;", | 7166 class A {}'''); |
| 6946 "import 'lib2.dart';", | 7167 addNamedSource("lib2.dart", r''' |
| 6947 "", | 7168 library lib2; |
| 6948 "main() {", | 7169 set foo(value) {}'''); |
| 6949 " foo = 0;", | 7170 Source source = addNamedSource("lib3.dart", r''' |
| 6950 "}", | 7171 import 'lib1.dart' hide foo; |
| 6951 "A a;"])); | 7172 import 'lib2.dart'; |
| 7173 |
| 7174 main() { |
| 7175 foo = 0; |
| 7176 } |
| 7177 A a;'''); |
| 6952 resolve(source); | 7178 resolve(source); |
| 6953 assertNoErrors(source); | 7179 assertNoErrors(source); |
| 6954 verify([source]); | 7180 verify([source]); |
| 6955 } | 7181 } |
| 6956 | 7182 |
| 6957 void test_import_prefix() { | 7183 void test_import_prefix() { |
| 6958 addNamedSource("/two.dart", EngineTestCase.createSource(["library two;", "f(
int x) {", " return x * x;", "}"])); | 7184 addNamedSource("/two.dart", r''' |
| 6959 Source source = addNamedSource("/one.dart", EngineTestCase.createSource([ | 7185 library two; |
| 6960 "library one;", | 7186 f(int x) { |
| 6961 "import 'two.dart' as _two;", | 7187 return x * x; |
| 6962 "main() {", | 7188 }'''); |
| 6963 " _two.f(0);", | 7189 Source source = addNamedSource("/one.dart", r''' |
| 6964 "}"])); | 7190 library one; |
| 7191 import 'two.dart' as _two; |
| 7192 main() { |
| 7193 _two.f(0); |
| 7194 }'''); |
| 6965 resolve(source); | 7195 resolve(source); |
| 6966 assertNoErrors(source); | 7196 assertNoErrors(source); |
| 6967 verify([source]); | 7197 verify([source]); |
| 6968 } | 7198 } |
| 6969 | 7199 |
| 6970 void test_import_spaceInUri() { | 7200 void test_import_spaceInUri() { |
| 6971 addNamedSource("sub folder/lib.dart", EngineTestCase.createSource(["library
lib;", "foo() {}"])); | 7201 addNamedSource("sub folder/lib.dart", r''' |
| 6972 Source source = addNamedSource("app.dart", EngineTestCase.createSource([ | 7202 library lib; |
| 6973 "import 'sub folder/lib.dart';", | 7203 foo() {}'''); |
| 6974 "", | 7204 Source source = addNamedSource("app.dart", r''' |
| 6975 "main() {", | 7205 import 'sub folder/lib.dart'; |
| 6976 " foo();", | 7206 |
| 6977 "}"])); | 7207 main() { |
| 7208 foo(); |
| 7209 }'''); |
| 6978 resolve(source); | 7210 resolve(source); |
| 6979 assertNoErrors(source); | 7211 assertNoErrors(source); |
| 6980 verify([source]); | 7212 verify([source]); |
| 6981 } | 7213 } |
| 6982 | 7214 |
| 6983 void test_indexExpression_typeParameters() { | 7215 void test_indexExpression_typeParameters() { |
| 6984 Source source = addSource(EngineTestCase.createSource([ | 7216 Source source = addSource(r''' |
| 6985 "f() {", | 7217 f() { |
| 6986 " List<int> a;", | 7218 List<int> a; |
| 6987 " a[0];", | 7219 a[0]; |
| 6988 " List<List<int>> b;", | 7220 List<List<int>> b; |
| 6989 " b[0][0];", | 7221 b[0][0]; |
| 6990 " List<List<List<int>>> c;", | 7222 List<List<List<int>>> c; |
| 6991 " c[0][0][0];", | 7223 c[0][0][0]; |
| 6992 "}"])); | 7224 }'''); |
| 6993 resolve(source); | 7225 resolve(source); |
| 6994 assertNoErrors(source); | 7226 assertNoErrors(source); |
| 6995 verify([source]); | 7227 verify([source]); |
| 6996 } | 7228 } |
| 6997 | 7229 |
| 6998 void test_indexExpression_typeParameters_invalidAssignmentWarning() { | 7230 void test_indexExpression_typeParameters_invalidAssignmentWarning() { |
| 6999 Source source = addSource(EngineTestCase.createSource(["f() {", " List<List
<int>> b;", " b[0][0] = 'hi';", "}"])); | 7231 Source source = addSource(r''' |
| 7232 f() { |
| 7233 List<List<int>> b; |
| 7234 b[0][0] = 'hi'; |
| 7235 }'''); |
| 7000 resolve(source); | 7236 resolve(source); |
| 7001 assertErrors(source, [StaticTypeWarningCode.INVALID_ASSIGNMENT]); | 7237 assertErrors(source, [StaticTypeWarningCode.INVALID_ASSIGNMENT]); |
| 7002 verify([source]); | 7238 verify([source]); |
| 7003 } | 7239 } |
| 7004 | 7240 |
| 7005 void test_indirectOperatorThroughCall() { | 7241 void test_indirectOperatorThroughCall() { |
| 7006 Source source = addSource(EngineTestCase.createSource([ | 7242 Source source = addSource(r''' |
| 7007 "class A {", | 7243 class A { |
| 7008 " B call() { return new B(); }", | 7244 B call() { return new B(); } |
| 7009 "}", | 7245 } |
| 7010 "", | 7246 |
| 7011 "class B {", | 7247 class B { |
| 7012 " int operator [](int i) { return i; }", | 7248 int operator [](int i) { return i; } |
| 7013 "}", | 7249 } |
| 7014 "", | 7250 |
| 7015 "A f = new A();", | 7251 A f = new A(); |
| 7016 "", | 7252 |
| 7017 "g(int x) {}", | 7253 g(int x) {} |
| 7018 "", | 7254 |
| 7019 "main() {", | 7255 main() { |
| 7020 " g(f()[0]);", | 7256 g(f()[0]); |
| 7021 "}"])); | 7257 }'''); |
| 7022 resolve(source); | 7258 resolve(source); |
| 7023 assertNoErrors(source); | 7259 assertNoErrors(source); |
| 7024 verify([source]); | 7260 verify([source]); |
| 7025 } | 7261 } |
| 7026 | 7262 |
| 7027 void test_invoke_dynamicThroughGetter() { | 7263 void test_invoke_dynamicThroughGetter() { |
| 7028 Source source = addSource(EngineTestCase.createSource([ | 7264 Source source = addSource(r''' |
| 7029 "class A {", | 7265 class A { |
| 7030 " List get X => [() => 0];", | 7266 List get X => [() => 0]; |
| 7031 " m(A a) {", | 7267 m(A a) { |
| 7032 " X.last;", | 7268 X.last; |
| 7033 " }", | 7269 } |
| 7034 "}"])); | 7270 }'''); |
| 7035 resolve(source); | 7271 resolve(source); |
| 7036 assertNoErrors(source); | 7272 assertNoErrors(source); |
| 7037 verify([source]); | 7273 verify([source]); |
| 7038 } | 7274 } |
| 7039 | 7275 |
| 7040 void test_isValidMixin_badSuperclass() { | 7276 void test_isValidMixin_badSuperclass() { |
| 7041 Source source = addSource(EngineTestCase.createSource(["class A extends B {}
", "class B {}"])); | 7277 Source source = addSource(r''' |
| 7278 class A extends B {} |
| 7279 class B {}'''); |
| 7042 LibraryElement library = resolve(source); | 7280 LibraryElement library = resolve(source); |
| 7043 JUnitTestCase.assertNotNull(library); | 7281 JUnitTestCase.assertNotNull(library); |
| 7044 CompilationUnitElement unit = library.definingCompilationUnit; | 7282 CompilationUnitElement unit = library.definingCompilationUnit; |
| 7045 JUnitTestCase.assertNotNull(unit); | 7283 JUnitTestCase.assertNotNull(unit); |
| 7046 List<ClassElement> classes = unit.types; | 7284 List<ClassElement> classes = unit.types; |
| 7047 EngineTestCase.assertLength(2, classes); | 7285 EngineTestCase.assertLength(2, classes); |
| 7048 JUnitTestCase.assertFalse(classes[0].isValidMixin); | 7286 JUnitTestCase.assertFalse(classes[0].isValidMixin); |
| 7049 assertNoErrors(source); | 7287 assertNoErrors(source); |
| 7050 verify([source]); | 7288 verify([source]); |
| 7051 } | 7289 } |
| 7052 | 7290 |
| 7053 void test_isValidMixin_constructor() { | 7291 void test_isValidMixin_constructor() { |
| 7054 Source source = addSource(EngineTestCase.createSource(["class A {", " A() {
}", "}"])); | 7292 Source source = addSource(r''' |
| 7293 class A { |
| 7294 A() {} |
| 7295 }'''); |
| 7055 LibraryElement library = resolve(source); | 7296 LibraryElement library = resolve(source); |
| 7056 JUnitTestCase.assertNotNull(library); | 7297 JUnitTestCase.assertNotNull(library); |
| 7057 CompilationUnitElement unit = library.definingCompilationUnit; | 7298 CompilationUnitElement unit = library.definingCompilationUnit; |
| 7058 JUnitTestCase.assertNotNull(unit); | 7299 JUnitTestCase.assertNotNull(unit); |
| 7059 List<ClassElement> classes = unit.types; | 7300 List<ClassElement> classes = unit.types; |
| 7060 EngineTestCase.assertLength(1, classes); | 7301 EngineTestCase.assertLength(1, classes); |
| 7061 JUnitTestCase.assertFalse(classes[0].isValidMixin); | 7302 JUnitTestCase.assertFalse(classes[0].isValidMixin); |
| 7062 assertNoErrors(source); | 7303 assertNoErrors(source); |
| 7063 verify([source]); | 7304 verify([source]); |
| 7064 } | 7305 } |
| 7065 | 7306 |
| 7066 void test_isValidMixin_super() { | 7307 void test_isValidMixin_super() { |
| 7067 Source source = addSource(EngineTestCase.createSource([ | 7308 Source source = addSource(r''' |
| 7068 "class A {", | 7309 class A { |
| 7069 " toString() {", | 7310 toString() { |
| 7070 " return super.toString();", | 7311 return super.toString(); |
| 7071 " }", | 7312 } |
| 7072 "}"])); | 7313 }'''); |
| 7073 LibraryElement library = resolve(source); | 7314 LibraryElement library = resolve(source); |
| 7074 JUnitTestCase.assertNotNull(library); | 7315 JUnitTestCase.assertNotNull(library); |
| 7075 CompilationUnitElement unit = library.definingCompilationUnit; | 7316 CompilationUnitElement unit = library.definingCompilationUnit; |
| 7076 JUnitTestCase.assertNotNull(unit); | 7317 JUnitTestCase.assertNotNull(unit); |
| 7077 List<ClassElement> classes = unit.types; | 7318 List<ClassElement> classes = unit.types; |
| 7078 EngineTestCase.assertLength(1, classes); | 7319 EngineTestCase.assertLength(1, classes); |
| 7079 JUnitTestCase.assertFalse(classes[0].isValidMixin); | 7320 JUnitTestCase.assertFalse(classes[0].isValidMixin); |
| 7080 assertNoErrors(source); | 7321 assertNoErrors(source); |
| 7081 verify([source]); | 7322 verify([source]); |
| 7082 } | 7323 } |
| 7083 | 7324 |
| 7084 void test_isValidMixin_valid() { | 7325 void test_isValidMixin_valid() { |
| 7085 Source source = addSource(EngineTestCase.createSource(["class A {}"])); | 7326 Source source = addSource("class A {}"); |
| 7086 LibraryElement library = resolve(source); | 7327 LibraryElement library = resolve(source); |
| 7087 JUnitTestCase.assertNotNull(library); | 7328 JUnitTestCase.assertNotNull(library); |
| 7088 CompilationUnitElement unit = library.definingCompilationUnit; | 7329 CompilationUnitElement unit = library.definingCompilationUnit; |
| 7089 JUnitTestCase.assertNotNull(unit); | 7330 JUnitTestCase.assertNotNull(unit); |
| 7090 List<ClassElement> classes = unit.types; | 7331 List<ClassElement> classes = unit.types; |
| 7091 EngineTestCase.assertLength(1, classes); | 7332 EngineTestCase.assertLength(1, classes); |
| 7092 JUnitTestCase.assertTrue(classes[0].isValidMixin); | 7333 JUnitTestCase.assertTrue(classes[0].isValidMixin); |
| 7093 assertNoErrors(source); | 7334 assertNoErrors(source); |
| 7094 verify([source]); | 7335 verify([source]); |
| 7095 } | 7336 } |
| 7096 | 7337 |
| 7097 void test_labels_switch() { | 7338 void test_labels_switch() { |
| 7098 Source source = addSource(EngineTestCase.createSource([ | 7339 Source source = addSource(r''' |
| 7099 "void doSwitch(int target) {", | 7340 void doSwitch(int target) { |
| 7100 " switch (target) {", | 7341 switch (target) { |
| 7101 " l0: case 0:", | 7342 l0: case 0: |
| 7102 " continue l1;", | 7343 continue l1; |
| 7103 " l1: case 1:", | 7344 l1: case 1: |
| 7104 " continue l0;", | 7345 continue l0; |
| 7105 " default:", | 7346 default: |
| 7106 " continue l1;", | 7347 continue l1; |
| 7107 " }", | 7348 } |
| 7108 "}"])); | 7349 }'''); |
| 7109 LibraryElement library = resolve(source); | 7350 LibraryElement library = resolve(source); |
| 7110 JUnitTestCase.assertNotNull(library); | 7351 JUnitTestCase.assertNotNull(library); |
| 7111 assertNoErrors(source); | 7352 assertNoErrors(source); |
| 7112 verify([source]); | 7353 verify([source]); |
| 7113 } | 7354 } |
| 7114 | 7355 |
| 7115 void test_localVariable_types_invoked() { | 7356 void test_localVariable_types_invoked() { |
| 7116 Source source = addSource(EngineTestCase.createSource([ | 7357 Source source = addSource(r''' |
| 7117 "const A = null;", | 7358 const A = null; |
| 7118 "main() {", | 7359 main() { |
| 7119 " var myVar = (int p) => 'foo';", | 7360 var myVar = (int p) => 'foo'; |
| 7120 " myVar(42);", | 7361 myVar(42); |
| 7121 "}"])); | 7362 }'''); |
| 7122 LibraryElement library = resolve(source); | 7363 LibraryElement library = resolve(source); |
| 7123 JUnitTestCase.assertNotNull(library); | 7364 JUnitTestCase.assertNotNull(library); |
| 7124 CompilationUnit unit = analysisContext.getResolvedCompilationUnit(source, li
brary); | 7365 CompilationUnit unit = analysisContext.getResolvedCompilationUnit(source, li
brary); |
| 7125 JUnitTestCase.assertNotNull(unit); | 7366 JUnitTestCase.assertNotNull(unit); |
| 7126 List<bool> found = [false]; | 7367 List<bool> found = [false]; |
| 7127 List<CaughtException> thrownException = new List<CaughtException>(1); | 7368 List<CaughtException> thrownException = new List<CaughtException>(1); |
| 7128 unit.accept(new RecursiveAstVisitor_SimpleResolverTest_test_localVariable_ty
pes_invoked(this, found, thrownException)); | 7369 unit.accept(new RecursiveAstVisitor_SimpleResolverTest_test_localVariable_ty
pes_invoked(this, found, thrownException)); |
| 7129 if (thrownException[0] != null) { | 7370 if (thrownException[0] != null) { |
| 7130 throw new AnalysisException("Exception", new CaughtException(thrownExcepti
on[0], null)); | 7371 throw new AnalysisException("Exception", new CaughtException(thrownExcepti
on[0], null)); |
| 7131 } | 7372 } |
| 7132 JUnitTestCase.assertTrue(found[0]); | 7373 JUnitTestCase.assertTrue(found[0]); |
| 7133 } | 7374 } |
| 7134 | 7375 |
| 7135 void test_metadata_class() { | 7376 void test_metadata_class() { |
| 7136 Source source = addSource(EngineTestCase.createSource(["const A = null;", "@
A class C<A> {}"])); | 7377 Source source = addSource(r''' |
| 7378 const A = null; |
| 7379 @A class C<A> {}'''); |
| 7137 LibraryElement library = resolve(source); | 7380 LibraryElement library = resolve(source); |
| 7138 JUnitTestCase.assertNotNull(library); | 7381 JUnitTestCase.assertNotNull(library); |
| 7139 CompilationUnitElement unitElement = library.definingCompilationUnit; | 7382 CompilationUnitElement unitElement = library.definingCompilationUnit; |
| 7140 JUnitTestCase.assertNotNull(unitElement); | 7383 JUnitTestCase.assertNotNull(unitElement); |
| 7141 List<ClassElement> classes = unitElement.types; | 7384 List<ClassElement> classes = unitElement.types; |
| 7142 EngineTestCase.assertLength(1, classes); | 7385 EngineTestCase.assertLength(1, classes); |
| 7143 List<ElementAnnotation> annotations = classes[0].metadata; | 7386 List<ElementAnnotation> annotations = classes[0].metadata; |
| 7144 EngineTestCase.assertLength(1, annotations); | 7387 EngineTestCase.assertLength(1, annotations); |
| 7145 assertNoErrors(source); | 7388 assertNoErrors(source); |
| 7146 verify([source]); | 7389 verify([source]); |
| 7147 CompilationUnit unit = resolveCompilationUnit(source, library); | 7390 CompilationUnit unit = resolveCompilationUnit(source, library); |
| 7148 NodeList<CompilationUnitMember> declarations = unit.declarations; | 7391 NodeList<CompilationUnitMember> declarations = unit.declarations; |
| 7149 EngineTestCase.assertSizeOfList(2, declarations); | 7392 EngineTestCase.assertSizeOfList(2, declarations); |
| 7150 Element expectedElement = (declarations[0] as TopLevelVariableDeclaration).v
ariables.variables[0].name.staticElement; | 7393 Element expectedElement = (declarations[0] as TopLevelVariableDeclaration).v
ariables.variables[0].name.staticElement; |
| 7151 EngineTestCase.assertInstanceOf((obj) => obj is PropertyInducingElement, Pro
pertyInducingElement, expectedElement); | 7394 EngineTestCase.assertInstanceOf((obj) => obj is PropertyInducingElement, Pro
pertyInducingElement, expectedElement); |
| 7152 expectedElement = (expectedElement as PropertyInducingElement).getter; | 7395 expectedElement = (expectedElement as PropertyInducingElement).getter; |
| 7153 Element actualElement = (declarations[1] as ClassDeclaration).metadata[0].na
me.staticElement; | 7396 Element actualElement = (declarations[1] as ClassDeclaration).metadata[0].na
me.staticElement; |
| 7154 JUnitTestCase.assertSame(expectedElement, actualElement); | 7397 JUnitTestCase.assertSame(expectedElement, actualElement); |
| 7155 } | 7398 } |
| 7156 | 7399 |
| 7157 void test_metadata_field() { | 7400 void test_metadata_field() { |
| 7158 Source source = addSource(EngineTestCase.createSource(["const A = null;", "c
lass C {", " @A int f;", "}"])); | 7401 Source source = addSource(r''' |
| 7402 const A = null; |
| 7403 class C { |
| 7404 @A int f; |
| 7405 }'''); |
| 7159 LibraryElement library = resolve(source); | 7406 LibraryElement library = resolve(source); |
| 7160 JUnitTestCase.assertNotNull(library); | 7407 JUnitTestCase.assertNotNull(library); |
| 7161 CompilationUnitElement unit = library.definingCompilationUnit; | 7408 CompilationUnitElement unit = library.definingCompilationUnit; |
| 7162 JUnitTestCase.assertNotNull(unit); | 7409 JUnitTestCase.assertNotNull(unit); |
| 7163 List<ClassElement> classes = unit.types; | 7410 List<ClassElement> classes = unit.types; |
| 7164 EngineTestCase.assertLength(1, classes); | 7411 EngineTestCase.assertLength(1, classes); |
| 7165 FieldElement field = classes[0].fields[0]; | 7412 FieldElement field = classes[0].fields[0]; |
| 7166 List<ElementAnnotation> annotations = field.metadata; | 7413 List<ElementAnnotation> annotations = field.metadata; |
| 7167 EngineTestCase.assertLength(1, annotations); | 7414 EngineTestCase.assertLength(1, annotations); |
| 7168 assertNoErrors(source); | 7415 assertNoErrors(source); |
| 7169 verify([source]); | 7416 verify([source]); |
| 7170 } | 7417 } |
| 7171 | 7418 |
| 7172 void test_metadata_fieldFormalParameter() { | 7419 void test_metadata_fieldFormalParameter() { |
| 7173 Source source = addSource(EngineTestCase.createSource([ | 7420 Source source = addSource(r''' |
| 7174 "const A = null;", | 7421 const A = null; |
| 7175 "class C {", | 7422 class C { |
| 7176 " int f;", | 7423 int f; |
| 7177 " C(@A this.f);", | 7424 C(@A this.f); |
| 7178 "}"])); | 7425 }'''); |
| 7179 LibraryElement library = resolve(source); | 7426 LibraryElement library = resolve(source); |
| 7180 JUnitTestCase.assertNotNull(library); | 7427 JUnitTestCase.assertNotNull(library); |
| 7181 CompilationUnitElement unit = library.definingCompilationUnit; | 7428 CompilationUnitElement unit = library.definingCompilationUnit; |
| 7182 JUnitTestCase.assertNotNull(unit); | 7429 JUnitTestCase.assertNotNull(unit); |
| 7183 List<ClassElement> classes = unit.types; | 7430 List<ClassElement> classes = unit.types; |
| 7184 EngineTestCase.assertLength(1, classes); | 7431 EngineTestCase.assertLength(1, classes); |
| 7185 List<ConstructorElement> constructors = classes[0].constructors; | 7432 List<ConstructorElement> constructors = classes[0].constructors; |
| 7186 EngineTestCase.assertLength(1, constructors); | 7433 EngineTestCase.assertLength(1, constructors); |
| 7187 List<ParameterElement> parameters = constructors[0].parameters; | 7434 List<ParameterElement> parameters = constructors[0].parameters; |
| 7188 EngineTestCase.assertLength(1, parameters); | 7435 EngineTestCase.assertLength(1, parameters); |
| 7189 List<ElementAnnotation> annotations = parameters[0].metadata; | 7436 List<ElementAnnotation> annotations = parameters[0].metadata; |
| 7190 EngineTestCase.assertLength(1, annotations); | 7437 EngineTestCase.assertLength(1, annotations); |
| 7191 assertNoErrors(source); | 7438 assertNoErrors(source); |
| 7192 verify([source]); | 7439 verify([source]); |
| 7193 } | 7440 } |
| 7194 | 7441 |
| 7195 void test_metadata_function() { | 7442 void test_metadata_function() { |
| 7196 Source source = addSource(EngineTestCase.createSource(["const A = null;", "@
A f() {}"])); | 7443 Source source = addSource(r''' |
| 7444 const A = null; |
| 7445 @A f() {}'''); |
| 7197 LibraryElement library = resolve(source); | 7446 LibraryElement library = resolve(source); |
| 7198 JUnitTestCase.assertNotNull(library); | 7447 JUnitTestCase.assertNotNull(library); |
| 7199 CompilationUnitElement unit = library.definingCompilationUnit; | 7448 CompilationUnitElement unit = library.definingCompilationUnit; |
| 7200 JUnitTestCase.assertNotNull(unit); | 7449 JUnitTestCase.assertNotNull(unit); |
| 7201 List<FunctionElement> functions = unit.functions; | 7450 List<FunctionElement> functions = unit.functions; |
| 7202 EngineTestCase.assertLength(1, functions); | 7451 EngineTestCase.assertLength(1, functions); |
| 7203 List<ElementAnnotation> annotations = functions[0].metadata; | 7452 List<ElementAnnotation> annotations = functions[0].metadata; |
| 7204 EngineTestCase.assertLength(1, annotations); | 7453 EngineTestCase.assertLength(1, annotations); |
| 7205 assertNoErrors(source); | 7454 assertNoErrors(source); |
| 7206 verify([source]); | 7455 verify([source]); |
| 7207 } | 7456 } |
| 7208 | 7457 |
| 7209 void test_metadata_functionTypedParameter() { | 7458 void test_metadata_functionTypedParameter() { |
| 7210 Source source = addSource(EngineTestCase.createSource(["const A = null;", "f
(@A int p(int x)) {}"])); | 7459 Source source = addSource(r''' |
| 7460 const A = null; |
| 7461 f(@A int p(int x)) {}'''); |
| 7211 LibraryElement library = resolve(source); | 7462 LibraryElement library = resolve(source); |
| 7212 JUnitTestCase.assertNotNull(library); | 7463 JUnitTestCase.assertNotNull(library); |
| 7213 CompilationUnitElement unit = library.definingCompilationUnit; | 7464 CompilationUnitElement unit = library.definingCompilationUnit; |
| 7214 JUnitTestCase.assertNotNull(unit); | 7465 JUnitTestCase.assertNotNull(unit); |
| 7215 List<FunctionElement> functions = unit.functions; | 7466 List<FunctionElement> functions = unit.functions; |
| 7216 EngineTestCase.assertLength(1, functions); | 7467 EngineTestCase.assertLength(1, functions); |
| 7217 List<ParameterElement> parameters = functions[0].parameters; | 7468 List<ParameterElement> parameters = functions[0].parameters; |
| 7218 EngineTestCase.assertLength(1, parameters); | 7469 EngineTestCase.assertLength(1, parameters); |
| 7219 List<ElementAnnotation> annotations1 = parameters[0].metadata; | 7470 List<ElementAnnotation> annotations1 = parameters[0].metadata; |
| 7220 EngineTestCase.assertLength(1, annotations1); | 7471 EngineTestCase.assertLength(1, annotations1); |
| 7221 assertNoErrors(source); | 7472 assertNoErrors(source); |
| 7222 verify([source]); | 7473 verify([source]); |
| 7223 } | 7474 } |
| 7224 | 7475 |
| 7225 void test_metadata_libraryDirective() { | 7476 void test_metadata_libraryDirective() { |
| 7226 Source source = addSource(EngineTestCase.createSource(["@A library lib;", "c
onst A = null;"])); | 7477 Source source = addSource(r''' |
| 7478 @A library lib; |
| 7479 const A = null;'''); |
| 7227 LibraryElement library = resolve(source); | 7480 LibraryElement library = resolve(source); |
| 7228 JUnitTestCase.assertNotNull(library); | 7481 JUnitTestCase.assertNotNull(library); |
| 7229 List<ElementAnnotation> annotations = library.metadata; | 7482 List<ElementAnnotation> annotations = library.metadata; |
| 7230 EngineTestCase.assertLength(1, annotations); | 7483 EngineTestCase.assertLength(1, annotations); |
| 7231 assertNoErrors(source); | 7484 assertNoErrors(source); |
| 7232 verify([source]); | 7485 verify([source]); |
| 7233 } | 7486 } |
| 7234 | 7487 |
| 7235 void test_metadata_method() { | 7488 void test_metadata_method() { |
| 7236 Source source = addSource(EngineTestCase.createSource(["const A = null;", "c
lass C {", " @A void m() {}", "}"])); | 7489 Source source = addSource(r''' |
| 7490 const A = null; |
| 7491 class C { |
| 7492 @A void m() {} |
| 7493 }'''); |
| 7237 LibraryElement library = resolve(source); | 7494 LibraryElement library = resolve(source); |
| 7238 JUnitTestCase.assertNotNull(library); | 7495 JUnitTestCase.assertNotNull(library); |
| 7239 CompilationUnitElement unit = library.definingCompilationUnit; | 7496 CompilationUnitElement unit = library.definingCompilationUnit; |
| 7240 JUnitTestCase.assertNotNull(unit); | 7497 JUnitTestCase.assertNotNull(unit); |
| 7241 List<ClassElement> classes = unit.types; | 7498 List<ClassElement> classes = unit.types; |
| 7242 EngineTestCase.assertLength(1, classes); | 7499 EngineTestCase.assertLength(1, classes); |
| 7243 MethodElement method = classes[0].methods[0]; | 7500 MethodElement method = classes[0].methods[0]; |
| 7244 List<ElementAnnotation> annotations = method.metadata; | 7501 List<ElementAnnotation> annotations = method.metadata; |
| 7245 EngineTestCase.assertLength(1, annotations); | 7502 EngineTestCase.assertLength(1, annotations); |
| 7246 assertNoErrors(source); | 7503 assertNoErrors(source); |
| 7247 verify([source]); | 7504 verify([source]); |
| 7248 } | 7505 } |
| 7249 | 7506 |
| 7250 void test_metadata_namedParameter() { | 7507 void test_metadata_namedParameter() { |
| 7251 Source source = addSource(EngineTestCase.createSource(["const A = null;", "f
({@A int p : 0}) {}"])); | 7508 Source source = addSource(r''' |
| 7509 const A = null; |
| 7510 f({@A int p : 0}) {}'''); |
| 7252 LibraryElement library = resolve(source); | 7511 LibraryElement library = resolve(source); |
| 7253 JUnitTestCase.assertNotNull(library); | 7512 JUnitTestCase.assertNotNull(library); |
| 7254 CompilationUnitElement unit = library.definingCompilationUnit; | 7513 CompilationUnitElement unit = library.definingCompilationUnit; |
| 7255 JUnitTestCase.assertNotNull(unit); | 7514 JUnitTestCase.assertNotNull(unit); |
| 7256 List<FunctionElement> functions = unit.functions; | 7515 List<FunctionElement> functions = unit.functions; |
| 7257 EngineTestCase.assertLength(1, functions); | 7516 EngineTestCase.assertLength(1, functions); |
| 7258 List<ParameterElement> parameters = functions[0].parameters; | 7517 List<ParameterElement> parameters = functions[0].parameters; |
| 7259 EngineTestCase.assertLength(1, parameters); | 7518 EngineTestCase.assertLength(1, parameters); |
| 7260 List<ElementAnnotation> annotations1 = parameters[0].metadata; | 7519 List<ElementAnnotation> annotations1 = parameters[0].metadata; |
| 7261 EngineTestCase.assertLength(1, annotations1); | 7520 EngineTestCase.assertLength(1, annotations1); |
| 7262 assertNoErrors(source); | 7521 assertNoErrors(source); |
| 7263 verify([source]); | 7522 verify([source]); |
| 7264 } | 7523 } |
| 7265 | 7524 |
| 7266 void test_metadata_positionalParameter() { | 7525 void test_metadata_positionalParameter() { |
| 7267 Source source = addSource(EngineTestCase.createSource(["const A = null;", "f
([@A int p = 0]) {}"])); | 7526 Source source = addSource(r''' |
| 7527 const A = null; |
| 7528 f([@A int p = 0]) {}'''); |
| 7268 LibraryElement library = resolve(source); | 7529 LibraryElement library = resolve(source); |
| 7269 JUnitTestCase.assertNotNull(library); | 7530 JUnitTestCase.assertNotNull(library); |
| 7270 CompilationUnitElement unit = library.definingCompilationUnit; | 7531 CompilationUnitElement unit = library.definingCompilationUnit; |
| 7271 JUnitTestCase.assertNotNull(unit); | 7532 JUnitTestCase.assertNotNull(unit); |
| 7272 List<FunctionElement> functions = unit.functions; | 7533 List<FunctionElement> functions = unit.functions; |
| 7273 EngineTestCase.assertLength(1, functions); | 7534 EngineTestCase.assertLength(1, functions); |
| 7274 List<ParameterElement> parameters = functions[0].parameters; | 7535 List<ParameterElement> parameters = functions[0].parameters; |
| 7275 EngineTestCase.assertLength(1, parameters); | 7536 EngineTestCase.assertLength(1, parameters); |
| 7276 List<ElementAnnotation> annotations1 = parameters[0].metadata; | 7537 List<ElementAnnotation> annotations1 = parameters[0].metadata; |
| 7277 EngineTestCase.assertLength(1, annotations1); | 7538 EngineTestCase.assertLength(1, annotations1); |
| 7278 assertNoErrors(source); | 7539 assertNoErrors(source); |
| 7279 verify([source]); | 7540 verify([source]); |
| 7280 } | 7541 } |
| 7281 | 7542 |
| 7282 void test_metadata_simpleParameter() { | 7543 void test_metadata_simpleParameter() { |
| 7283 Source source = addSource(EngineTestCase.createSource(["const A = null;", "f
(@A p1, @A int p2) {}"])); | 7544 Source source = addSource(r''' |
| 7545 const A = null; |
| 7546 f(@A p1, @A int p2) {}'''); |
| 7284 LibraryElement library = resolve(source); | 7547 LibraryElement library = resolve(source); |
| 7285 JUnitTestCase.assertNotNull(library); | 7548 JUnitTestCase.assertNotNull(library); |
| 7286 CompilationUnitElement unit = library.definingCompilationUnit; | 7549 CompilationUnitElement unit = library.definingCompilationUnit; |
| 7287 JUnitTestCase.assertNotNull(unit); | 7550 JUnitTestCase.assertNotNull(unit); |
| 7288 List<FunctionElement> functions = unit.functions; | 7551 List<FunctionElement> functions = unit.functions; |
| 7289 EngineTestCase.assertLength(1, functions); | 7552 EngineTestCase.assertLength(1, functions); |
| 7290 List<ParameterElement> parameters = functions[0].parameters; | 7553 List<ParameterElement> parameters = functions[0].parameters; |
| 7291 EngineTestCase.assertLength(2, parameters); | 7554 EngineTestCase.assertLength(2, parameters); |
| 7292 List<ElementAnnotation> annotations1 = parameters[0].metadata; | 7555 List<ElementAnnotation> annotations1 = parameters[0].metadata; |
| 7293 EngineTestCase.assertLength(1, annotations1); | 7556 EngineTestCase.assertLength(1, annotations1); |
| 7294 List<ElementAnnotation> annotations2 = parameters[1].metadata; | 7557 List<ElementAnnotation> annotations2 = parameters[1].metadata; |
| 7295 EngineTestCase.assertLength(1, annotations2); | 7558 EngineTestCase.assertLength(1, annotations2); |
| 7296 assertNoErrors(source); | 7559 assertNoErrors(source); |
| 7297 verify([source]); | 7560 verify([source]); |
| 7298 } | 7561 } |
| 7299 | 7562 |
| 7300 void test_metadata_typedef() { | 7563 void test_metadata_typedef() { |
| 7301 Source source = addSource(EngineTestCase.createSource(["const A = null;", "@
A typedef F<A>();"])); | 7564 Source source = addSource(r''' |
| 7565 const A = null; |
| 7566 @A typedef F<A>();'''); |
| 7302 LibraryElement library = resolve(source); | 7567 LibraryElement library = resolve(source); |
| 7303 JUnitTestCase.assertNotNull(library); | 7568 JUnitTestCase.assertNotNull(library); |
| 7304 CompilationUnitElement unitElement = library.definingCompilationUnit; | 7569 CompilationUnitElement unitElement = library.definingCompilationUnit; |
| 7305 JUnitTestCase.assertNotNull(unitElement); | 7570 JUnitTestCase.assertNotNull(unitElement); |
| 7306 List<FunctionTypeAliasElement> aliases = unitElement.functionTypeAliases; | 7571 List<FunctionTypeAliasElement> aliases = unitElement.functionTypeAliases; |
| 7307 EngineTestCase.assertLength(1, aliases); | 7572 EngineTestCase.assertLength(1, aliases); |
| 7308 List<ElementAnnotation> annotations = aliases[0].metadata; | 7573 List<ElementAnnotation> annotations = aliases[0].metadata; |
| 7309 EngineTestCase.assertLength(1, annotations); | 7574 EngineTestCase.assertLength(1, annotations); |
| 7310 assertNoErrors(source); | 7575 assertNoErrors(source); |
| 7311 verify([source]); | 7576 verify([source]); |
| 7312 CompilationUnit unit = resolveCompilationUnit(source, library); | 7577 CompilationUnit unit = resolveCompilationUnit(source, library); |
| 7313 NodeList<CompilationUnitMember> declarations = unit.declarations; | 7578 NodeList<CompilationUnitMember> declarations = unit.declarations; |
| 7314 EngineTestCase.assertSizeOfList(2, declarations); | 7579 EngineTestCase.assertSizeOfList(2, declarations); |
| 7315 Element expectedElement = (declarations[0] as TopLevelVariableDeclaration).v
ariables.variables[0].name.staticElement; | 7580 Element expectedElement = (declarations[0] as TopLevelVariableDeclaration).v
ariables.variables[0].name.staticElement; |
| 7316 EngineTestCase.assertInstanceOf((obj) => obj is PropertyInducingElement, Pro
pertyInducingElement, expectedElement); | 7581 EngineTestCase.assertInstanceOf((obj) => obj is PropertyInducingElement, Pro
pertyInducingElement, expectedElement); |
| 7317 expectedElement = (expectedElement as PropertyInducingElement).getter; | 7582 expectedElement = (expectedElement as PropertyInducingElement).getter; |
| 7318 Element actualElement = (declarations[1] as FunctionTypeAlias).metadata[0].n
ame.staticElement; | 7583 Element actualElement = (declarations[1] as FunctionTypeAlias).metadata[0].n
ame.staticElement; |
| 7319 JUnitTestCase.assertSame(expectedElement, actualElement); | 7584 JUnitTestCase.assertSame(expectedElement, actualElement); |
| 7320 } | 7585 } |
| 7321 | 7586 |
| 7322 void test_method_fromMixin() { | 7587 void test_method_fromMixin() { |
| 7323 Source source = addSource(EngineTestCase.createSource([ | 7588 Source source = addSource(r''' |
| 7324 "class B {", | 7589 class B { |
| 7325 " bar() => 1;", | 7590 bar() => 1; |
| 7326 "}", | 7591 } |
| 7327 "class A {", | 7592 class A { |
| 7328 " foo() => 2;", | 7593 foo() => 2; |
| 7329 "}", | 7594 } |
| 7330 "", | 7595 |
| 7331 "class C extends B with A {", | 7596 class C extends B with A { |
| 7332 " bar() => super.bar();", | 7597 bar() => super.bar(); |
| 7333 " foo() => super.foo();", | 7598 foo() => super.foo(); |
| 7334 "}"])); | 7599 }'''); |
| 7335 resolve(source); | 7600 resolve(source); |
| 7336 assertNoErrors(source); | 7601 assertNoErrors(source); |
| 7337 verify([source]); | 7602 verify([source]); |
| 7338 } | 7603 } |
| 7339 | 7604 |
| 7340 void test_method_fromSuperclassMixin() { | 7605 void test_method_fromSuperclassMixin() { |
| 7341 Source source = addSource(EngineTestCase.createSource([ | 7606 Source source = addSource(r''' |
| 7342 "class A {", | 7607 class A { |
| 7343 " void m1() {}", | 7608 void m1() {} |
| 7344 "}", | 7609 } |
| 7345 "class B extends Object with A {", | 7610 class B extends Object with A { |
| 7346 "}", | 7611 } |
| 7347 "class C extends B {", | 7612 class C extends B { |
| 7348 "}", | 7613 } |
| 7349 "f(C c) {", | 7614 f(C c) { |
| 7350 " c.m1();", | 7615 c.m1(); |
| 7351 "}"])); | 7616 }'''); |
| 7352 resolve(source); | 7617 resolve(source); |
| 7353 assertNoErrors(source); | 7618 assertNoErrors(source); |
| 7354 verify([source]); | 7619 verify([source]); |
| 7355 } | 7620 } |
| 7356 | 7621 |
| 7357 void test_methodCascades() { | 7622 void test_methodCascades() { |
| 7358 Source source = addSource(EngineTestCase.createSource([ | 7623 Source source = addSource(r''' |
| 7359 "class A {", | 7624 class A { |
| 7360 " void m1() {}", | 7625 void m1() {} |
| 7361 " void m2() {}", | 7626 void m2() {} |
| 7362 " void m() {", | 7627 void m() { |
| 7363 " A a = new A();", | 7628 A a = new A(); |
| 7364 " a..m1()", | 7629 a..m1() |
| 7365 " ..m2();", | 7630 ..m2(); |
| 7366 " }", | 7631 } |
| 7367 "}"])); | 7632 }'''); |
| 7368 resolve(source); | 7633 resolve(source); |
| 7369 assertNoErrors(source); | 7634 assertNoErrors(source); |
| 7370 verify([source]); | 7635 verify([source]); |
| 7371 } | 7636 } |
| 7372 | 7637 |
| 7373 void test_methodCascades_withSetter() { | 7638 void test_methodCascades_withSetter() { |
| 7374 Source source = addSource(EngineTestCase.createSource([ | 7639 Source source = addSource(r''' |
| 7375 "class A {", | 7640 class A { |
| 7376 " String name;", | 7641 String name; |
| 7377 " void m1() {}", | 7642 void m1() {} |
| 7378 " void m2() {}", | 7643 void m2() {} |
| 7379 " void m() {", | 7644 void m() { |
| 7380 " A a = new A();", | 7645 A a = new A(); |
| 7381 " a..m1()", | 7646 a..m1() |
| 7382 " ..name = 'name'", | 7647 ..name = 'name' |
| 7383 " ..m2();", | 7648 ..m2(); |
| 7384 " }", | 7649 } |
| 7385 "}"])); | 7650 }'''); |
| 7386 resolve(source); | 7651 resolve(source); |
| 7387 // failing with error code: INVOCATION_OF_NON_FUNCTION | 7652 // failing with error code: INVOCATION_OF_NON_FUNCTION |
| 7388 assertNoErrors(source); | 7653 assertNoErrors(source); |
| 7389 verify([source]); | 7654 verify([source]); |
| 7390 } | 7655 } |
| 7391 | 7656 |
| 7392 void test_resolveAgainstNull() { | 7657 void test_resolveAgainstNull() { |
| 7393 Source source = addSource(EngineTestCase.createSource(["f(var p) {", " retu
rn null == p;", "}"])); | 7658 Source source = addSource(r''' |
| 7659 f(var p) { |
| 7660 return null == p; |
| 7661 }'''); |
| 7394 resolve(source); | 7662 resolve(source); |
| 7395 assertNoErrors(source); | 7663 assertNoErrors(source); |
| 7396 } | 7664 } |
| 7397 | 7665 |
| 7398 void test_setter_inherited() { | 7666 void test_setter_inherited() { |
| 7399 Source source = addSource(EngineTestCase.createSource([ | 7667 Source source = addSource(r''' |
| 7400 "class A {", | 7668 class A { |
| 7401 " int get x => 0;", | 7669 int get x => 0; |
| 7402 " set x(int p) {}", | 7670 set x(int p) {} |
| 7403 "}", | 7671 } |
| 7404 "class B extends A {", | 7672 class B extends A { |
| 7405 " int get x => super.x == null ? 0 : super.x;", | 7673 int get x => super.x == null ? 0 : super.x; |
| 7406 " int f() => x = 1;", | 7674 int f() => x = 1; |
| 7407 "}"])); | 7675 }'''); |
| 7408 resolve(source); | 7676 resolve(source); |
| 7409 assertNoErrors(source); | 7677 assertNoErrors(source); |
| 7410 verify([source]); | 7678 verify([source]); |
| 7411 } | 7679 } |
| 7412 | 7680 |
| 7413 void test_setter_static() { | 7681 void test_setter_static() { |
| 7414 Source source = addSource(EngineTestCase.createSource(["set s(x) {", "}", ""
, "main() {", " s = 123;", "}"])); | 7682 Source source = addSource(r''' |
| 7683 set s(x) { |
| 7684 } |
| 7685 |
| 7686 main() { |
| 7687 s = 123; |
| 7688 }'''); |
| 7415 resolve(source); | 7689 resolve(source); |
| 7416 assertNoErrors(source); | 7690 assertNoErrors(source); |
| 7417 verify([source]); | 7691 verify([source]); |
| 7418 } | 7692 } |
| 7419 | 7693 |
| 7420 /** | 7694 /** |
| 7421 * Resolve the given source and verify that the arguments in a specific method
invocation were | 7695 * Resolve the given source and verify that the arguments in a specific method
invocation were |
| 7422 * correctly resolved. | 7696 * correctly resolved. |
| 7423 * | 7697 * |
| 7424 * The source is expected to be source for a compilation unit, the first decla
ration is expected | 7698 * The source is expected to be source for a compilation unit, the first decla
ration is expected |
| (...skipping 1302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8727 return "<unknown file- ASTNode is null>"; | 9001 return "<unknown file- ASTNode is null>"; |
| 8728 } | 9002 } |
| 8729 } | 9003 } |
| 8730 | 9004 |
| 8731 /** | 9005 /** |
| 8732 * The class `StrictModeTest` contains tests to ensure that the correct errors a
nd warnings | 9006 * The class `StrictModeTest` contains tests to ensure that the correct errors a
nd warnings |
| 8733 * are reported when the analysis engine is run in strict mode. | 9007 * are reported when the analysis engine is run in strict mode. |
| 8734 */ | 9008 */ |
| 8735 class StrictModeTest extends ResolverTestCase { | 9009 class StrictModeTest extends ResolverTestCase { |
| 8736 void fail_for() { | 9010 void fail_for() { |
| 8737 Source source = addSource(EngineTestCase.createSource([ | 9011 Source source = addSource(r''' |
| 8738 "int f(List<int> list) {", | 9012 int f(List<int> list) { |
| 8739 " num sum = 0;", | 9013 num sum = 0; |
| 8740 " for (num i = 0; i < list.length; i++) {", | 9014 for (num i = 0; i < list.length; i++) { |
| 8741 " sum += list[i];", | 9015 sum += list[i]; |
| 8742 " }", | 9016 } |
| 8743 "}"])); | 9017 }'''); |
| 8744 resolve(source); | 9018 resolve(source); |
| 8745 assertErrors(source, [StaticTypeWarningCode.UNDEFINED_OPERATOR]); | 9019 assertErrors(source, [StaticTypeWarningCode.UNDEFINED_OPERATOR]); |
| 8746 } | 9020 } |
| 8747 | 9021 |
| 8748 @override | 9022 @override |
| 8749 void setUp() { | 9023 void setUp() { |
| 8750 AnalysisOptionsImpl options = new AnalysisOptionsImpl(); | 9024 AnalysisOptionsImpl options = new AnalysisOptionsImpl(); |
| 8751 options.hint = false; | 9025 options.hint = false; |
| 8752 resetWithOptions(options); | 9026 resetWithOptions(options); |
| 8753 } | 9027 } |
| 8754 | 9028 |
| 8755 void test_assert_is() { | 9029 void test_assert_is() { |
| 8756 Source source = addSource(EngineTestCase.createSource([ | 9030 Source source = addSource(r''' |
| 8757 "int f(num n) {", | 9031 int f(num n) { |
| 8758 " assert (n is int);", | 9032 assert (n is int); |
| 8759 " return n & 0x0F;", | 9033 return n & 0x0F; |
| 8760 "}"])); | 9034 }'''); |
| 8761 resolve(source); | 9035 resolve(source); |
| 8762 assertErrors(source, [StaticTypeWarningCode.UNDEFINED_OPERATOR]); | 9036 assertErrors(source, [StaticTypeWarningCode.UNDEFINED_OPERATOR]); |
| 8763 } | 9037 } |
| 8764 | 9038 |
| 8765 void test_conditional_and_is() { | 9039 void test_conditional_and_is() { |
| 8766 Source source = addSource(EngineTestCase.createSource([ | 9040 Source source = addSource(r''' |
| 8767 "int f(num n) {", | 9041 int f(num n) { |
| 8768 " return (n is int && n > 0) ? n & 0x0F : 0;", | 9042 return (n is int && n > 0) ? n & 0x0F : 0; |
| 8769 "}"])); | 9043 }'''); |
| 8770 resolve(source); | 9044 resolve(source); |
| 8771 assertNoErrors(source); | 9045 assertNoErrors(source); |
| 8772 } | 9046 } |
| 8773 | 9047 |
| 8774 void test_conditional_is() { | 9048 void test_conditional_is() { |
| 8775 Source source = addSource(EngineTestCase.createSource([ | 9049 Source source = addSource(r''' |
| 8776 "int f(num n) {", | 9050 int f(num n) { |
| 8777 " return (n is int) ? n & 0x0F : 0;", | 9051 return (n is int) ? n & 0x0F : 0; |
| 8778 "}"])); | 9052 }'''); |
| 8779 resolve(source); | 9053 resolve(source); |
| 8780 assertNoErrors(source); | 9054 assertNoErrors(source); |
| 8781 } | 9055 } |
| 8782 | 9056 |
| 8783 void test_conditional_isNot() { | 9057 void test_conditional_isNot() { |
| 8784 Source source = addSource(EngineTestCase.createSource([ | 9058 Source source = addSource(r''' |
| 8785 "int f(num n) {", | 9059 int f(num n) { |
| 8786 " return (n is! int) ? 0 : n & 0x0F;", | 9060 return (n is! int) ? 0 : n & 0x0F; |
| 8787 "}"])); | 9061 }'''); |
| 8788 resolve(source); | 9062 resolve(source); |
| 8789 assertErrors(source, [StaticTypeWarningCode.UNDEFINED_OPERATOR]); | 9063 assertErrors(source, [StaticTypeWarningCode.UNDEFINED_OPERATOR]); |
| 8790 } | 9064 } |
| 8791 | 9065 |
| 8792 void test_conditional_or_is() { | 9066 void test_conditional_or_is() { |
| 8793 Source source = addSource(EngineTestCase.createSource([ | 9067 Source source = addSource(r''' |
| 8794 "int f(num n) {", | 9068 int f(num n) { |
| 8795 " return (n is! int || n < 0) ? 0 : n & 0x0F;", | 9069 return (n is! int || n < 0) ? 0 : n & 0x0F; |
| 8796 "}"])); | 9070 }'''); |
| 8797 resolve(source); | 9071 resolve(source); |
| 8798 assertErrors(source, [StaticTypeWarningCode.UNDEFINED_OPERATOR]); | 9072 assertErrors(source, [StaticTypeWarningCode.UNDEFINED_OPERATOR]); |
| 8799 } | 9073 } |
| 8800 | 9074 |
| 8801 void test_forEach() { | 9075 void test_forEach() { |
| 8802 Source source = addSource(EngineTestCase.createSource([ | 9076 Source source = addSource(r''' |
| 8803 "int f(List<int> list) {", | 9077 int f(List<int> list) { |
| 8804 " num sum = 0;", | 9078 num sum = 0; |
| 8805 " for (num n in list) {", | 9079 for (num n in list) { |
| 8806 " sum += n & 0x0F;", | 9080 sum += n & 0x0F; |
| 8807 " }", | 9081 } |
| 8808 "}"])); | 9082 }'''); |
| 8809 resolve(source); | 9083 resolve(source); |
| 8810 assertErrors(source, [StaticTypeWarningCode.UNDEFINED_OPERATOR]); | 9084 assertErrors(source, [StaticTypeWarningCode.UNDEFINED_OPERATOR]); |
| 8811 } | 9085 } |
| 8812 | 9086 |
| 8813 void test_if_and_is() { | 9087 void test_if_and_is() { |
| 8814 Source source = addSource(EngineTestCase.createSource([ | 9088 Source source = addSource(r''' |
| 8815 "int f(num n) {", | 9089 int f(num n) { |
| 8816 " if (n is int && n > 0) {", | 9090 if (n is int && n > 0) { |
| 8817 " return n & 0x0F;", | 9091 return n & 0x0F; |
| 8818 " }", | 9092 } |
| 8819 " return 0;", | 9093 return 0; |
| 8820 "}"])); | 9094 }'''); |
| 8821 resolve(source); | 9095 resolve(source); |
| 8822 assertNoErrors(source); | 9096 assertNoErrors(source); |
| 8823 } | 9097 } |
| 8824 | 9098 |
| 8825 void test_if_is() { | 9099 void test_if_is() { |
| 8826 Source source = addSource(EngineTestCase.createSource([ | 9100 Source source = addSource(r''' |
| 8827 "int f(num n) {", | 9101 int f(num n) { |
| 8828 " if (n is int) {", | 9102 if (n is int) { |
| 8829 " return n & 0x0F;", | 9103 return n & 0x0F; |
| 8830 " }", | 9104 } |
| 8831 " return 0;", | 9105 return 0; |
| 8832 "}"])); | 9106 }'''); |
| 8833 resolve(source); | 9107 resolve(source); |
| 8834 assertNoErrors(source); | 9108 assertNoErrors(source); |
| 8835 } | 9109 } |
| 8836 | 9110 |
| 8837 void test_if_isNot() { | 9111 void test_if_isNot() { |
| 8838 Source source = addSource(EngineTestCase.createSource([ | 9112 Source source = addSource(r''' |
| 8839 "int f(num n) {", | 9113 int f(num n) { |
| 8840 " if (n is! int) {", | 9114 if (n is! int) { |
| 8841 " return 0;", | 9115 return 0; |
| 8842 " } else {", | 9116 } else { |
| 8843 " return n & 0x0F;", | 9117 return n & 0x0F; |
| 8844 " }", | 9118 } |
| 8845 "}"])); | 9119 }'''); |
| 8846 resolve(source); | 9120 resolve(source); |
| 8847 assertErrors(source, [StaticTypeWarningCode.UNDEFINED_OPERATOR]); | 9121 assertErrors(source, [StaticTypeWarningCode.UNDEFINED_OPERATOR]); |
| 8848 } | 9122 } |
| 8849 | 9123 |
| 8850 void test_if_isNot_abrupt() { | 9124 void test_if_isNot_abrupt() { |
| 8851 Source source = addSource(EngineTestCase.createSource([ | 9125 Source source = addSource(r''' |
| 8852 "int f(num n) {", | 9126 int f(num n) { |
| 8853 " if (n is! int) {", | 9127 if (n is! int) { |
| 8854 " return 0;", | 9128 return 0; |
| 8855 " }", | 9129 } |
| 8856 " return n & 0x0F;", | 9130 return n & 0x0F; |
| 8857 "}"])); | 9131 }'''); |
| 8858 resolve(source); | 9132 resolve(source); |
| 8859 assertErrors(source, [StaticTypeWarningCode.UNDEFINED_OPERATOR]); | 9133 assertErrors(source, [StaticTypeWarningCode.UNDEFINED_OPERATOR]); |
| 8860 } | 9134 } |
| 8861 | 9135 |
| 8862 void test_if_or_is() { | 9136 void test_if_or_is() { |
| 8863 Source source = addSource(EngineTestCase.createSource([ | 9137 Source source = addSource(r''' |
| 8864 "int f(num n) {", | 9138 int f(num n) { |
| 8865 " if (n is! int || n < 0) {", | 9139 if (n is! int || n < 0) { |
| 8866 " return 0;", | 9140 return 0; |
| 8867 " } else {", | 9141 } else { |
| 8868 " return n & 0x0F;", | 9142 return n & 0x0F; |
| 8869 " }", | 9143 } |
| 8870 "}"])); | 9144 }'''); |
| 8871 resolve(source); | 9145 resolve(source); |
| 8872 assertErrors(source, [StaticTypeWarningCode.UNDEFINED_OPERATOR]); | 9146 assertErrors(source, [StaticTypeWarningCode.UNDEFINED_OPERATOR]); |
| 8873 } | 9147 } |
| 8874 | 9148 |
| 8875 void test_localVar() { | 9149 void test_localVar() { |
| 8876 Source source = addSource(EngineTestCase.createSource(["int f() {", " num n
= 1234;", " return n & 0x0F;", "}"])); | 9150 Source source = addSource(r''' |
| 9151 int f() { |
| 9152 num n = 1234; |
| 9153 return n & 0x0F; |
| 9154 }'''); |
| 8877 resolve(source); | 9155 resolve(source); |
| 8878 assertErrors(source, [StaticTypeWarningCode.UNDEFINED_OPERATOR]); | 9156 assertErrors(source, [StaticTypeWarningCode.UNDEFINED_OPERATOR]); |
| 8879 } | 9157 } |
| 8880 } | 9158 } |
| 8881 | 9159 |
| 8882 class SubtypeManagerTest extends EngineTestCase { | 9160 class SubtypeManagerTest extends EngineTestCase { |
| 8883 /** | 9161 /** |
| 8884 * The inheritance manager being tested. | 9162 * The inheritance manager being tested. |
| 8885 */ | 9163 */ |
| 8886 SubtypeManager _subtypeManager; | 9164 SubtypeManager _subtypeManager; |
| (...skipping 584 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9471 void test_getType_noScope() { | 9749 void test_getType_noScope() { |
| 9472 TypeOverrideManager manager = new TypeOverrideManager(); | 9750 TypeOverrideManager manager = new TypeOverrideManager(); |
| 9473 JUnitTestCase.assertNull(manager.getType(ElementFactory.localVariableElement
2("v"))); | 9751 JUnitTestCase.assertNull(manager.getType(ElementFactory.localVariableElement
2("v"))); |
| 9474 } | 9752 } |
| 9475 } | 9753 } |
| 9476 | 9754 |
| 9477 | 9755 |
| 9478 class TypePropagationTest extends ResolverTestCase { | 9756 class TypePropagationTest extends ResolverTestCase { |
| 9479 void fail_mergePropagatedTypesAtJoinPoint_1() { | 9757 void fail_mergePropagatedTypesAtJoinPoint_1() { |
| 9480 // https://code.google.com/p/dart/issues/detail?id=19929 | 9758 // https://code.google.com/p/dart/issues/detail?id=19929 |
| 9481 _assertTypeOfMarkedExpression(EngineTestCase.createSource([ | 9759 _assertTypeOfMarkedExpression(r''' |
| 9482 "f1(x) {", | 9760 f1(x) { |
| 9483 " var y = [];", | 9761 var y = []; |
| 9484 " if (x) {", | 9762 if (x) { |
| 9485 " y = 0;", | 9763 y = 0; |
| 9486 " } else {", | 9764 } else { |
| 9487 " y = '';", | 9765 y = ''; |
| 9488 " }", | 9766 } |
| 9489 " // Propagated type is [List] here: incorrect.", | 9767 // Propagated type is [List] here: incorrect. |
| 9490 " // Best we can do is [Object]?", | 9768 // Best we can do is [Object]? |
| 9491 " return y; // marker", | 9769 return y; // marker |
| 9492 "}"]), null, typeProvider.dynamicType); | 9770 }''', null, typeProvider.dynamicType); |
| 9493 } | 9771 } |
| 9494 | 9772 |
| 9495 void fail_mergePropagatedTypesAtJoinPoint_2() { | 9773 void fail_mergePropagatedTypesAtJoinPoint_2() { |
| 9496 // https://code.google.com/p/dart/issues/detail?id=19929 | 9774 // https://code.google.com/p/dart/issues/detail?id=19929 |
| 9497 _assertTypeOfMarkedExpression(EngineTestCase.createSource([ | 9775 _assertTypeOfMarkedExpression(r''' |
| 9498 "f2(x) {", | 9776 f2(x) { |
| 9499 " var y = [];", | 9777 var y = []; |
| 9500 " if (x) {", | 9778 if (x) { |
| 9501 " y = 0;", | 9779 y = 0; |
| 9502 " } else {", | 9780 } else { |
| 9503 " }", | 9781 } |
| 9504 " // Propagated type is [List] here: incorrect.", | 9782 // Propagated type is [List] here: incorrect. |
| 9505 " // Best we can do is [Object]?", | 9783 // Best we can do is [Object]? |
| 9506 " return y; // marker", | 9784 return y; // marker |
| 9507 "}"]), null, typeProvider.dynamicType); | 9785 }''', null, typeProvider.dynamicType); |
| 9508 } | 9786 } |
| 9509 | 9787 |
| 9510 void fail_mergePropagatedTypesAtJoinPoint_3() { | 9788 void fail_mergePropagatedTypesAtJoinPoint_3() { |
| 9511 // https://code.google.com/p/dart/issues/detail?id=19929 | 9789 // https://code.google.com/p/dart/issues/detail?id=19929 |
| 9512 _assertTypeOfMarkedExpression(EngineTestCase.createSource([ | 9790 _assertTypeOfMarkedExpression(r''' |
| 9513 "f4(x) {", | 9791 f4(x) { |
| 9514 " var y = [];", | 9792 var y = []; |
| 9515 " if (x) {", | 9793 if (x) { |
| 9516 " y = 0;", | 9794 y = 0; |
| 9517 " } else {", | 9795 } else { |
| 9518 " y = 1.5;", | 9796 y = 1.5; |
| 9519 " }", | 9797 } |
| 9520 " // Propagated type is [List] here: incorrect.", | 9798 // Propagated type is [List] here: incorrect. |
| 9521 " // A correct answer is the least upper bound of [int] and [double],", | 9799 // A correct answer is the least upper bound of [int] and [double], |
| 9522 " // i.e. [num].", | 9800 // i.e. [num]. |
| 9523 " return y; // marker", | 9801 return y; // marker |
| 9524 "}"]), null, typeProvider.numType); | 9802 }''', null, typeProvider.numType); |
| 9525 } | 9803 } |
| 9526 | 9804 |
| 9527 void fail_mergePropagatedTypesAtJoinPoint_5() { | 9805 void fail_mergePropagatedTypesAtJoinPoint_5() { |
| 9528 // https://code.google.com/p/dart/issues/detail?id=19929 | 9806 // https://code.google.com/p/dart/issues/detail?id=19929 |
| 9529 _assertTypeOfMarkedExpression(EngineTestCase.createSource([ | 9807 _assertTypeOfMarkedExpression(r''' |
| 9530 "f6(x,y) {", | 9808 f6(x,y) { |
| 9531 " var z = [];", | 9809 var z = []; |
| 9532 " if (x || (z = y) < 0) {", | 9810 if (x || (z = y) < 0) { |
| 9533 " } else {", | 9811 } else { |
| 9534 " z = 0;", | 9812 z = 0; |
| 9535 " }", | 9813 } |
| 9536 " // Propagated type is [List] here: incorrect.", | 9814 // Propagated type is [List] here: incorrect. |
| 9537 " // Best we can do is [Object]?", | 9815 // Best we can do is [Object]? |
| 9538 " return z; // marker", | 9816 return z; // marker |
| 9539 "}"]), null, typeProvider.dynamicType); | 9817 }''', null, typeProvider.dynamicType); |
| 9540 } | 9818 } |
| 9541 | 9819 |
| 9542 void fail_mergePropagatedTypesAtJoinPoint_7() { | 9820 void fail_mergePropagatedTypesAtJoinPoint_7() { |
| 9543 // https://code.google.com/p/dart/issues/detail?id=19929 | 9821 // https://code.google.com/p/dart/issues/detail?id=19929 |
| 9544 // | 9822 // |
| 9545 // In general [continue]s are unsafe for the purposes of [isAbruptTerminatio
nStatement]. | 9823 // In general [continue]s are unsafe for the purposes of [isAbruptTerminatio
nStatement]. |
| 9546 // | 9824 // |
| 9547 // This is like example 6, but less tricky: the code in the branch that | 9825 // This is like example 6, but less tricky: the code in the branch that |
| 9548 // [continue]s is in effect after the [if]. | 9826 // [continue]s is in effect after the [if]. |
| 9549 String code = EngineTestCase.createSource([ | 9827 String code = r''' |
| 9550 "f() {", | 9828 f() { |
| 9551 " var x = 0;", | 9829 var x = 0; |
| 9552 " var c = false;", | 9830 var c = false; |
| 9553 " var d = true;", | 9831 var d = true; |
| 9554 " while (d) {", | 9832 while (d) { |
| 9555 " if (c) {", | 9833 if (c) { |
| 9556 " d = false;", | 9834 d = false; |
| 9557 " } else {", | 9835 } else { |
| 9558 " x = '';", | 9836 x = ''; |
| 9559 " c = true;", | 9837 c = true; |
| 9560 " continue;", | 9838 continue; |
| 9561 " }", | 9839 } |
| 9562 " x; // marker", | 9840 x; // marker |
| 9563 " }", | 9841 } |
| 9564 "}"]); | 9842 }'''; |
| 9565 DartType t = _findMarkedIdentifier(code, "; // marker").propagatedType; | 9843 DartType t = _findMarkedIdentifier(code, "; // marker").propagatedType; |
| 9566 JUnitTestCase.assertTrue(typeProvider.intType.isSubtypeOf(t)); | 9844 JUnitTestCase.assertTrue(typeProvider.intType.isSubtypeOf(t)); |
| 9567 JUnitTestCase.assertTrue(typeProvider.stringType.isSubtypeOf(t)); | 9845 JUnitTestCase.assertTrue(typeProvider.stringType.isSubtypeOf(t)); |
| 9568 } | 9846 } |
| 9569 | 9847 |
| 9570 void fail_mergePropagatedTypesAtJoinPoint_8() { | 9848 void fail_mergePropagatedTypesAtJoinPoint_8() { |
| 9571 // https://code.google.com/p/dart/issues/detail?id=19929 | 9849 // https://code.google.com/p/dart/issues/detail?id=19929 |
| 9572 // | 9850 // |
| 9573 // In nested loops [breaks]s are unsafe for the purposes of [isAbruptTermina
tionStatement]. | 9851 // In nested loops [breaks]s are unsafe for the purposes of [isAbruptTermina
tionStatement]. |
| 9574 // | 9852 // |
| 9575 // This is a combination of 6 and 7: we use an unlabeled [break] | 9853 // This is a combination of 6 and 7: we use an unlabeled [break] |
| 9576 // like a continue for the outer loop / like a labeled [break] to | 9854 // like a continue for the outer loop / like a labeled [break] to |
| 9577 // jump just above the [if]. | 9855 // jump just above the [if]. |
| 9578 String code = EngineTestCase.createSource([ | 9856 String code = r''' |
| 9579 "f() {", | 9857 f() { |
| 9580 " var x = 0;", | 9858 var x = 0; |
| 9581 " var c = false;", | 9859 var c = false; |
| 9582 " var d = true;", | 9860 var d = true; |
| 9583 " while (d) {", | 9861 while (d) { |
| 9584 " while (d) {", | 9862 while (d) { |
| 9585 " if (c) {", | 9863 if (c) { |
| 9586 " d = false;", | 9864 d = false; |
| 9587 " } else {", | 9865 } else { |
| 9588 " x = '';", | 9866 x = ''; |
| 9589 " c = true;", | 9867 c = true; |
| 9590 " break;", | 9868 break; |
| 9591 " }", | 9869 } |
| 9592 " x; // marker", | 9870 x; // marker |
| 9593 " }", | 9871 } |
| 9594 " }", | 9872 } |
| 9595 "}"]); | 9873 }'''; |
| 9596 DartType t = _findMarkedIdentifier(code, "; // marker").propagatedType; | 9874 DartType t = _findMarkedIdentifier(code, "; // marker").propagatedType; |
| 9597 JUnitTestCase.assertTrue(typeProvider.intType.isSubtypeOf(t)); | 9875 JUnitTestCase.assertTrue(typeProvider.intType.isSubtypeOf(t)); |
| 9598 JUnitTestCase.assertTrue(typeProvider.stringType.isSubtypeOf(t)); | 9876 JUnitTestCase.assertTrue(typeProvider.stringType.isSubtypeOf(t)); |
| 9599 } | 9877 } |
| 9600 | 9878 |
| 9601 void fail_propagatedReturnType_functionExpression() { | 9879 void fail_propagatedReturnType_functionExpression() { |
| 9602 // TODO(scheglov) disabled because we don't resolve function expression | 9880 // TODO(scheglov) disabled because we don't resolve function expression |
| 9603 String code = EngineTestCase.createSource(["main() {", " var v = (() {retur
n 42;})();", "}"]); | 9881 String code = r''' |
| 9882 main() { |
| 9883 var v = (() {return 42;})(); |
| 9884 }'''; |
| 9604 _assertPropagatedReturnType(code, typeProvider.dynamicType, typeProvider.int
Type); | 9885 _assertPropagatedReturnType(code, typeProvider.dynamicType, typeProvider.int
Type); |
| 9605 } | 9886 } |
| 9606 | 9887 |
| 9607 void test_as() { | 9888 void test_as() { |
| 9608 Source source = addSource(EngineTestCase.createSource([ | 9889 Source source = addSource(r''' |
| 9609 "class A {", | 9890 class A { |
| 9610 " bool get g => true;", | 9891 bool get g => true; |
| 9611 "}", | 9892 } |
| 9612 "A f(var p) {", | 9893 A f(var p) { |
| 9613 " if ((p as A).g) {", | 9894 if ((p as A).g) { |
| 9614 " return p;", | 9895 return p; |
| 9615 " } else {", | 9896 } else { |
| 9616 " return null;", | 9897 return null; |
| 9617 " }", | 9898 } |
| 9618 "}"])); | 9899 }'''); |
| 9619 LibraryElement library = resolve(source); | 9900 LibraryElement library = resolve(source); |
| 9620 assertNoErrors(source); | 9901 assertNoErrors(source); |
| 9621 verify([source]); | 9902 verify([source]); |
| 9622 CompilationUnit unit = resolveCompilationUnit(source, library); | 9903 CompilationUnit unit = resolveCompilationUnit(source, library); |
| 9623 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration; | 9904 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration; |
| 9624 InterfaceType typeA = classA.element.type; | 9905 InterfaceType typeA = classA.element.type; |
| 9625 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration; | 9906 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration; |
| 9626 BlockFunctionBody body = function.functionExpression.body as BlockFunctionBo
dy; | 9907 BlockFunctionBody body = function.functionExpression.body as BlockFunctionBo
dy; |
| 9627 IfStatement ifStatement = body.block.statements[0] as IfStatement; | 9908 IfStatement ifStatement = body.block.statements[0] as IfStatement; |
| 9628 ReturnStatement statement = (ifStatement.thenStatement as Block).statements[
0] as ReturnStatement; | 9909 ReturnStatement statement = (ifStatement.thenStatement as Block).statements[
0] as ReturnStatement; |
| 9629 SimpleIdentifier variableName = statement.expression as SimpleIdentifier; | 9910 SimpleIdentifier variableName = statement.expression as SimpleIdentifier; |
| 9630 JUnitTestCase.assertSame(typeA, variableName.propagatedType); | 9911 JUnitTestCase.assertSame(typeA, variableName.propagatedType); |
| 9631 } | 9912 } |
| 9632 | 9913 |
| 9633 void test_assert() { | 9914 void test_assert() { |
| 9634 Source source = addSource(EngineTestCase.createSource([ | 9915 Source source = addSource(r''' |
| 9635 "class A {}", | 9916 class A {} |
| 9636 "A f(var p) {", | 9917 A f(var p) { |
| 9637 " assert (p is A);", | 9918 assert (p is A); |
| 9638 " return p;", | 9919 return p; |
| 9639 "}"])); | 9920 }'''); |
| 9640 LibraryElement library = resolve(source); | 9921 LibraryElement library = resolve(source); |
| 9641 assertNoErrors(source); | 9922 assertNoErrors(source); |
| 9642 verify([source]); | 9923 verify([source]); |
| 9643 CompilationUnit unit = resolveCompilationUnit(source, library); | 9924 CompilationUnit unit = resolveCompilationUnit(source, library); |
| 9644 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration; | 9925 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration; |
| 9645 InterfaceType typeA = classA.element.type; | 9926 InterfaceType typeA = classA.element.type; |
| 9646 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration; | 9927 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration; |
| 9647 BlockFunctionBody body = function.functionExpression.body as BlockFunctionBo
dy; | 9928 BlockFunctionBody body = function.functionExpression.body as BlockFunctionBo
dy; |
| 9648 ReturnStatement statement = body.block.statements[1] as ReturnStatement; | 9929 ReturnStatement statement = body.block.statements[1] as ReturnStatement; |
| 9649 SimpleIdentifier variableName = statement.expression as SimpleIdentifier; | 9930 SimpleIdentifier variableName = statement.expression as SimpleIdentifier; |
| 9650 JUnitTestCase.assertSame(typeA, variableName.propagatedType); | 9931 JUnitTestCase.assertSame(typeA, variableName.propagatedType); |
| 9651 } | 9932 } |
| 9652 | 9933 |
| 9653 void test_assignment() { | 9934 void test_assignment() { |
| 9654 Source source = addSource(EngineTestCase.createSource(["f() {", " var v;",
" v = 0;", " return v;", "}"])); | 9935 Source source = addSource(r''' |
| 9936 f() { |
| 9937 var v; |
| 9938 v = 0; |
| 9939 return v; |
| 9940 }'''); |
| 9655 LibraryElement library = resolve(source); | 9941 LibraryElement library = resolve(source); |
| 9656 assertNoErrors(source); | 9942 assertNoErrors(source); |
| 9657 verify([source]); | 9943 verify([source]); |
| 9658 CompilationUnit unit = resolveCompilationUnit(source, library); | 9944 CompilationUnit unit = resolveCompilationUnit(source, library); |
| 9659 FunctionDeclaration function = unit.declarations[0] as FunctionDeclaration; | 9945 FunctionDeclaration function = unit.declarations[0] as FunctionDeclaration; |
| 9660 BlockFunctionBody body = function.functionExpression.body as BlockFunctionBo
dy; | 9946 BlockFunctionBody body = function.functionExpression.body as BlockFunctionBo
dy; |
| 9661 ReturnStatement statement = body.block.statements[2] as ReturnStatement; | 9947 ReturnStatement statement = body.block.statements[2] as ReturnStatement; |
| 9662 SimpleIdentifier variableName = statement.expression as SimpleIdentifier; | 9948 SimpleIdentifier variableName = statement.expression as SimpleIdentifier; |
| 9663 JUnitTestCase.assertSame(typeProvider.intType, variableName.propagatedType); | 9949 JUnitTestCase.assertSame(typeProvider.intType, variableName.propagatedType); |
| 9664 } | 9950 } |
| 9665 | 9951 |
| 9666 void test_assignment_afterInitializer() { | 9952 void test_assignment_afterInitializer() { |
| 9667 Source source = addSource(EngineTestCase.createSource(["f() {", " var v = 0
;", " v = 1.0;", " return v;", "}"])); | 9953 Source source = addSource(r''' |
| 9954 f() { |
| 9955 var v = 0; |
| 9956 v = 1.0; |
| 9957 return v; |
| 9958 }'''); |
| 9668 LibraryElement library = resolve(source); | 9959 LibraryElement library = resolve(source); |
| 9669 assertNoErrors(source); | 9960 assertNoErrors(source); |
| 9670 verify([source]); | 9961 verify([source]); |
| 9671 CompilationUnit unit = resolveCompilationUnit(source, library); | 9962 CompilationUnit unit = resolveCompilationUnit(source, library); |
| 9672 FunctionDeclaration function = unit.declarations[0] as FunctionDeclaration; | 9963 FunctionDeclaration function = unit.declarations[0] as FunctionDeclaration; |
| 9673 BlockFunctionBody body = function.functionExpression.body as BlockFunctionBo
dy; | 9964 BlockFunctionBody body = function.functionExpression.body as BlockFunctionBo
dy; |
| 9674 ReturnStatement statement = body.block.statements[2] as ReturnStatement; | 9965 ReturnStatement statement = body.block.statements[2] as ReturnStatement; |
| 9675 SimpleIdentifier variableName = statement.expression as SimpleIdentifier; | 9966 SimpleIdentifier variableName = statement.expression as SimpleIdentifier; |
| 9676 JUnitTestCase.assertSame(typeProvider.doubleType, variableName.propagatedTyp
e); | 9967 JUnitTestCase.assertSame(typeProvider.doubleType, variableName.propagatedTyp
e); |
| 9677 } | 9968 } |
| 9678 | 9969 |
| 9679 void test_assignment_null() { | 9970 void test_assignment_null() { |
| 9680 String code = EngineTestCase.createSource([ | 9971 String code = r''' |
| 9681 "main() {", | 9972 main() { |
| 9682 " int v; // declare", | 9973 int v; // declare |
| 9683 " v = null;", | 9974 v = null; |
| 9684 " return v; // return", | 9975 return v; // return |
| 9685 "}"]); | 9976 }'''; |
| 9686 CompilationUnit unit; | 9977 CompilationUnit unit; |
| 9687 { | 9978 { |
| 9688 Source source = addSource(code); | 9979 Source source = addSource(code); |
| 9689 LibraryElement library = resolve(source); | 9980 LibraryElement library = resolve(source); |
| 9690 assertNoErrors(source); | 9981 assertNoErrors(source); |
| 9691 verify([source]); | 9982 verify([source]); |
| 9692 unit = resolveCompilationUnit(source, library); | 9983 unit = resolveCompilationUnit(source, library); |
| 9693 } | 9984 } |
| 9694 { | 9985 { |
| 9695 SimpleIdentifier identifier = EngineTestCase.findNode(unit, code, "v; // d
eclare", (node) => node is SimpleIdentifier); | 9986 SimpleIdentifier identifier = EngineTestCase.findNode(unit, code, "v; // d
eclare", (node) => node is SimpleIdentifier); |
| 9696 JUnitTestCase.assertSame(typeProvider.intType, identifier.staticType); | 9987 JUnitTestCase.assertSame(typeProvider.intType, identifier.staticType); |
| 9697 JUnitTestCase.assertSame(null, identifier.propagatedType); | 9988 JUnitTestCase.assertSame(null, identifier.propagatedType); |
| 9698 } | 9989 } |
| 9699 { | 9990 { |
| 9700 SimpleIdentifier identifier = EngineTestCase.findNode(unit, code, "v = nul
l;", (node) => node is SimpleIdentifier); | 9991 SimpleIdentifier identifier = EngineTestCase.findNode(unit, code, "v = nul
l;", (node) => node is SimpleIdentifier); |
| 9701 JUnitTestCase.assertSame(typeProvider.intType, identifier.staticType); | 9992 JUnitTestCase.assertSame(typeProvider.intType, identifier.staticType); |
| 9702 JUnitTestCase.assertSame(null, identifier.propagatedType); | 9993 JUnitTestCase.assertSame(null, identifier.propagatedType); |
| 9703 } | 9994 } |
| 9704 { | 9995 { |
| 9705 SimpleIdentifier identifier = EngineTestCase.findNode(unit, code, "v; // r
eturn", (node) => node is SimpleIdentifier); | 9996 SimpleIdentifier identifier = EngineTestCase.findNode(unit, code, "v; // r
eturn", (node) => node is SimpleIdentifier); |
| 9706 JUnitTestCase.assertSame(typeProvider.intType, identifier.staticType); | 9997 JUnitTestCase.assertSame(typeProvider.intType, identifier.staticType); |
| 9707 JUnitTestCase.assertSame(null, identifier.propagatedType); | 9998 JUnitTestCase.assertSame(null, identifier.propagatedType); |
| 9708 } | 9999 } |
| 9709 } | 10000 } |
| 9710 | 10001 |
| 9711 void test_CanvasElement_getContext() { | 10002 void test_CanvasElement_getContext() { |
| 9712 String code = EngineTestCase.createSource([ | 10003 String code = r''' |
| 9713 "import 'dart:html';", | 10004 import 'dart:html'; |
| 9714 "main(CanvasElement canvas) {", | 10005 main(CanvasElement canvas) { |
| 9715 " var context = canvas.getContext('2d');", | 10006 var context = canvas.getContext('2d'); |
| 9716 "}"]); | 10007 }'''; |
| 9717 Source source = addSource(code); | 10008 Source source = addSource(code); |
| 9718 LibraryElement library = resolve(source); | 10009 LibraryElement library = resolve(source); |
| 9719 assertNoErrors(source); | 10010 assertNoErrors(source); |
| 9720 verify([source]); | 10011 verify([source]); |
| 9721 CompilationUnit unit = resolveCompilationUnit(source, library); | 10012 CompilationUnit unit = resolveCompilationUnit(source, library); |
| 9722 SimpleIdentifier identifier = EngineTestCase.findNode(unit, code, "context",
(node) => node is SimpleIdentifier); | 10013 SimpleIdentifier identifier = EngineTestCase.findNode(unit, code, "context",
(node) => node is SimpleIdentifier); |
| 9723 JUnitTestCase.assertEquals("CanvasRenderingContext2D", identifier.propagated
Type.name); | 10014 JUnitTestCase.assertEquals("CanvasRenderingContext2D", identifier.propagated
Type.name); |
| 9724 } | 10015 } |
| 9725 | 10016 |
| 9726 void test_finalPropertyInducingVariable_classMember_instance() { | 10017 void test_finalPropertyInducingVariable_classMember_instance() { |
| 9727 addNamedSource("/lib.dart", EngineTestCase.createSource(["class A {", " fin
al v = 0;", "}"])); | 10018 addNamedSource("/lib.dart", r''' |
| 9728 String code = EngineTestCase.createSource([ | 10019 class A { |
| 9729 "import 'lib.dart';", | 10020 final v = 0; |
| 9730 "f(A a) {", | 10021 }'''); |
| 9731 " return a.v; // marker", | 10022 String code = r''' |
| 9732 "}"]); | 10023 import 'lib.dart'; |
| 10024 f(A a) { |
| 10025 return a.v; // marker |
| 10026 }'''; |
| 9733 _assertTypeOfMarkedExpression(code, typeProvider.dynamicType, typeProvider.i
ntType); | 10027 _assertTypeOfMarkedExpression(code, typeProvider.dynamicType, typeProvider.i
ntType); |
| 9734 } | 10028 } |
| 9735 | 10029 |
| 9736 void test_finalPropertyInducingVariable_classMember_instance_inherited() { | 10030 void test_finalPropertyInducingVariable_classMember_instance_inherited() { |
| 9737 addNamedSource("/lib.dart", EngineTestCase.createSource(["class A {", " fin
al v = 0;", "}"])); | 10031 addNamedSource("/lib.dart", r''' |
| 9738 String code = EngineTestCase.createSource([ | 10032 class A { |
| 9739 "import 'lib.dart';", | 10033 final v = 0; |
| 9740 "class B extends A {", | 10034 }'''); |
| 9741 " m() {", | 10035 String code = r''' |
| 9742 " return v; // marker", | 10036 import 'lib.dart'; |
| 9743 " }", | 10037 class B extends A { |
| 9744 "}"]); | 10038 m() { |
| 10039 return v; // marker |
| 10040 } |
| 10041 }'''; |
| 9745 _assertTypeOfMarkedExpression(code, typeProvider.dynamicType, typeProvider.i
ntType); | 10042 _assertTypeOfMarkedExpression(code, typeProvider.dynamicType, typeProvider.i
ntType); |
| 9746 } | 10043 } |
| 9747 | 10044 |
| 9748 void test_finalPropertyInducingVariable_classMember_instance_propagatedTarget(
) { | 10045 void test_finalPropertyInducingVariable_classMember_instance_propagatedTarget(
) { |
| 9749 addNamedSource("/lib.dart", EngineTestCase.createSource(["class A {", " fin
al v = 0;", "}"])); | 10046 addNamedSource("/lib.dart", r''' |
| 9750 String code = EngineTestCase.createSource([ | 10047 class A { |
| 9751 "import 'lib.dart';", | 10048 final v = 0; |
| 9752 "f(p) {", | 10049 }'''); |
| 9753 " if (p is A) {", | 10050 String code = r''' |
| 9754 " return p.v; // marker", | 10051 import 'lib.dart'; |
| 9755 " }", | 10052 f(p) { |
| 9756 "}"]); | 10053 if (p is A) { |
| 10054 return p.v; // marker |
| 10055 } |
| 10056 }'''; |
| 9757 _assertTypeOfMarkedExpression(code, typeProvider.dynamicType, typeProvider.i
ntType); | 10057 _assertTypeOfMarkedExpression(code, typeProvider.dynamicType, typeProvider.i
ntType); |
| 9758 } | 10058 } |
| 9759 | 10059 |
| 9760 void test_finalPropertyInducingVariable_classMember_static() { | 10060 void test_finalPropertyInducingVariable_classMember_static() { |
| 9761 addNamedSource("/lib.dart", EngineTestCase.createSource(["class A {", " sta
tic final V = 0;", "}"])); | 10061 addNamedSource("/lib.dart", r''' |
| 9762 String code = EngineTestCase.createSource([ | 10062 class A { |
| 9763 "import 'lib.dart';", | 10063 static final V = 0; |
| 9764 "f() {", | 10064 }'''); |
| 9765 " return A.V; // marker", | 10065 String code = r''' |
| 9766 "}"]); | 10066 import 'lib.dart'; |
| 10067 f() { |
| 10068 return A.V; // marker |
| 10069 }'''; |
| 9767 _assertTypeOfMarkedExpression(code, typeProvider.dynamicType, typeProvider.i
ntType); | 10070 _assertTypeOfMarkedExpression(code, typeProvider.dynamicType, typeProvider.i
ntType); |
| 9768 } | 10071 } |
| 9769 | 10072 |
| 9770 void test_finalPropertyInducingVariable_topLevelVaraible_prefixed() { | 10073 void test_finalPropertyInducingVariable_topLevelVaraible_prefixed() { |
| 9771 addNamedSource("/lib.dart", "final V = 0;"); | 10074 addNamedSource("/lib.dart", "final V = 0;"); |
| 9772 String code = EngineTestCase.createSource([ | 10075 String code = r''' |
| 9773 "import 'lib.dart' as p;", | 10076 import 'lib.dart' as p; |
| 9774 "f() {", | 10077 f() { |
| 9775 " var v2 = p.V; // marker prefixed", | 10078 var v2 = p.V; // marker prefixed |
| 9776 "}"]); | 10079 }'''; |
| 9777 _assertTypeOfMarkedExpression(code, typeProvider.dynamicType, typeProvider.i
ntType); | 10080 _assertTypeOfMarkedExpression(code, typeProvider.dynamicType, typeProvider.i
ntType); |
| 9778 } | 10081 } |
| 9779 | 10082 |
| 9780 void test_finalPropertyInducingVariable_topLevelVaraible_simple() { | 10083 void test_finalPropertyInducingVariable_topLevelVaraible_simple() { |
| 9781 addNamedSource("/lib.dart", "final V = 0;"); | 10084 addNamedSource("/lib.dart", "final V = 0;"); |
| 9782 String code = EngineTestCase.createSource([ | 10085 String code = r''' |
| 9783 "import 'lib.dart';", | 10086 import 'lib.dart'; |
| 9784 "f() {", | 10087 f() { |
| 9785 " return V; // marker simple", | 10088 return V; // marker simple |
| 9786 "}"]); | 10089 }'''; |
| 9787 _assertTypeOfMarkedExpression(code, typeProvider.dynamicType, typeProvider.i
ntType); | 10090 _assertTypeOfMarkedExpression(code, typeProvider.dynamicType, typeProvider.i
ntType); |
| 9788 } | 10091 } |
| 9789 | 10092 |
| 9790 void test_forEach() { | 10093 void test_forEach() { |
| 9791 String code = EngineTestCase.createSource([ | 10094 String code = r''' |
| 9792 "main() {", | 10095 main() { |
| 9793 " var list = <String> [];", | 10096 var list = <String> []; |
| 9794 " for (var e in list) {", | 10097 for (var e in list) { |
| 9795 " e;", | 10098 e; |
| 9796 " }", | 10099 } |
| 9797 "}"]); | 10100 }'''; |
| 9798 Source source = addSource(code); | 10101 Source source = addSource(code); |
| 9799 LibraryElement library = resolve(source); | 10102 LibraryElement library = resolve(source); |
| 9800 assertNoErrors(source); | 10103 assertNoErrors(source); |
| 9801 verify([source]); | 10104 verify([source]); |
| 9802 CompilationUnit unit = resolveCompilationUnit(source, library); | 10105 CompilationUnit unit = resolveCompilationUnit(source, library); |
| 9803 InterfaceType stringType = typeProvider.stringType; | 10106 InterfaceType stringType = typeProvider.stringType; |
| 9804 // in the declaration | 10107 // in the declaration |
| 9805 { | 10108 { |
| 9806 SimpleIdentifier identifier = EngineTestCase.findNode(unit, code, "e in",
(node) => node is SimpleIdentifier); | 10109 SimpleIdentifier identifier = EngineTestCase.findNode(unit, code, "e in",
(node) => node is SimpleIdentifier); |
| 9807 JUnitTestCase.assertSame(stringType, identifier.propagatedType); | 10110 JUnitTestCase.assertSame(stringType, identifier.propagatedType); |
| 9808 } | 10111 } |
| 9809 // in the loop body | 10112 // in the loop body |
| 9810 { | 10113 { |
| 9811 SimpleIdentifier identifier = EngineTestCase.findNode(unit, code, "e;", (n
ode) => node is SimpleIdentifier); | 10114 SimpleIdentifier identifier = EngineTestCase.findNode(unit, code, "e;", (n
ode) => node is SimpleIdentifier); |
| 9812 JUnitTestCase.assertSame(stringType, identifier.propagatedType); | 10115 JUnitTestCase.assertSame(stringType, identifier.propagatedType); |
| 9813 } | 10116 } |
| 9814 } | 10117 } |
| 9815 | 10118 |
| 9816 void test_functionExpression_asInvocationArgument() { | 10119 void test_functionExpression_asInvocationArgument() { |
| 9817 String code = EngineTestCase.createSource([ | 10120 String code = r''' |
| 9818 "class MyMap<K, V> {", | 10121 class MyMap<K, V> { |
| 9819 " forEach(f(K key, V value)) {}", | 10122 forEach(f(K key, V value)) {} |
| 9820 "}", | 10123 } |
| 9821 "f(MyMap<int, String> m) {", | 10124 f(MyMap<int, String> m) { |
| 9822 " m.forEach((k, v) {", | 10125 m.forEach((k, v) { |
| 9823 " k;", | 10126 k; |
| 9824 " v;", | 10127 v; |
| 9825 " });", | 10128 }); |
| 9826 "}"]); | 10129 }'''; |
| 9827 Source source = addSource(code); | 10130 Source source = addSource(code); |
| 9828 LibraryElement library = resolve(source); | 10131 LibraryElement library = resolve(source); |
| 9829 assertNoErrors(source); | 10132 assertNoErrors(source); |
| 9830 verify([source]); | 10133 verify([source]); |
| 9831 CompilationUnit unit = resolveCompilationUnit(source, library); | 10134 CompilationUnit unit = resolveCompilationUnit(source, library); |
| 9832 // k | 10135 // k |
| 9833 DartType intType = typeProvider.intType; | 10136 DartType intType = typeProvider.intType; |
| 9834 FormalParameter kParameter = EngineTestCase.findNode(unit, code, "k, ", (nod
e) => node is SimpleFormalParameter); | 10137 FormalParameter kParameter = EngineTestCase.findNode(unit, code, "k, ", (nod
e) => node is SimpleFormalParameter); |
| 9835 JUnitTestCase.assertSame(intType, kParameter.identifier.propagatedType); | 10138 JUnitTestCase.assertSame(intType, kParameter.identifier.propagatedType); |
| 9836 SimpleIdentifier kIdentifier = EngineTestCase.findNode(unit, code, "k;", (no
de) => node is SimpleIdentifier); | 10139 SimpleIdentifier kIdentifier = EngineTestCase.findNode(unit, code, "k;", (no
de) => node is SimpleIdentifier); |
| 9837 JUnitTestCase.assertSame(intType, kIdentifier.propagatedType); | 10140 JUnitTestCase.assertSame(intType, kIdentifier.propagatedType); |
| 9838 JUnitTestCase.assertSame(typeProvider.dynamicType, kIdentifier.staticType); | 10141 JUnitTestCase.assertSame(typeProvider.dynamicType, kIdentifier.staticType); |
| 9839 // v | 10142 // v |
| 9840 DartType stringType = typeProvider.stringType; | 10143 DartType stringType = typeProvider.stringType; |
| 9841 FormalParameter vParameter = EngineTestCase.findNode(unit, code, "v)", (node
) => node is SimpleFormalParameter); | 10144 FormalParameter vParameter = EngineTestCase.findNode(unit, code, "v)", (node
) => node is SimpleFormalParameter); |
| 9842 JUnitTestCase.assertSame(stringType, vParameter.identifier.propagatedType); | 10145 JUnitTestCase.assertSame(stringType, vParameter.identifier.propagatedType); |
| 9843 SimpleIdentifier vIdentifier = EngineTestCase.findNode(unit, code, "v;", (no
de) => node is SimpleIdentifier); | 10146 SimpleIdentifier vIdentifier = EngineTestCase.findNode(unit, code, "v;", (no
de) => node is SimpleIdentifier); |
| 9844 JUnitTestCase.assertSame(stringType, vIdentifier.propagatedType); | 10147 JUnitTestCase.assertSame(stringType, vIdentifier.propagatedType); |
| 9845 JUnitTestCase.assertSame(typeProvider.dynamicType, vIdentifier.staticType); | 10148 JUnitTestCase.assertSame(typeProvider.dynamicType, vIdentifier.staticType); |
| 9846 } | 10149 } |
| 9847 | 10150 |
| 9848 void test_functionExpression_asInvocationArgument_fromInferredInvocation() { | 10151 void test_functionExpression_asInvocationArgument_fromInferredInvocation() { |
| 9849 String code = EngineTestCase.createSource([ | 10152 String code = r''' |
| 9850 "class MyMap<K, V> {", | 10153 class MyMap<K, V> { |
| 9851 " forEach(f(K key, V value)) {}", | 10154 forEach(f(K key, V value)) {} |
| 9852 "}", | 10155 } |
| 9853 "f(MyMap<int, String> m) {", | 10156 f(MyMap<int, String> m) { |
| 9854 " var m2 = m;", | 10157 var m2 = m; |
| 9855 " m2.forEach((k, v) {});", | 10158 m2.forEach((k, v) {}); |
| 9856 "}"]); | 10159 }'''; |
| 9857 Source source = addSource(code); | 10160 Source source = addSource(code); |
| 9858 LibraryElement library = resolve(source); | 10161 LibraryElement library = resolve(source); |
| 9859 assertNoErrors(source); | 10162 assertNoErrors(source); |
| 9860 verify([source]); | 10163 verify([source]); |
| 9861 CompilationUnit unit = resolveCompilationUnit(source, library); | 10164 CompilationUnit unit = resolveCompilationUnit(source, library); |
| 9862 // k | 10165 // k |
| 9863 DartType intType = typeProvider.intType; | 10166 DartType intType = typeProvider.intType; |
| 9864 FormalParameter kParameter = EngineTestCase.findNode(unit, code, "k, ", (nod
e) => node is SimpleFormalParameter); | 10167 FormalParameter kParameter = EngineTestCase.findNode(unit, code, "k, ", (nod
e) => node is SimpleFormalParameter); |
| 9865 JUnitTestCase.assertSame(intType, kParameter.identifier.propagatedType); | 10168 JUnitTestCase.assertSame(intType, kParameter.identifier.propagatedType); |
| 9866 // v | 10169 // v |
| 9867 DartType stringType = typeProvider.stringType; | 10170 DartType stringType = typeProvider.stringType; |
| 9868 FormalParameter vParameter = EngineTestCase.findNode(unit, code, "v)", (node
) => node is SimpleFormalParameter); | 10171 FormalParameter vParameter = EngineTestCase.findNode(unit, code, "v)", (node
) => node is SimpleFormalParameter); |
| 9869 JUnitTestCase.assertSame(stringType, vParameter.identifier.propagatedType); | 10172 JUnitTestCase.assertSame(stringType, vParameter.identifier.propagatedType); |
| 9870 } | 10173 } |
| 9871 | 10174 |
| 9872 void test_functionExpression_asInvocationArgument_functionExpressionInvocation
() { | 10175 void test_functionExpression_asInvocationArgument_functionExpressionInvocation
() { |
| 9873 String code = EngineTestCase.createSource([ | 10176 String code = r''' |
| 9874 "main() {", | 10177 main() { |
| 9875 " (f(String value)) {} ((v) {", | 10178 (f(String value)) {} ((v) { |
| 9876 " v;", | 10179 v; |
| 9877 " });", | 10180 }); |
| 9878 "}"]); | 10181 }'''; |
| 9879 Source source = addSource(code); | 10182 Source source = addSource(code); |
| 9880 LibraryElement library = resolve(source); | 10183 LibraryElement library = resolve(source); |
| 9881 assertNoErrors(source); | 10184 assertNoErrors(source); |
| 9882 verify([source]); | 10185 verify([source]); |
| 9883 CompilationUnit unit = resolveCompilationUnit(source, library); | 10186 CompilationUnit unit = resolveCompilationUnit(source, library); |
| 9884 // v | 10187 // v |
| 9885 DartType dynamicType = typeProvider.dynamicType; | 10188 DartType dynamicType = typeProvider.dynamicType; |
| 9886 DartType stringType = typeProvider.stringType; | 10189 DartType stringType = typeProvider.stringType; |
| 9887 FormalParameter vParameter = EngineTestCase.findNode(unit, code, "v)", (node
) => node is FormalParameter); | 10190 FormalParameter vParameter = EngineTestCase.findNode(unit, code, "v)", (node
) => node is FormalParameter); |
| 9888 JUnitTestCase.assertSame(stringType, vParameter.identifier.propagatedType); | 10191 JUnitTestCase.assertSame(stringType, vParameter.identifier.propagatedType); |
| 9889 JUnitTestCase.assertSame(dynamicType, vParameter.identifier.staticType); | 10192 JUnitTestCase.assertSame(dynamicType, vParameter.identifier.staticType); |
| 9890 SimpleIdentifier vIdentifier = EngineTestCase.findNode(unit, code, "v;", (no
de) => node is SimpleIdentifier); | 10193 SimpleIdentifier vIdentifier = EngineTestCase.findNode(unit, code, "v;", (no
de) => node is SimpleIdentifier); |
| 9891 JUnitTestCase.assertSame(stringType, vIdentifier.propagatedType); | 10194 JUnitTestCase.assertSame(stringType, vIdentifier.propagatedType); |
| 9892 JUnitTestCase.assertSame(dynamicType, vIdentifier.staticType); | 10195 JUnitTestCase.assertSame(dynamicType, vIdentifier.staticType); |
| 9893 } | 10196 } |
| 9894 | 10197 |
| 9895 void test_functionExpression_asInvocationArgument_keepIfLessSpecific() { | 10198 void test_functionExpression_asInvocationArgument_keepIfLessSpecific() { |
| 9896 String code = EngineTestCase.createSource([ | 10199 String code = r''' |
| 9897 "class MyList {", | 10200 class MyList { |
| 9898 " forEach(f(Object value)) {}", | 10201 forEach(f(Object value)) {} |
| 9899 "}", | 10202 } |
| 9900 "f(MyList list) {", | 10203 f(MyList list) { |
| 9901 " list.forEach((int v) {", | 10204 list.forEach((int v) { |
| 9902 " v;", | 10205 v; |
| 9903 " });", | 10206 }); |
| 9904 "}"]); | 10207 }'''; |
| 9905 Source source = addSource(code); | 10208 Source source = addSource(code); |
| 9906 LibraryElement library = resolve(source); | 10209 LibraryElement library = resolve(source); |
| 9907 assertNoErrors(source); | 10210 assertNoErrors(source); |
| 9908 verify([source]); | 10211 verify([source]); |
| 9909 CompilationUnit unit = resolveCompilationUnit(source, library); | 10212 CompilationUnit unit = resolveCompilationUnit(source, library); |
| 9910 // v | 10213 // v |
| 9911 DartType intType = typeProvider.intType; | 10214 DartType intType = typeProvider.intType; |
| 9912 FormalParameter vParameter = EngineTestCase.findNode(unit, code, "v)", (node
) => node is SimpleFormalParameter); | 10215 FormalParameter vParameter = EngineTestCase.findNode(unit, code, "v)", (node
) => node is SimpleFormalParameter); |
| 9913 JUnitTestCase.assertSame(null, vParameter.identifier.propagatedType); | 10216 JUnitTestCase.assertSame(null, vParameter.identifier.propagatedType); |
| 9914 JUnitTestCase.assertSame(intType, vParameter.identifier.staticType); | 10217 JUnitTestCase.assertSame(intType, vParameter.identifier.staticType); |
| 9915 SimpleIdentifier vIdentifier = EngineTestCase.findNode(unit, code, "v;", (no
de) => node is SimpleIdentifier); | 10218 SimpleIdentifier vIdentifier = EngineTestCase.findNode(unit, code, "v;", (no
de) => node is SimpleIdentifier); |
| 9916 JUnitTestCase.assertSame(intType, vIdentifier.staticType); | 10219 JUnitTestCase.assertSame(intType, vIdentifier.staticType); |
| 9917 JUnitTestCase.assertSame(null, vIdentifier.propagatedType); | 10220 JUnitTestCase.assertSame(null, vIdentifier.propagatedType); |
| 9918 } | 10221 } |
| 9919 | 10222 |
| 9920 void test_functionExpression_asInvocationArgument_notSubtypeOfStaticType() { | 10223 void test_functionExpression_asInvocationArgument_notSubtypeOfStaticType() { |
| 9921 String code = EngineTestCase.createSource([ | 10224 String code = r''' |
| 9922 "class A {", | 10225 class A { |
| 9923 " m(void f(int i)) {}", | 10226 m(void f(int i)) {} |
| 9924 "}", | 10227 } |
| 9925 "x() {", | 10228 x() { |
| 9926 " A a = new A();", | 10229 A a = new A(); |
| 9927 " a.m(() => 0);", | 10230 a.m(() => 0); |
| 9928 "}"]); | 10231 }'''; |
| 9929 Source source = addSource(code); | 10232 Source source = addSource(code); |
| 9930 LibraryElement library = resolve(source); | 10233 LibraryElement library = resolve(source); |
| 9931 assertErrors(source, [StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE]); | 10234 assertErrors(source, [StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE]); |
| 9932 verify([source]); | 10235 verify([source]); |
| 9933 CompilationUnit unit = resolveCompilationUnit(source, library); | 10236 CompilationUnit unit = resolveCompilationUnit(source, library); |
| 9934 // () => 0 | 10237 // () => 0 |
| 9935 FunctionExpression functionExpression = EngineTestCase.findNode(unit, code,
"() => 0)", (node) => node is FunctionExpression); | 10238 FunctionExpression functionExpression = EngineTestCase.findNode(unit, code,
"() => 0)", (node) => node is FunctionExpression); |
| 9936 JUnitTestCase.assertSame(0, (functionExpression.staticType as FunctionType).
parameters.length); | 10239 JUnitTestCase.assertSame(0, (functionExpression.staticType as FunctionType).
parameters.length); |
| 9937 JUnitTestCase.assertSame(null, functionExpression.propagatedType); | 10240 JUnitTestCase.assertSame(null, functionExpression.propagatedType); |
| 9938 } | 10241 } |
| 9939 | 10242 |
| 9940 void test_functionExpression_asInvocationArgument_replaceIfMoreSpecific() { | 10243 void test_functionExpression_asInvocationArgument_replaceIfMoreSpecific() { |
| 9941 String code = EngineTestCase.createSource([ | 10244 String code = r''' |
| 9942 "class MyList<E> {", | 10245 class MyList<E> { |
| 9943 " forEach(f(E value)) {}", | 10246 forEach(f(E value)) {} |
| 9944 "}", | 10247 } |
| 9945 "f(MyList<String> list) {", | 10248 f(MyList<String> list) { |
| 9946 " list.forEach((Object v) {", | 10249 list.forEach((Object v) { |
| 9947 " v;", | 10250 v; |
| 9948 " });", | 10251 }); |
| 9949 "}"]); | 10252 }'''; |
| 9950 Source source = addSource(code); | 10253 Source source = addSource(code); |
| 9951 LibraryElement library = resolve(source); | 10254 LibraryElement library = resolve(source); |
| 9952 assertNoErrors(source); | 10255 assertNoErrors(source); |
| 9953 verify([source]); | 10256 verify([source]); |
| 9954 CompilationUnit unit = resolveCompilationUnit(source, library); | 10257 CompilationUnit unit = resolveCompilationUnit(source, library); |
| 9955 // v | 10258 // v |
| 9956 DartType stringType = typeProvider.stringType; | 10259 DartType stringType = typeProvider.stringType; |
| 9957 FormalParameter vParameter = EngineTestCase.findNode(unit, code, "v)", (node
) => node is SimpleFormalParameter); | 10260 FormalParameter vParameter = EngineTestCase.findNode(unit, code, "v)", (node
) => node is SimpleFormalParameter); |
| 9958 JUnitTestCase.assertSame(stringType, vParameter.identifier.propagatedType); | 10261 JUnitTestCase.assertSame(stringType, vParameter.identifier.propagatedType); |
| 9959 JUnitTestCase.assertSame(typeProvider.objectType, vParameter.identifier.stat
icType); | 10262 JUnitTestCase.assertSame(typeProvider.objectType, vParameter.identifier.stat
icType); |
| 9960 SimpleIdentifier vIdentifier = EngineTestCase.findNode(unit, code, "v;", (no
de) => node is SimpleIdentifier); | 10263 SimpleIdentifier vIdentifier = EngineTestCase.findNode(unit, code, "v;", (no
de) => node is SimpleIdentifier); |
| 9961 JUnitTestCase.assertSame(stringType, vIdentifier.propagatedType); | 10264 JUnitTestCase.assertSame(stringType, vIdentifier.propagatedType); |
| 9962 } | 10265 } |
| 9963 | 10266 |
| 9964 void test_Future_then() { | 10267 void test_Future_then() { |
| 9965 String code = EngineTestCase.createSource([ | 10268 String code = r''' |
| 9966 "import 'dart:async';", | 10269 import 'dart:async'; |
| 9967 "main(Future<int> firstFuture) {", | 10270 main(Future<int> firstFuture) { |
| 9968 " firstFuture.then((p1) {", | 10271 firstFuture.then((p1) { |
| 9969 " return 1.0;", | 10272 return 1.0; |
| 9970 " }).then((p2) {", | 10273 }).then((p2) { |
| 9971 " return new Future<String>.value('str');", | 10274 return new Future<String>.value('str'); |
| 9972 " }).then((p3) {", | 10275 }).then((p3) { |
| 9973 " });", | 10276 }); |
| 9974 "}"]); | 10277 }'''; |
| 9975 Source source = addSource(code); | 10278 Source source = addSource(code); |
| 9976 LibraryElement library = resolve(source); | 10279 LibraryElement library = resolve(source); |
| 9977 assertNoErrors(source); | 10280 assertNoErrors(source); |
| 9978 verify([source]); | 10281 verify([source]); |
| 9979 CompilationUnit unit = resolveCompilationUnit(source, library); | 10282 CompilationUnit unit = resolveCompilationUnit(source, library); |
| 9980 // p1 | 10283 // p1 |
| 9981 FormalParameter p1 = EngineTestCase.findNode(unit, code, "p1) {", (node) =>
node is SimpleFormalParameter); | 10284 FormalParameter p1 = EngineTestCase.findNode(unit, code, "p1) {", (node) =>
node is SimpleFormalParameter); |
| 9982 JUnitTestCase.assertSame(typeProvider.intType, p1.identifier.propagatedType)
; | 10285 JUnitTestCase.assertSame(typeProvider.intType, p1.identifier.propagatedType)
; |
| 9983 // p2 | 10286 // p2 |
| 9984 FormalParameter p2 = EngineTestCase.findNode(unit, code, "p2) {", (node) =>
node is SimpleFormalParameter); | 10287 FormalParameter p2 = EngineTestCase.findNode(unit, code, "p2) {", (node) =>
node is SimpleFormalParameter); |
| 9985 JUnitTestCase.assertSame(typeProvider.doubleType, p2.identifier.propagatedTy
pe); | 10288 JUnitTestCase.assertSame(typeProvider.doubleType, p2.identifier.propagatedTy
pe); |
| 9986 // p3 | 10289 // p3 |
| 9987 FormalParameter p3 = EngineTestCase.findNode(unit, code, "p3) {", (node) =>
node is SimpleFormalParameter); | 10290 FormalParameter p3 = EngineTestCase.findNode(unit, code, "p3) {", (node) =>
node is SimpleFormalParameter); |
| 9988 JUnitTestCase.assertSame(typeProvider.stringType, p3.identifier.propagatedTy
pe); | 10291 JUnitTestCase.assertSame(typeProvider.stringType, p3.identifier.propagatedTy
pe); |
| 9989 } | 10292 } |
| 9990 | 10293 |
| 9991 void test_initializer() { | 10294 void test_initializer() { |
| 9992 Source source = addSource(EngineTestCase.createSource(["f() {", " var v = 0
;", " return v;", "}"])); | 10295 Source source = addSource(r''' |
| 10296 f() { |
| 10297 var v = 0; |
| 10298 return v; |
| 10299 }'''); |
| 9993 LibraryElement library = resolve(source); | 10300 LibraryElement library = resolve(source); |
| 9994 assertNoErrors(source); | 10301 assertNoErrors(source); |
| 9995 verify([source]); | 10302 verify([source]); |
| 9996 CompilationUnit unit = resolveCompilationUnit(source, library); | 10303 CompilationUnit unit = resolveCompilationUnit(source, library); |
| 9997 FunctionDeclaration function = unit.declarations[0] as FunctionDeclaration; | 10304 FunctionDeclaration function = unit.declarations[0] as FunctionDeclaration; |
| 9998 BlockFunctionBody body = function.functionExpression.body as BlockFunctionBo
dy; | 10305 BlockFunctionBody body = function.functionExpression.body as BlockFunctionBo
dy; |
| 9999 NodeList<Statement> statements = body.block.statements; | 10306 NodeList<Statement> statements = body.block.statements; |
| 10000 // Type of 'v' in declaration. | 10307 // Type of 'v' in declaration. |
| 10001 { | 10308 { |
| 10002 VariableDeclarationStatement statement = statements[0] as VariableDeclarat
ionStatement; | 10309 VariableDeclarationStatement statement = statements[0] as VariableDeclarat
ionStatement; |
| 10003 SimpleIdentifier variableName = statement.variables.variables[0].name; | 10310 SimpleIdentifier variableName = statement.variables.variables[0].name; |
| 10004 JUnitTestCase.assertSame(typeProvider.dynamicType, variableName.staticType
); | 10311 JUnitTestCase.assertSame(typeProvider.dynamicType, variableName.staticType
); |
| 10005 JUnitTestCase.assertSame(typeProvider.intType, variableName.propagatedType
); | 10312 JUnitTestCase.assertSame(typeProvider.intType, variableName.propagatedType
); |
| 10006 } | 10313 } |
| 10007 // Type of 'v' in reference. | 10314 // Type of 'v' in reference. |
| 10008 { | 10315 { |
| 10009 ReturnStatement statement = statements[1] as ReturnStatement; | 10316 ReturnStatement statement = statements[1] as ReturnStatement; |
| 10010 SimpleIdentifier variableName = statement.expression as SimpleIdentifier; | 10317 SimpleIdentifier variableName = statement.expression as SimpleIdentifier; |
| 10011 JUnitTestCase.assertSame(typeProvider.intType, variableName.propagatedType
); | 10318 JUnitTestCase.assertSame(typeProvider.intType, variableName.propagatedType
); |
| 10012 } | 10319 } |
| 10013 } | 10320 } |
| 10014 | 10321 |
| 10015 void test_initializer_dereference() { | 10322 void test_initializer_dereference() { |
| 10016 Source source = addSource(EngineTestCase.createSource(["f() {", " var v = '
String';", " v.", "}"])); | 10323 Source source = addSource(r''' |
| 10324 f() { |
| 10325 var v = 'String'; |
| 10326 v. |
| 10327 }'''); |
| 10017 LibraryElement library = resolve(source); | 10328 LibraryElement library = resolve(source); |
| 10018 CompilationUnit unit = resolveCompilationUnit(source, library); | 10329 CompilationUnit unit = resolveCompilationUnit(source, library); |
| 10019 FunctionDeclaration function = unit.declarations[0] as FunctionDeclaration; | 10330 FunctionDeclaration function = unit.declarations[0] as FunctionDeclaration; |
| 10020 BlockFunctionBody body = function.functionExpression.body as BlockFunctionBo
dy; | 10331 BlockFunctionBody body = function.functionExpression.body as BlockFunctionBo
dy; |
| 10021 ExpressionStatement statement = body.block.statements[1] as ExpressionStatem
ent; | 10332 ExpressionStatement statement = body.block.statements[1] as ExpressionStatem
ent; |
| 10022 PrefixedIdentifier invocation = statement.expression as PrefixedIdentifier; | 10333 PrefixedIdentifier invocation = statement.expression as PrefixedIdentifier; |
| 10023 SimpleIdentifier variableName = invocation.prefix; | 10334 SimpleIdentifier variableName = invocation.prefix; |
| 10024 JUnitTestCase.assertSame(typeProvider.stringType, variableName.propagatedTyp
e); | 10335 JUnitTestCase.assertSame(typeProvider.stringType, variableName.propagatedTyp
e); |
| 10025 } | 10336 } |
| 10026 | 10337 |
| 10027 void test_initializer_null() { | 10338 void test_initializer_null() { |
| 10028 String code = EngineTestCase.createSource([ | 10339 String code = r''' |
| 10029 "main() {", | 10340 main() { |
| 10030 " int v = null;", | 10341 int v = null; |
| 10031 " return v; // marker", | 10342 return v; // marker |
| 10032 "}"]); | 10343 }'''; |
| 10033 CompilationUnit unit; | 10344 CompilationUnit unit; |
| 10034 { | 10345 { |
| 10035 Source source = addSource(code); | 10346 Source source = addSource(code); |
| 10036 LibraryElement library = resolve(source); | 10347 LibraryElement library = resolve(source); |
| 10037 assertNoErrors(source); | 10348 assertNoErrors(source); |
| 10038 verify([source]); | 10349 verify([source]); |
| 10039 unit = resolveCompilationUnit(source, library); | 10350 unit = resolveCompilationUnit(source, library); |
| 10040 } | 10351 } |
| 10041 { | 10352 { |
| 10042 SimpleIdentifier identifier = EngineTestCase.findNode(unit, code, "v = nul
l;", (node) => node is SimpleIdentifier); | 10353 SimpleIdentifier identifier = EngineTestCase.findNode(unit, code, "v = nul
l;", (node) => node is SimpleIdentifier); |
| 10043 JUnitTestCase.assertSame(typeProvider.intType, identifier.staticType); | 10354 JUnitTestCase.assertSame(typeProvider.intType, identifier.staticType); |
| 10044 JUnitTestCase.assertSame(null, identifier.propagatedType); | 10355 JUnitTestCase.assertSame(null, identifier.propagatedType); |
| 10045 } | 10356 } |
| 10046 { | 10357 { |
| 10047 SimpleIdentifier identifier = EngineTestCase.findNode(unit, code, "v; // m
arker", (node) => node is SimpleIdentifier); | 10358 SimpleIdentifier identifier = EngineTestCase.findNode(unit, code, "v; // m
arker", (node) => node is SimpleIdentifier); |
| 10048 JUnitTestCase.assertSame(typeProvider.intType, identifier.staticType); | 10359 JUnitTestCase.assertSame(typeProvider.intType, identifier.staticType); |
| 10049 JUnitTestCase.assertSame(null, identifier.propagatedType); | 10360 JUnitTestCase.assertSame(null, identifier.propagatedType); |
| 10050 } | 10361 } |
| 10051 } | 10362 } |
| 10052 | 10363 |
| 10053 void test_is_conditional() { | 10364 void test_is_conditional() { |
| 10054 Source source = addSource(EngineTestCase.createSource([ | 10365 Source source = addSource(r''' |
| 10055 "class A {}", | 10366 class A {} |
| 10056 "A f(var p) {", | 10367 A f(var p) { |
| 10057 " return (p is A) ? p : null;", | 10368 return (p is A) ? p : null; |
| 10058 "}"])); | 10369 }'''); |
| 10059 LibraryElement library = resolve(source); | 10370 LibraryElement library = resolve(source); |
| 10060 assertNoErrors(source); | 10371 assertNoErrors(source); |
| 10061 verify([source]); | 10372 verify([source]); |
| 10062 CompilationUnit unit = resolveCompilationUnit(source, library); | 10373 CompilationUnit unit = resolveCompilationUnit(source, library); |
| 10063 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration; | 10374 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration; |
| 10064 InterfaceType typeA = classA.element.type; | 10375 InterfaceType typeA = classA.element.type; |
| 10065 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration; | 10376 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration; |
| 10066 BlockFunctionBody body = function.functionExpression.body as BlockFunctionBo
dy; | 10377 BlockFunctionBody body = function.functionExpression.body as BlockFunctionBo
dy; |
| 10067 ReturnStatement statement = body.block.statements[0] as ReturnStatement; | 10378 ReturnStatement statement = body.block.statements[0] as ReturnStatement; |
| 10068 ConditionalExpression conditional = statement.expression as ConditionalExpre
ssion; | 10379 ConditionalExpression conditional = statement.expression as ConditionalExpre
ssion; |
| 10069 SimpleIdentifier variableName = conditional.thenExpression as SimpleIdentifi
er; | 10380 SimpleIdentifier variableName = conditional.thenExpression as SimpleIdentifi
er; |
| 10070 JUnitTestCase.assertSame(typeA, variableName.propagatedType); | 10381 JUnitTestCase.assertSame(typeA, variableName.propagatedType); |
| 10071 } | 10382 } |
| 10072 | 10383 |
| 10073 void test_is_if() { | 10384 void test_is_if() { |
| 10074 Source source = addSource(EngineTestCase.createSource([ | 10385 Source source = addSource(r''' |
| 10075 "class A {}", | 10386 class A {} |
| 10076 "A f(var p) {", | 10387 A f(var p) { |
| 10077 " if (p is A) {", | 10388 if (p is A) { |
| 10078 " return p;", | 10389 return p; |
| 10079 " } else {", | 10390 } else { |
| 10080 " return null;", | 10391 return null; |
| 10081 " }", | 10392 } |
| 10082 "}"])); | 10393 }'''); |
| 10083 LibraryElement library = resolve(source); | 10394 LibraryElement library = resolve(source); |
| 10084 assertNoErrors(source); | 10395 assertNoErrors(source); |
| 10085 verify([source]); | 10396 verify([source]); |
| 10086 CompilationUnit unit = resolveCompilationUnit(source, library); | 10397 CompilationUnit unit = resolveCompilationUnit(source, library); |
| 10087 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration; | 10398 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration; |
| 10088 InterfaceType typeA = classA.element.type; | 10399 InterfaceType typeA = classA.element.type; |
| 10089 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration; | 10400 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration; |
| 10090 BlockFunctionBody body = function.functionExpression.body as BlockFunctionBo
dy; | 10401 BlockFunctionBody body = function.functionExpression.body as BlockFunctionBo
dy; |
| 10091 IfStatement ifStatement = body.block.statements[0] as IfStatement; | 10402 IfStatement ifStatement = body.block.statements[0] as IfStatement; |
| 10092 ReturnStatement statement = (ifStatement.thenStatement as Block).statements[
0] as ReturnStatement; | 10403 ReturnStatement statement = (ifStatement.thenStatement as Block).statements[
0] as ReturnStatement; |
| 10093 SimpleIdentifier variableName = statement.expression as SimpleIdentifier; | 10404 SimpleIdentifier variableName = statement.expression as SimpleIdentifier; |
| 10094 JUnitTestCase.assertSame(typeA, variableName.propagatedType); | 10405 JUnitTestCase.assertSame(typeA, variableName.propagatedType); |
| 10095 } | 10406 } |
| 10096 | 10407 |
| 10097 void test_is_if_lessSpecific() { | 10408 void test_is_if_lessSpecific() { |
| 10098 Source source = addSource(EngineTestCase.createSource([ | 10409 Source source = addSource(r''' |
| 10099 "class A {}", | 10410 class A {} |
| 10100 "A f(A p) {", | 10411 A f(A p) { |
| 10101 " if (p is String) {", | 10412 if (p is String) { |
| 10102 " return p;", | 10413 return p; |
| 10103 " } else {", | 10414 } else { |
| 10104 " return null;", | 10415 return null; |
| 10105 " }", | 10416 } |
| 10106 "}"])); | 10417 }'''); |
| 10107 LibraryElement library = resolve(source); | 10418 LibraryElement library = resolve(source); |
| 10108 assertNoErrors(source); | 10419 assertNoErrors(source); |
| 10109 verify([source]); | 10420 verify([source]); |
| 10110 CompilationUnit unit = resolveCompilationUnit(source, library); | 10421 CompilationUnit unit = resolveCompilationUnit(source, library); |
| 10111 // ClassDeclaration classA = (ClassDeclaration) unit.getDeclarations().ge
t(0); | 10422 // ClassDeclaration classA = (ClassDeclaration) unit.getDeclarations().ge
t(0); |
| 10112 // InterfaceType typeA = classA.getElement().getType(); | 10423 // InterfaceType typeA = classA.getElement().getType(); |
| 10113 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration; | 10424 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration; |
| 10114 BlockFunctionBody body = function.functionExpression.body as BlockFunctionBo
dy; | 10425 BlockFunctionBody body = function.functionExpression.body as BlockFunctionBo
dy; |
| 10115 IfStatement ifStatement = body.block.statements[0] as IfStatement; | 10426 IfStatement ifStatement = body.block.statements[0] as IfStatement; |
| 10116 ReturnStatement statement = (ifStatement.thenStatement as Block).statements[
0] as ReturnStatement; | 10427 ReturnStatement statement = (ifStatement.thenStatement as Block).statements[
0] as ReturnStatement; |
| 10117 SimpleIdentifier variableName = statement.expression as SimpleIdentifier; | 10428 SimpleIdentifier variableName = statement.expression as SimpleIdentifier; |
| 10118 JUnitTestCase.assertSame(null, variableName.propagatedType); | 10429 JUnitTestCase.assertSame(null, variableName.propagatedType); |
| 10119 } | 10430 } |
| 10120 | 10431 |
| 10121 void test_is_if_logicalAnd() { | 10432 void test_is_if_logicalAnd() { |
| 10122 Source source = addSource(EngineTestCase.createSource([ | 10433 Source source = addSource(r''' |
| 10123 "class A {}", | 10434 class A {} |
| 10124 "A f(var p) {", | 10435 A f(var p) { |
| 10125 " if (p is A && p != null) {", | 10436 if (p is A && p != null) { |
| 10126 " return p;", | 10437 return p; |
| 10127 " } else {", | 10438 } else { |
| 10128 " return null;", | 10439 return null; |
| 10129 " }", | 10440 } |
| 10130 "}"])); | 10441 }'''); |
| 10131 LibraryElement library = resolve(source); | 10442 LibraryElement library = resolve(source); |
| 10132 assertNoErrors(source); | 10443 assertNoErrors(source); |
| 10133 verify([source]); | 10444 verify([source]); |
| 10134 CompilationUnit unit = resolveCompilationUnit(source, library); | 10445 CompilationUnit unit = resolveCompilationUnit(source, library); |
| 10135 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration; | 10446 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration; |
| 10136 InterfaceType typeA = classA.element.type; | 10447 InterfaceType typeA = classA.element.type; |
| 10137 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration; | 10448 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration; |
| 10138 BlockFunctionBody body = function.functionExpression.body as BlockFunctionBo
dy; | 10449 BlockFunctionBody body = function.functionExpression.body as BlockFunctionBo
dy; |
| 10139 IfStatement ifStatement = body.block.statements[0] as IfStatement; | 10450 IfStatement ifStatement = body.block.statements[0] as IfStatement; |
| 10140 ReturnStatement statement = (ifStatement.thenStatement as Block).statements[
0] as ReturnStatement; | 10451 ReturnStatement statement = (ifStatement.thenStatement as Block).statements[
0] as ReturnStatement; |
| 10141 SimpleIdentifier variableName = statement.expression as SimpleIdentifier; | 10452 SimpleIdentifier variableName = statement.expression as SimpleIdentifier; |
| 10142 JUnitTestCase.assertSame(typeA, variableName.propagatedType); | 10453 JUnitTestCase.assertSame(typeA, variableName.propagatedType); |
| 10143 } | 10454 } |
| 10144 | 10455 |
| 10145 void test_is_postConditional() { | 10456 void test_is_postConditional() { |
| 10146 Source source = addSource(EngineTestCase.createSource([ | 10457 Source source = addSource(r''' |
| 10147 "class A {}", | 10458 class A {} |
| 10148 "A f(var p) {", | 10459 A f(var p) { |
| 10149 " A a = (p is A) ? p : throw null;", | 10460 A a = (p is A) ? p : throw null; |
| 10150 " return p;", | 10461 return p; |
| 10151 "}"])); | 10462 }'''); |
| 10152 LibraryElement library = resolve(source); | 10463 LibraryElement library = resolve(source); |
| 10153 assertNoErrors(source); | 10464 assertNoErrors(source); |
| 10154 verify([source]); | 10465 verify([source]); |
| 10155 CompilationUnit unit = resolveCompilationUnit(source, library); | 10466 CompilationUnit unit = resolveCompilationUnit(source, library); |
| 10156 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration; | 10467 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration; |
| 10157 InterfaceType typeA = classA.element.type; | 10468 InterfaceType typeA = classA.element.type; |
| 10158 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration; | 10469 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration; |
| 10159 BlockFunctionBody body = function.functionExpression.body as BlockFunctionBo
dy; | 10470 BlockFunctionBody body = function.functionExpression.body as BlockFunctionBo
dy; |
| 10160 ReturnStatement statement = body.block.statements[1] as ReturnStatement; | 10471 ReturnStatement statement = body.block.statements[1] as ReturnStatement; |
| 10161 SimpleIdentifier variableName = statement.expression as SimpleIdentifier; | 10472 SimpleIdentifier variableName = statement.expression as SimpleIdentifier; |
| 10162 JUnitTestCase.assertSame(typeA, variableName.propagatedType); | 10473 JUnitTestCase.assertSame(typeA, variableName.propagatedType); |
| 10163 } | 10474 } |
| 10164 | 10475 |
| 10165 void test_is_postIf() { | 10476 void test_is_postIf() { |
| 10166 Source source = addSource(EngineTestCase.createSource([ | 10477 Source source = addSource(r''' |
| 10167 "class A {}", | 10478 class A {} |
| 10168 "A f(var p) {", | 10479 A f(var p) { |
| 10169 " if (p is A) {", | 10480 if (p is A) { |
| 10170 " A a = p;", | 10481 A a = p; |
| 10171 " } else {", | 10482 } else { |
| 10172 " return null;", | 10483 return null; |
| 10173 " }", | 10484 } |
| 10174 " return p;", | 10485 return p; |
| 10175 "}"])); | 10486 }'''); |
| 10176 LibraryElement library = resolve(source); | 10487 LibraryElement library = resolve(source); |
| 10177 assertNoErrors(source); | 10488 assertNoErrors(source); |
| 10178 verify([source]); | 10489 verify([source]); |
| 10179 CompilationUnit unit = resolveCompilationUnit(source, library); | 10490 CompilationUnit unit = resolveCompilationUnit(source, library); |
| 10180 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration; | 10491 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration; |
| 10181 InterfaceType typeA = classA.element.type; | 10492 InterfaceType typeA = classA.element.type; |
| 10182 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration; | 10493 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration; |
| 10183 BlockFunctionBody body = function.functionExpression.body as BlockFunctionBo
dy; | 10494 BlockFunctionBody body = function.functionExpression.body as BlockFunctionBo
dy; |
| 10184 ReturnStatement statement = body.block.statements[1] as ReturnStatement; | 10495 ReturnStatement statement = body.block.statements[1] as ReturnStatement; |
| 10185 SimpleIdentifier variableName = statement.expression as SimpleIdentifier; | 10496 SimpleIdentifier variableName = statement.expression as SimpleIdentifier; |
| 10186 JUnitTestCase.assertSame(typeA, variableName.propagatedType); | 10497 JUnitTestCase.assertSame(typeA, variableName.propagatedType); |
| 10187 } | 10498 } |
| 10188 | 10499 |
| 10189 void test_is_subclass() { | 10500 void test_is_subclass() { |
| 10190 Source source = addSource(EngineTestCase.createSource([ | 10501 Source source = addSource(r''' |
| 10191 "class A {}", | 10502 class A {} |
| 10192 "class B extends A {", | 10503 class B extends A { |
| 10193 " B m() => this;", | 10504 B m() => this; |
| 10194 "}", | 10505 } |
| 10195 "A f(A p) {", | 10506 A f(A p) { |
| 10196 " if (p is B) {", | 10507 if (p is B) { |
| 10197 " return p.m();", | 10508 return p.m(); |
| 10198 " }", | 10509 } |
| 10199 " return p;", | 10510 return p; |
| 10200 "}"])); | 10511 }'''); |
| 10201 LibraryElement library = resolve(source); | 10512 LibraryElement library = resolve(source); |
| 10202 assertNoErrors(source); | 10513 assertNoErrors(source); |
| 10203 CompilationUnit unit = resolveCompilationUnit(source, library); | 10514 CompilationUnit unit = resolveCompilationUnit(source, library); |
| 10204 FunctionDeclaration function = unit.declarations[2] as FunctionDeclaration; | 10515 FunctionDeclaration function = unit.declarations[2] as FunctionDeclaration; |
| 10205 BlockFunctionBody body = function.functionExpression.body as BlockFunctionBo
dy; | 10516 BlockFunctionBody body = function.functionExpression.body as BlockFunctionBo
dy; |
| 10206 IfStatement ifStatement = body.block.statements[0] as IfStatement; | 10517 IfStatement ifStatement = body.block.statements[0] as IfStatement; |
| 10207 ReturnStatement statement = (ifStatement.thenStatement as Block).statements[
0] as ReturnStatement; | 10518 ReturnStatement statement = (ifStatement.thenStatement as Block).statements[
0] as ReturnStatement; |
| 10208 MethodInvocation invocation = statement.expression as MethodInvocation; | 10519 MethodInvocation invocation = statement.expression as MethodInvocation; |
| 10209 JUnitTestCase.assertNotNull(invocation.methodName.propagatedElement); | 10520 JUnitTestCase.assertNotNull(invocation.methodName.propagatedElement); |
| 10210 } | 10521 } |
| 10211 | 10522 |
| 10212 void test_is_while() { | 10523 void test_is_while() { |
| 10213 Source source = addSource(EngineTestCase.createSource([ | 10524 Source source = addSource(r''' |
| 10214 "class A {}", | 10525 class A {} |
| 10215 "A f(var p) {", | 10526 A f(var p) { |
| 10216 " while (p is A) {", | 10527 while (p is A) { |
| 10217 " return p;", | 10528 return p; |
| 10218 " }", | 10529 } |
| 10219 " return p;", | 10530 return p; |
| 10220 "}"])); | 10531 }'''); |
| 10221 LibraryElement library = resolve(source); | 10532 LibraryElement library = resolve(source); |
| 10222 assertNoErrors(source); | 10533 assertNoErrors(source); |
| 10223 verify([source]); | 10534 verify([source]); |
| 10224 CompilationUnit unit = resolveCompilationUnit(source, library); | 10535 CompilationUnit unit = resolveCompilationUnit(source, library); |
| 10225 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration; | 10536 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration; |
| 10226 InterfaceType typeA = classA.element.type; | 10537 InterfaceType typeA = classA.element.type; |
| 10227 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration; | 10538 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration; |
| 10228 BlockFunctionBody body = function.functionExpression.body as BlockFunctionBo
dy; | 10539 BlockFunctionBody body = function.functionExpression.body as BlockFunctionBo
dy; |
| 10229 WhileStatement whileStatement = body.block.statements[0] as WhileStatement; | 10540 WhileStatement whileStatement = body.block.statements[0] as WhileStatement; |
| 10230 ReturnStatement statement = (whileStatement.body as Block).statements[0] as
ReturnStatement; | 10541 ReturnStatement statement = (whileStatement.body as Block).statements[0] as
ReturnStatement; |
| 10231 SimpleIdentifier variableName = statement.expression as SimpleIdentifier; | 10542 SimpleIdentifier variableName = statement.expression as SimpleIdentifier; |
| 10232 JUnitTestCase.assertSame(typeA, variableName.propagatedType); | 10543 JUnitTestCase.assertSame(typeA, variableName.propagatedType); |
| 10233 } | 10544 } |
| 10234 | 10545 |
| 10235 void test_isNot_conditional() { | 10546 void test_isNot_conditional() { |
| 10236 Source source = addSource(EngineTestCase.createSource([ | 10547 Source source = addSource(r''' |
| 10237 "class A {}", | 10548 class A {} |
| 10238 "A f(var p) {", | 10549 A f(var p) { |
| 10239 " return (p is! A) ? null : p;", | 10550 return (p is! A) ? null : p; |
| 10240 "}"])); | 10551 }'''); |
| 10241 LibraryElement library = resolve(source); | 10552 LibraryElement library = resolve(source); |
| 10242 assertNoErrors(source); | 10553 assertNoErrors(source); |
| 10243 verify([source]); | 10554 verify([source]); |
| 10244 CompilationUnit unit = resolveCompilationUnit(source, library); | 10555 CompilationUnit unit = resolveCompilationUnit(source, library); |
| 10245 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration; | 10556 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration; |
| 10246 InterfaceType typeA = classA.element.type; | 10557 InterfaceType typeA = classA.element.type; |
| 10247 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration; | 10558 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration; |
| 10248 BlockFunctionBody body = function.functionExpression.body as BlockFunctionBo
dy; | 10559 BlockFunctionBody body = function.functionExpression.body as BlockFunctionBo
dy; |
| 10249 ReturnStatement statement = body.block.statements[0] as ReturnStatement; | 10560 ReturnStatement statement = body.block.statements[0] as ReturnStatement; |
| 10250 ConditionalExpression conditional = statement.expression as ConditionalExpre
ssion; | 10561 ConditionalExpression conditional = statement.expression as ConditionalExpre
ssion; |
| 10251 SimpleIdentifier variableName = conditional.elseExpression as SimpleIdentifi
er; | 10562 SimpleIdentifier variableName = conditional.elseExpression as SimpleIdentifi
er; |
| 10252 JUnitTestCase.assertSame(typeA, variableName.propagatedType); | 10563 JUnitTestCase.assertSame(typeA, variableName.propagatedType); |
| 10253 } | 10564 } |
| 10254 | 10565 |
| 10255 void test_isNot_if() { | 10566 void test_isNot_if() { |
| 10256 Source source = addSource(EngineTestCase.createSource([ | 10567 Source source = addSource(r''' |
| 10257 "class A {}", | 10568 class A {} |
| 10258 "A f(var p) {", | 10569 A f(var p) { |
| 10259 " if (p is! A) {", | 10570 if (p is! A) { |
| 10260 " return null;", | 10571 return null; |
| 10261 " } else {", | 10572 } else { |
| 10262 " return p;", | 10573 return p; |
| 10263 " }", | 10574 } |
| 10264 "}"])); | 10575 }'''); |
| 10265 LibraryElement library = resolve(source); | 10576 LibraryElement library = resolve(source); |
| 10266 assertNoErrors(source); | 10577 assertNoErrors(source); |
| 10267 verify([source]); | 10578 verify([source]); |
| 10268 CompilationUnit unit = resolveCompilationUnit(source, library); | 10579 CompilationUnit unit = resolveCompilationUnit(source, library); |
| 10269 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration; | 10580 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration; |
| 10270 InterfaceType typeA = classA.element.type; | 10581 InterfaceType typeA = classA.element.type; |
| 10271 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration; | 10582 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration; |
| 10272 BlockFunctionBody body = function.functionExpression.body as BlockFunctionBo
dy; | 10583 BlockFunctionBody body = function.functionExpression.body as BlockFunctionBo
dy; |
| 10273 IfStatement ifStatement = body.block.statements[0] as IfStatement; | 10584 IfStatement ifStatement = body.block.statements[0] as IfStatement; |
| 10274 ReturnStatement statement = (ifStatement.elseStatement as Block).statements[
0] as ReturnStatement; | 10585 ReturnStatement statement = (ifStatement.elseStatement as Block).statements[
0] as ReturnStatement; |
| 10275 SimpleIdentifier variableName = statement.expression as SimpleIdentifier; | 10586 SimpleIdentifier variableName = statement.expression as SimpleIdentifier; |
| 10276 JUnitTestCase.assertSame(typeA, variableName.propagatedType); | 10587 JUnitTestCase.assertSame(typeA, variableName.propagatedType); |
| 10277 } | 10588 } |
| 10278 | 10589 |
| 10279 void test_isNot_if_logicalOr() { | 10590 void test_isNot_if_logicalOr() { |
| 10280 Source source = addSource(EngineTestCase.createSource([ | 10591 Source source = addSource(r''' |
| 10281 "class A {}", | 10592 class A {} |
| 10282 "A f(var p) {", | 10593 A f(var p) { |
| 10283 " if (p is! A || null == p) {", | 10594 if (p is! A || null == p) { |
| 10284 " return null;", | 10595 return null; |
| 10285 " } else {", | 10596 } else { |
| 10286 " return p;", | 10597 return p; |
| 10287 " }", | 10598 } |
| 10288 "}"])); | 10599 }'''); |
| 10289 LibraryElement library = resolve(source); | 10600 LibraryElement library = resolve(source); |
| 10290 assertNoErrors(source); | 10601 assertNoErrors(source); |
| 10291 CompilationUnit unit = resolveCompilationUnit(source, library); | 10602 CompilationUnit unit = resolveCompilationUnit(source, library); |
| 10292 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration; | 10603 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration; |
| 10293 InterfaceType typeA = classA.element.type; | 10604 InterfaceType typeA = classA.element.type; |
| 10294 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration; | 10605 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration; |
| 10295 BlockFunctionBody body = function.functionExpression.body as BlockFunctionBo
dy; | 10606 BlockFunctionBody body = function.functionExpression.body as BlockFunctionBo
dy; |
| 10296 IfStatement ifStatement = body.block.statements[0] as IfStatement; | 10607 IfStatement ifStatement = body.block.statements[0] as IfStatement; |
| 10297 ReturnStatement statement = (ifStatement.elseStatement as Block).statements[
0] as ReturnStatement; | 10608 ReturnStatement statement = (ifStatement.elseStatement as Block).statements[
0] as ReturnStatement; |
| 10298 SimpleIdentifier variableName = statement.expression as SimpleIdentifier; | 10609 SimpleIdentifier variableName = statement.expression as SimpleIdentifier; |
| 10299 JUnitTestCase.assertSame(typeA, variableName.propagatedType); | 10610 JUnitTestCase.assertSame(typeA, variableName.propagatedType); |
| 10300 } | 10611 } |
| 10301 | 10612 |
| 10302 void test_isNot_postConditional() { | 10613 void test_isNot_postConditional() { |
| 10303 Source source = addSource(EngineTestCase.createSource([ | 10614 Source source = addSource(r''' |
| 10304 "class A {}", | 10615 class A {} |
| 10305 "A f(var p) {", | 10616 A f(var p) { |
| 10306 " A a = (p is! A) ? throw null : p;", | 10617 A a = (p is! A) ? throw null : p; |
| 10307 " return p;", | 10618 return p; |
| 10308 "}"])); | 10619 }'''); |
| 10309 LibraryElement library = resolve(source); | 10620 LibraryElement library = resolve(source); |
| 10310 assertNoErrors(source); | 10621 assertNoErrors(source); |
| 10311 verify([source]); | 10622 verify([source]); |
| 10312 CompilationUnit unit = resolveCompilationUnit(source, library); | 10623 CompilationUnit unit = resolveCompilationUnit(source, library); |
| 10313 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration; | 10624 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration; |
| 10314 InterfaceType typeA = classA.element.type; | 10625 InterfaceType typeA = classA.element.type; |
| 10315 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration; | 10626 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration; |
| 10316 BlockFunctionBody body = function.functionExpression.body as BlockFunctionBo
dy; | 10627 BlockFunctionBody body = function.functionExpression.body as BlockFunctionBo
dy; |
| 10317 ReturnStatement statement = body.block.statements[1] as ReturnStatement; | 10628 ReturnStatement statement = body.block.statements[1] as ReturnStatement; |
| 10318 SimpleIdentifier variableName = statement.expression as SimpleIdentifier; | 10629 SimpleIdentifier variableName = statement.expression as SimpleIdentifier; |
| 10319 JUnitTestCase.assertSame(typeA, variableName.propagatedType); | 10630 JUnitTestCase.assertSame(typeA, variableName.propagatedType); |
| 10320 } | 10631 } |
| 10321 | 10632 |
| 10322 void test_isNot_postIf() { | 10633 void test_isNot_postIf() { |
| 10323 Source source = addSource(EngineTestCase.createSource([ | 10634 Source source = addSource(r''' |
| 10324 "class A {}", | 10635 class A {} |
| 10325 "A f(var p) {", | 10636 A f(var p) { |
| 10326 " if (p is! A) {", | 10637 if (p is! A) { |
| 10327 " return null;", | 10638 return null; |
| 10328 " }", | 10639 } |
| 10329 " return p;", | 10640 return p; |
| 10330 "}"])); | 10641 }'''); |
| 10331 LibraryElement library = resolve(source); | 10642 LibraryElement library = resolve(source); |
| 10332 assertNoErrors(source); | 10643 assertNoErrors(source); |
| 10333 verify([source]); | 10644 verify([source]); |
| 10334 CompilationUnit unit = resolveCompilationUnit(source, library); | 10645 CompilationUnit unit = resolveCompilationUnit(source, library); |
| 10335 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration; | 10646 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration; |
| 10336 InterfaceType typeA = classA.element.type; | 10647 InterfaceType typeA = classA.element.type; |
| 10337 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration; | 10648 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration; |
| 10338 BlockFunctionBody body = function.functionExpression.body as BlockFunctionBo
dy; | 10649 BlockFunctionBody body = function.functionExpression.body as BlockFunctionBo
dy; |
| 10339 ReturnStatement statement = body.block.statements[1] as ReturnStatement; | 10650 ReturnStatement statement = body.block.statements[1] as ReturnStatement; |
| 10340 SimpleIdentifier variableName = statement.expression as SimpleIdentifier; | 10651 SimpleIdentifier variableName = statement.expression as SimpleIdentifier; |
| 10341 JUnitTestCase.assertSame(typeA, variableName.propagatedType); | 10652 JUnitTestCase.assertSame(typeA, variableName.propagatedType); |
| 10342 } | 10653 } |
| 10343 | 10654 |
| 10344 void test_issue20904BuggyTypePromotionAtIfJoin_2() { | 10655 void test_issue20904BuggyTypePromotionAtIfJoin_2() { |
| 10345 // https://code.google.com/p/dart/issues/detail?id=20904 | 10656 // https://code.google.com/p/dart/issues/detail?id=20904 |
| 10346 enableUnionTypes(false); | 10657 enableUnionTypes(false); |
| 10347 String code = EngineTestCase.createSource([ | 10658 String code = r''' |
| 10348 "f(var message) {", | 10659 f(var message) { |
| 10349 " if (message is Function) {", | 10660 if (message is Function) { |
| 10350 " message = '';", | 10661 message = ''; |
| 10351 " }", | 10662 } |
| 10352 " message; // marker", | 10663 message; // marker |
| 10353 "}"]); | 10664 }'''; |
| 10354 DartType t = _findMarkedIdentifier(code, "; // marker").propagatedType; | 10665 DartType t = _findMarkedIdentifier(code, "; // marker").propagatedType; |
| 10355 JUnitTestCase.assertFalse(typeProvider.stringType == t); | 10666 JUnitTestCase.assertFalse(typeProvider.stringType == t); |
| 10356 JUnitTestCase.assertFalse(typeProvider.functionType == t); | 10667 JUnitTestCase.assertFalse(typeProvider.functionType == t); |
| 10357 } | 10668 } |
| 10358 | 10669 |
| 10359 void test_issue20904BuggyTypePromotionAtIfJoin_5() { | 10670 void test_issue20904BuggyTypePromotionAtIfJoin_5() { |
| 10360 // https://code.google.com/p/dart/issues/detail?id=20904 | 10671 // https://code.google.com/p/dart/issues/detail?id=20904 |
| 10361 // | 10672 // |
| 10362 // This is not an example of the 20904 bug, but rather, | 10673 // This is not an example of the 20904 bug, but rather, |
| 10363 // an example of something that one obvious fix changes inadvertently: we | 10674 // an example of something that one obvious fix changes inadvertently: we |
| 10364 // want to avoid using type information from is-checks when it | 10675 // want to avoid using type information from is-checks when it |
| 10365 // loses precision. I can't see how to get a bad hint this way, since | 10676 // loses precision. I can't see how to get a bad hint this way, since |
| 10366 // it seems the propagated type is not used to generate hints when a | 10677 // it seems the propagated type is not used to generate hints when a |
| 10367 // more precise type would cause no hint. For example, for code like the | 10678 // more precise type would cause no hint. For example, for code like the |
| 10368 // following, when the propagated type of [x] is [A] -- as happens for the | 10679 // following, when the propagated type of [x] is [A] -- as happens for the |
| 10369 // fix these tests aim to warn against -- there is no warning for | 10680 // fix these tests aim to warn against -- there is no warning for |
| 10370 // calling a method defined on [B] but not [A] (there aren't any, but preten
d), | 10681 // calling a method defined on [B] but not [A] (there aren't any, but preten
d), |
| 10371 // but there is for calling a method not defined on either. | 10682 // but there is for calling a method not defined on either. |
| 10372 // By not overriding the propagated type via an is-check that loses | 10683 // By not overriding the propagated type via an is-check that loses |
| 10373 // precision, we get more precise completion under an is-check. However, | 10684 // precision, we get more precise completion under an is-check. However, |
| 10374 // I can only imagine strange code would make use of this feature. | 10685 // I can only imagine strange code would make use of this feature. |
| 10375 // | 10686 // |
| 10376 // Here the is-check improves precision, so we use it. | 10687 // Here the is-check improves precision, so we use it. |
| 10377 String code = EngineTestCase.createSource([ | 10688 String code = r''' |
| 10378 "class A {}", | 10689 class A {} |
| 10379 "class B extends A {}", | 10690 class B extends A {} |
| 10380 "f() {", | 10691 f() { |
| 10381 " var a = new A();", | 10692 var a = new A(); |
| 10382 " var b = new B();", | 10693 var b = new B(); |
| 10383 " b; // B", | 10694 b; // B |
| 10384 " if (a is B) {", | 10695 if (a is B) { |
| 10385 " return a; // marker", | 10696 return a; // marker |
| 10386 " }", | 10697 } |
| 10387 "}"]); | 10698 }'''; |
| 10388 DartType tB = _findMarkedIdentifier(code, "; // B").propagatedType; | 10699 DartType tB = _findMarkedIdentifier(code, "; // B").propagatedType; |
| 10389 _assertTypeOfMarkedExpression(code, null, tB); | 10700 _assertTypeOfMarkedExpression(code, null, tB); |
| 10390 } | 10701 } |
| 10391 | 10702 |
| 10392 void test_issue20904BuggyTypePromotionAtIfJoin_6() { | 10703 void test_issue20904BuggyTypePromotionAtIfJoin_6() { |
| 10393 // https://code.google.com/p/dart/issues/detail?id=20904 | 10704 // https://code.google.com/p/dart/issues/detail?id=20904 |
| 10394 // | 10705 // |
| 10395 // The other half of the *_5() test. | 10706 // The other half of the *_5() test. |
| 10396 // | 10707 // |
| 10397 // Here the is-check loses precision, so we don't use it. | 10708 // Here the is-check loses precision, so we don't use it. |
| 10398 String code = EngineTestCase.createSource([ | 10709 String code = r''' |
| 10399 "class A {}", | 10710 class A {} |
| 10400 "class B extends A {}", | 10711 class B extends A {} |
| 10401 "f() {", | 10712 f() { |
| 10402 " var b = new B();", | 10713 var b = new B(); |
| 10403 " b; // B", | 10714 b; // B |
| 10404 " if (b is A) {", | 10715 if (b is A) { |
| 10405 " return b; // marker", | 10716 return b; // marker |
| 10406 " }", | 10717 } |
| 10407 "}"]); | 10718 }'''; |
| 10408 DartType tB = _findMarkedIdentifier(code, "; // B").propagatedType; | 10719 DartType tB = _findMarkedIdentifier(code, "; // B").propagatedType; |
| 10409 _assertTypeOfMarkedExpression(code, null, tB); | 10720 _assertTypeOfMarkedExpression(code, null, tB); |
| 10410 } | 10721 } |
| 10411 | 10722 |
| 10412 void test_listLiteral_different() { | 10723 void test_listLiteral_different() { |
| 10413 Source source = addSource(EngineTestCase.createSource(["f() {", " var v = [
0, '1', 2];", " return v[2];", "}"])); | 10724 Source source = addSource(r''' |
| 10725 f() { |
| 10726 var v = [0, '1', 2]; |
| 10727 return v[2]; |
| 10728 }'''); |
| 10414 LibraryElement library = resolve(source); | 10729 LibraryElement library = resolve(source); |
| 10415 assertNoErrors(source); | 10730 assertNoErrors(source); |
| 10416 verify([source]); | 10731 verify([source]); |
| 10417 CompilationUnit unit = resolveCompilationUnit(source, library); | 10732 CompilationUnit unit = resolveCompilationUnit(source, library); |
| 10418 FunctionDeclaration function = unit.declarations[0] as FunctionDeclaration; | 10733 FunctionDeclaration function = unit.declarations[0] as FunctionDeclaration; |
| 10419 BlockFunctionBody body = function.functionExpression.body as BlockFunctionBo
dy; | 10734 BlockFunctionBody body = function.functionExpression.body as BlockFunctionBo
dy; |
| 10420 ReturnStatement statement = body.block.statements[1] as ReturnStatement; | 10735 ReturnStatement statement = body.block.statements[1] as ReturnStatement; |
| 10421 IndexExpression indexExpression = statement.expression as IndexExpression; | 10736 IndexExpression indexExpression = statement.expression as IndexExpression; |
| 10422 JUnitTestCase.assertNull(indexExpression.propagatedType); | 10737 JUnitTestCase.assertNull(indexExpression.propagatedType); |
| 10423 } | 10738 } |
| 10424 | 10739 |
| 10425 void test_listLiteral_same() { | 10740 void test_listLiteral_same() { |
| 10426 Source source = addSource(EngineTestCase.createSource(["f() {", " var v = [
0, 1, 2];", " return v[2];", "}"])); | 10741 Source source = addSource(r''' |
| 10742 f() { |
| 10743 var v = [0, 1, 2]; |
| 10744 return v[2]; |
| 10745 }'''); |
| 10427 LibraryElement library = resolve(source); | 10746 LibraryElement library = resolve(source); |
| 10428 assertNoErrors(source); | 10747 assertNoErrors(source); |
| 10429 verify([source]); | 10748 verify([source]); |
| 10430 CompilationUnit unit = resolveCompilationUnit(source, library); | 10749 CompilationUnit unit = resolveCompilationUnit(source, library); |
| 10431 FunctionDeclaration function = unit.declarations[0] as FunctionDeclaration; | 10750 FunctionDeclaration function = unit.declarations[0] as FunctionDeclaration; |
| 10432 BlockFunctionBody body = function.functionExpression.body as BlockFunctionBo
dy; | 10751 BlockFunctionBody body = function.functionExpression.body as BlockFunctionBo
dy; |
| 10433 ReturnStatement statement = body.block.statements[1] as ReturnStatement; | 10752 ReturnStatement statement = body.block.statements[1] as ReturnStatement; |
| 10434 IndexExpression indexExpression = statement.expression as IndexExpression; | 10753 IndexExpression indexExpression = statement.expression as IndexExpression; |
| 10435 JUnitTestCase.assertNull(indexExpression.propagatedType); | 10754 JUnitTestCase.assertNull(indexExpression.propagatedType); |
| 10436 Expression v = indexExpression.target; | 10755 Expression v = indexExpression.target; |
| 10437 InterfaceType propagatedType = v.propagatedType as InterfaceType; | 10756 InterfaceType propagatedType = v.propagatedType as InterfaceType; |
| 10438 JUnitTestCase.assertSame(typeProvider.listType.element, propagatedType.eleme
nt); | 10757 JUnitTestCase.assertSame(typeProvider.listType.element, propagatedType.eleme
nt); |
| 10439 List<DartType> typeArguments = propagatedType.typeArguments; | 10758 List<DartType> typeArguments = propagatedType.typeArguments; |
| 10440 EngineTestCase.assertLength(1, typeArguments); | 10759 EngineTestCase.assertLength(1, typeArguments); |
| 10441 JUnitTestCase.assertSame(typeProvider.dynamicType, typeArguments[0]); | 10760 JUnitTestCase.assertSame(typeProvider.dynamicType, typeArguments[0]); |
| 10442 } | 10761 } |
| 10443 | 10762 |
| 10444 void test_mapLiteral_different() { | 10763 void test_mapLiteral_different() { |
| 10445 Source source = addSource(EngineTestCase.createSource([ | 10764 Source source = addSource(r''' |
| 10446 "f() {", | 10765 f() { |
| 10447 " var v = {'0' : 0, 1 : '1', '2' : 2};", | 10766 var v = {'0' : 0, 1 : '1', '2' : 2}; |
| 10448 " return v;", | 10767 return v; |
| 10449 "}"])); | 10768 }'''); |
| 10450 LibraryElement library = resolve(source); | 10769 LibraryElement library = resolve(source); |
| 10451 assertNoErrors(source); | 10770 assertNoErrors(source); |
| 10452 verify([source]); | 10771 verify([source]); |
| 10453 CompilationUnit unit = resolveCompilationUnit(source, library); | 10772 CompilationUnit unit = resolveCompilationUnit(source, library); |
| 10454 FunctionDeclaration function = unit.declarations[0] as FunctionDeclaration; | 10773 FunctionDeclaration function = unit.declarations[0] as FunctionDeclaration; |
| 10455 BlockFunctionBody body = function.functionExpression.body as BlockFunctionBo
dy; | 10774 BlockFunctionBody body = function.functionExpression.body as BlockFunctionBo
dy; |
| 10456 ReturnStatement statement = body.block.statements[1] as ReturnStatement; | 10775 ReturnStatement statement = body.block.statements[1] as ReturnStatement; |
| 10457 SimpleIdentifier identifier = statement.expression as SimpleIdentifier; | 10776 SimpleIdentifier identifier = statement.expression as SimpleIdentifier; |
| 10458 InterfaceType propagatedType = identifier.propagatedType as InterfaceType; | 10777 InterfaceType propagatedType = identifier.propagatedType as InterfaceType; |
| 10459 JUnitTestCase.assertSame(typeProvider.mapType.element, propagatedType.elemen
t); | 10778 JUnitTestCase.assertSame(typeProvider.mapType.element, propagatedType.elemen
t); |
| 10460 List<DartType> typeArguments = propagatedType.typeArguments; | 10779 List<DartType> typeArguments = propagatedType.typeArguments; |
| 10461 EngineTestCase.assertLength(2, typeArguments); | 10780 EngineTestCase.assertLength(2, typeArguments); |
| 10462 JUnitTestCase.assertSame(typeProvider.dynamicType, typeArguments[0]); | 10781 JUnitTestCase.assertSame(typeProvider.dynamicType, typeArguments[0]); |
| 10463 JUnitTestCase.assertSame(typeProvider.dynamicType, typeArguments[1]); | 10782 JUnitTestCase.assertSame(typeProvider.dynamicType, typeArguments[1]); |
| 10464 } | 10783 } |
| 10465 | 10784 |
| 10466 void test_mapLiteral_same() { | 10785 void test_mapLiteral_same() { |
| 10467 Source source = addSource(EngineTestCase.createSource([ | 10786 Source source = addSource(r''' |
| 10468 "f() {", | 10787 f() { |
| 10469 " var v = {'a' : 0, 'b' : 1, 'c' : 2};", | 10788 var v = {'a' : 0, 'b' : 1, 'c' : 2}; |
| 10470 " return v;", | 10789 return v; |
| 10471 "}"])); | 10790 }'''); |
| 10472 LibraryElement library = resolve(source); | 10791 LibraryElement library = resolve(source); |
| 10473 assertNoErrors(source); | 10792 assertNoErrors(source); |
| 10474 verify([source]); | 10793 verify([source]); |
| 10475 CompilationUnit unit = resolveCompilationUnit(source, library); | 10794 CompilationUnit unit = resolveCompilationUnit(source, library); |
| 10476 FunctionDeclaration function = unit.declarations[0] as FunctionDeclaration; | 10795 FunctionDeclaration function = unit.declarations[0] as FunctionDeclaration; |
| 10477 BlockFunctionBody body = function.functionExpression.body as BlockFunctionBo
dy; | 10796 BlockFunctionBody body = function.functionExpression.body as BlockFunctionBo
dy; |
| 10478 ReturnStatement statement = body.block.statements[1] as ReturnStatement; | 10797 ReturnStatement statement = body.block.statements[1] as ReturnStatement; |
| 10479 SimpleIdentifier identifier = statement.expression as SimpleIdentifier; | 10798 SimpleIdentifier identifier = statement.expression as SimpleIdentifier; |
| 10480 InterfaceType propagatedType = identifier.propagatedType as InterfaceType; | 10799 InterfaceType propagatedType = identifier.propagatedType as InterfaceType; |
| 10481 JUnitTestCase.assertSame(typeProvider.mapType.element, propagatedType.elemen
t); | 10800 JUnitTestCase.assertSame(typeProvider.mapType.element, propagatedType.elemen
t); |
| 10482 List<DartType> typeArguments = propagatedType.typeArguments; | 10801 List<DartType> typeArguments = propagatedType.typeArguments; |
| 10483 EngineTestCase.assertLength(2, typeArguments); | 10802 EngineTestCase.assertLength(2, typeArguments); |
| 10484 JUnitTestCase.assertSame(typeProvider.dynamicType, typeArguments[0]); | 10803 JUnitTestCase.assertSame(typeProvider.dynamicType, typeArguments[0]); |
| 10485 JUnitTestCase.assertSame(typeProvider.dynamicType, typeArguments[1]); | 10804 JUnitTestCase.assertSame(typeProvider.dynamicType, typeArguments[1]); |
| 10486 } | 10805 } |
| 10487 | 10806 |
| 10488 void test_mergePropagatedTypesAtJoinPoint_4() { | 10807 void test_mergePropagatedTypesAtJoinPoint_4() { |
| 10489 // https://code.google.com/p/dart/issues/detail?id=19929 | 10808 // https://code.google.com/p/dart/issues/detail?id=19929 |
| 10490 _assertTypeOfMarkedExpression(EngineTestCase.createSource([ | 10809 _assertTypeOfMarkedExpression(r''' |
| 10491 "f5(x) {", | 10810 f5(x) { |
| 10492 " var y = [];", | 10811 var y = []; |
| 10493 " if (x) {", | 10812 if (x) { |
| 10494 " y = 0;", | 10813 y = 0; |
| 10495 " } else {", | 10814 } else { |
| 10496 " return y;", | 10815 return y; |
| 10497 " }", | 10816 } |
| 10498 " // Propagated type is [int] here: correct.", | 10817 // Propagated type is [int] here: correct. |
| 10499 " return y; // marker", | 10818 return y; // marker |
| 10500 "}"]), null, typeProvider.intType); | 10819 }''', null, typeProvider.intType); |
| 10501 } | 10820 } |
| 10502 | 10821 |
| 10503 void test_mergePropagatedTypesAtJoinPoint_6() { | 10822 void test_mergePropagatedTypesAtJoinPoint_6() { |
| 10504 // https://code.google.com/p/dart/issues/detail?id=19929 | 10823 // https://code.google.com/p/dart/issues/detail?id=19929 |
| 10505 // | 10824 // |
| 10506 // Labeled [break]s are unsafe for the purposes of [isAbruptTerminationState
ment]. | 10825 // Labeled [break]s are unsafe for the purposes of [isAbruptTerminationState
ment]. |
| 10507 // | 10826 // |
| 10508 // This is tricky: the [break] jumps back above the [if], making | 10827 // This is tricky: the [break] jumps back above the [if], making |
| 10509 // it into a loop of sorts. The [if] type-propagation code assumes | 10828 // it into a loop of sorts. The [if] type-propagation code assumes |
| 10510 // that [break] does not introduce a loop. | 10829 // that [break] does not introduce a loop. |
| 10511 enableUnionTypes(false); | 10830 enableUnionTypes(false); |
| 10512 String code = EngineTestCase.createSource([ | 10831 String code = r''' |
| 10513 "f() {", | 10832 f() { |
| 10514 " var x = 0;", | 10833 var x = 0; |
| 10515 " var c = false;", | 10834 var c = false; |
| 10516 " L: ", | 10835 L: |
| 10517 " if (c) {", | 10836 if (c) { |
| 10518 " } else {", | 10837 } else { |
| 10519 " x = '';", | 10838 x = ''; |
| 10520 " c = true;", | 10839 c = true; |
| 10521 " break L;", | 10840 break L; |
| 10522 " }", | 10841 } |
| 10523 " x; // marker", | 10842 x; // marker |
| 10524 "}"]); | 10843 }'''; |
| 10525 DartType t = _findMarkedIdentifier(code, "; // marker").propagatedType; | 10844 DartType t = _findMarkedIdentifier(code, "; // marker").propagatedType; |
| 10526 JUnitTestCase.assertTrue(typeProvider.intType.isSubtypeOf(t)); | 10845 JUnitTestCase.assertTrue(typeProvider.intType.isSubtypeOf(t)); |
| 10527 JUnitTestCase.assertTrue(typeProvider.stringType.isSubtypeOf(t)); | 10846 JUnitTestCase.assertTrue(typeProvider.stringType.isSubtypeOf(t)); |
| 10528 } | 10847 } |
| 10529 | 10848 |
| 10530 void test_objectMethodOnDynamicExpression_doubleEquals() { | 10849 void test_objectMethodOnDynamicExpression_doubleEquals() { |
| 10531 // https://code.google.com/p/dart/issues/detail?id=20342 | 10850 // https://code.google.com/p/dart/issues/detail?id=20342 |
| 10532 // | 10851 // |
| 10533 // This was not actually part of Issue 20342, since the spec specifies a | 10852 // This was not actually part of Issue 20342, since the spec specifies a |
| 10534 // static type of [bool] for [==] comparison and the implementation | 10853 // static type of [bool] for [==] comparison and the implementation |
| 10535 // was already consistent with the spec there. But, it's another | 10854 // was already consistent with the spec there. But, it's another |
| 10536 // [Object] method, so it's included here. | 10855 // [Object] method, so it's included here. |
| 10537 _assertTypeOfMarkedExpression(EngineTestCase.createSource([ | 10856 _assertTypeOfMarkedExpression(r''' |
| 10538 "f1(x) {", | 10857 f1(x) { |
| 10539 " var v = (x == x);", | 10858 var v = (x == x); |
| 10540 " return v; // marker", | 10859 return v; // marker |
| 10541 "}"]), null, typeProvider.boolType); | 10860 }''', null, typeProvider.boolType); |
| 10542 } | 10861 } |
| 10543 | 10862 |
| 10544 void test_objectMethodOnDynamicExpression_hashCode() { | 10863 void test_objectMethodOnDynamicExpression_hashCode() { |
| 10545 // https://code.google.com/p/dart/issues/detail?id=20342 | 10864 // https://code.google.com/p/dart/issues/detail?id=20342 |
| 10546 _assertTypeOfMarkedExpression(EngineTestCase.createSource([ | 10865 _assertTypeOfMarkedExpression(r''' |
| 10547 "f1(x) {", | 10866 f1(x) { |
| 10548 " var v = x.hashCode;", | 10867 var v = x.hashCode; |
| 10549 " return v; // marker", | 10868 return v; // marker |
| 10550 "}"]), null, typeProvider.intType); | 10869 }''', null, typeProvider.intType); |
| 10551 } | 10870 } |
| 10552 | 10871 |
| 10553 void test_objectMethodOnDynamicExpression_runtimeType() { | 10872 void test_objectMethodOnDynamicExpression_runtimeType() { |
| 10554 // https://code.google.com/p/dart/issues/detail?id=20342 | 10873 // https://code.google.com/p/dart/issues/detail?id=20342 |
| 10555 _assertTypeOfMarkedExpression(EngineTestCase.createSource([ | 10874 _assertTypeOfMarkedExpression(r''' |
| 10556 "f1(x) {", | 10875 f1(x) { |
| 10557 " var v = x.runtimeType;", | 10876 var v = x.runtimeType; |
| 10558 " return v; // marker", | 10877 return v; // marker |
| 10559 "}"]), null, typeProvider.typeType); | 10878 }''', null, typeProvider.typeType); |
| 10560 } | 10879 } |
| 10561 | 10880 |
| 10562 void test_objectMethodOnDynamicExpression_toString() { | 10881 void test_objectMethodOnDynamicExpression_toString() { |
| 10563 // https://code.google.com/p/dart/issues/detail?id=20342 | 10882 // https://code.google.com/p/dart/issues/detail?id=20342 |
| 10564 _assertTypeOfMarkedExpression(EngineTestCase.createSource([ | 10883 _assertTypeOfMarkedExpression(r''' |
| 10565 "f1(x) {", | 10884 f1(x) { |
| 10566 " var v = x.toString();", | 10885 var v = x.toString(); |
| 10567 " return v; // marker", | 10886 return v; // marker |
| 10568 "}"]), null, typeProvider.stringType); | 10887 }''', null, typeProvider.stringType); |
| 10569 } | 10888 } |
| 10570 | 10889 |
| 10571 void test_propagatedReturnType_function_hasReturnType_returnsNull() { | 10890 void test_propagatedReturnType_function_hasReturnType_returnsNull() { |
| 10572 String code = EngineTestCase.createSource(["String f() => null;", "main() {"
, " var v = f();", "}"]); | 10891 String code = r''' |
| 10892 String f() => null; |
| 10893 main() { |
| 10894 var v = f(); |
| 10895 }'''; |
| 10573 _assertPropagatedReturnType(code, typeProvider.dynamicType, typeProvider.str
ingType); | 10896 _assertPropagatedReturnType(code, typeProvider.dynamicType, typeProvider.str
ingType); |
| 10574 } | 10897 } |
| 10575 | 10898 |
| 10576 void test_propagatedReturnType_function_lessSpecificStaticReturnType() { | 10899 void test_propagatedReturnType_function_lessSpecificStaticReturnType() { |
| 10577 String code = EngineTestCase.createSource(["Object f() => 42;", "main() {",
" var v = f();", "}"]); | 10900 String code = r''' |
| 10901 Object f() => 42; |
| 10902 main() { |
| 10903 var v = f(); |
| 10904 }'''; |
| 10578 _assertPropagatedReturnType(code, typeProvider.dynamicType, typeProvider.int
Type); | 10905 _assertPropagatedReturnType(code, typeProvider.dynamicType, typeProvider.int
Type); |
| 10579 } | 10906 } |
| 10580 | 10907 |
| 10581 void test_propagatedReturnType_function_moreSpecificStaticReturnType() { | 10908 void test_propagatedReturnType_function_moreSpecificStaticReturnType() { |
| 10582 String code = EngineTestCase.createSource([ | 10909 String code = r''' |
| 10583 "int f(v) => (v as num);", | 10910 int f(v) => (v as num); |
| 10584 "main() {", | 10911 main() { |
| 10585 " var v = f(3);", | 10912 var v = f(3); |
| 10586 "}"]); | 10913 }'''; |
| 10587 _assertPropagatedReturnType(code, typeProvider.dynamicType, typeProvider.int
Type); | 10914 _assertPropagatedReturnType(code, typeProvider.dynamicType, typeProvider.int
Type); |
| 10588 } | 10915 } |
| 10589 | 10916 |
| 10590 void test_propagatedReturnType_function_noReturnTypeName_blockBody_multipleRet
urns() { | 10917 void test_propagatedReturnType_function_noReturnTypeName_blockBody_multipleRet
urns() { |
| 10591 String code = EngineTestCase.createSource([ | 10918 String code = r''' |
| 10592 "f() {", | 10919 f() { |
| 10593 " if (true) return 0;", | 10920 if (true) return 0; |
| 10594 " return 1.0;", | 10921 return 1.0; |
| 10595 "}", | 10922 } |
| 10596 "main() {", | 10923 main() { |
| 10597 " var v = f();", | 10924 var v = f(); |
| 10598 "}"]); | 10925 }'''; |
| 10599 _assertPropagatedReturnType(code, typeProvider.dynamicType, typeProvider.num
Type); | 10926 _assertPropagatedReturnType(code, typeProvider.dynamicType, typeProvider.num
Type); |
| 10600 } | 10927 } |
| 10601 | 10928 |
| 10602 void test_propagatedReturnType_function_noReturnTypeName_blockBody_oneReturn()
{ | 10929 void test_propagatedReturnType_function_noReturnTypeName_blockBody_oneReturn()
{ |
| 10603 String code = EngineTestCase.createSource([ | 10930 String code = r''' |
| 10604 "f() {", | 10931 f() { |
| 10605 " var z = 42;", | 10932 var z = 42; |
| 10606 " return z;", | 10933 return z; |
| 10607 "}", | 10934 } |
| 10608 "main() {", | 10935 main() { |
| 10609 " var v = f();", | 10936 var v = f(); |
| 10610 "}"]); | 10937 }'''; |
| 10611 _assertPropagatedReturnType(code, typeProvider.dynamicType, typeProvider.int
Type); | 10938 _assertPropagatedReturnType(code, typeProvider.dynamicType, typeProvider.int
Type); |
| 10612 } | 10939 } |
| 10613 | 10940 |
| 10614 void test_propagatedReturnType_function_noReturnTypeName_expressionBody() { | 10941 void test_propagatedReturnType_function_noReturnTypeName_expressionBody() { |
| 10615 String code = EngineTestCase.createSource(["f() => 42;", "main() {", " var
v = f();", "}"]); | 10942 String code = r''' |
| 10943 f() => 42; |
| 10944 main() { |
| 10945 var v = f(); |
| 10946 }'''; |
| 10616 _assertPropagatedReturnType(code, typeProvider.dynamicType, typeProvider.int
Type); | 10947 _assertPropagatedReturnType(code, typeProvider.dynamicType, typeProvider.int
Type); |
| 10617 } | 10948 } |
| 10618 | 10949 |
| 10619 void test_propagatedReturnType_localFunction() { | 10950 void test_propagatedReturnType_localFunction() { |
| 10620 String code = EngineTestCase.createSource(["main() {", " f() => 42;", " va
r v = f();", "}"]); | 10951 String code = r''' |
| 10952 main() { |
| 10953 f() => 42; |
| 10954 var v = f(); |
| 10955 }'''; |
| 10621 _assertPropagatedReturnType(code, typeProvider.dynamicType, typeProvider.int
Type); | 10956 _assertPropagatedReturnType(code, typeProvider.dynamicType, typeProvider.int
Type); |
| 10622 } | 10957 } |
| 10623 | 10958 |
| 10624 void test_query() { | 10959 void test_query() { |
| 10625 Source source = addSource(EngineTestCase.createSource([ | 10960 Source source = addSource(r''' |
| 10626 "import 'dart:html';", | 10961 import 'dart:html'; |
| 10627 "", | 10962 |
| 10628 "main() {", | 10963 main() { |
| 10629 " var v1 = query('a');", | 10964 var v1 = query('a'); |
| 10630 " var v2 = query('A');", | 10965 var v2 = query('A'); |
| 10631 " var v3 = query('body:active');", | 10966 var v3 = query('body:active'); |
| 10632 " var v4 = query('button[foo=\"bar\"]');", | 10967 var v4 = query('button[foo="bar"]'); |
| 10633 " var v5 = query('div.class');", | 10968 var v5 = query('div.class'); |
| 10634 " var v6 = query('input#id');", | 10969 var v6 = query('input#id'); |
| 10635 " var v7 = query('select#id');", | 10970 var v7 = query('select#id'); |
| 10636 " // invocation of method", | 10971 // invocation of method |
| 10637 " var m1 = document.query('div');", | 10972 var m1 = document.query('div'); |
| 10638 " // unsupported currently", | 10973 // unsupported currently |
| 10639 " var b1 = query('noSuchTag');", | 10974 var b1 = query('noSuchTag'); |
| 10640 " var b2 = query('DART_EDITOR_NO_SUCH_TYPE');", | 10975 var b2 = query('DART_EDITOR_NO_SUCH_TYPE'); |
| 10641 " var b3 = query('body div');", | 10976 var b3 = query('body div'); |
| 10642 " return [v1, v2, v3, v4, v5, v6, v7, m1, b1, b2, b3];", | 10977 return [v1, v2, v3, v4, v5, v6, v7, m1, b1, b2, b3]; |
| 10643 "}"])); | 10978 }'''); |
| 10644 LibraryElement library = resolve(source); | 10979 LibraryElement library = resolve(source); |
| 10645 assertNoErrors(source); | 10980 assertNoErrors(source); |
| 10646 verify([source]); | 10981 verify([source]); |
| 10647 CompilationUnit unit = resolveCompilationUnit(source, library); | 10982 CompilationUnit unit = resolveCompilationUnit(source, library); |
| 10648 FunctionDeclaration main = unit.declarations[0] as FunctionDeclaration; | 10983 FunctionDeclaration main = unit.declarations[0] as FunctionDeclaration; |
| 10649 BlockFunctionBody body = main.functionExpression.body as BlockFunctionBody; | 10984 BlockFunctionBody body = main.functionExpression.body as BlockFunctionBody; |
| 10650 ReturnStatement statement = body.block.statements[11] as ReturnStatement; | 10985 ReturnStatement statement = body.block.statements[11] as ReturnStatement; |
| 10651 NodeList<Expression> elements = (statement.expression as ListLiteral).elemen
ts; | 10986 NodeList<Expression> elements = (statement.expression as ListLiteral).elemen
ts; |
| 10652 JUnitTestCase.assertEquals("AnchorElement", elements[0].propagatedType.name)
; | 10987 JUnitTestCase.assertEquals("AnchorElement", elements[0].propagatedType.name)
; |
| 10653 JUnitTestCase.assertEquals("AnchorElement", elements[1].propagatedType.name)
; | 10988 JUnitTestCase.assertEquals("AnchorElement", elements[1].propagatedType.name)
; |
| (...skipping 503 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 11157 runReflectiveTests(TypeResolverVisitorTest); | 11492 runReflectiveTests(TypeResolverVisitorTest); |
| 11158 runReflectiveTests(CheckedModeCompileTimeErrorCodeTest); | 11493 runReflectiveTests(CheckedModeCompileTimeErrorCodeTest); |
| 11159 runReflectiveTests(ErrorResolverTest); | 11494 runReflectiveTests(ErrorResolverTest); |
| 11160 runReflectiveTests(HintCodeTest); | 11495 runReflectiveTests(HintCodeTest); |
| 11161 runReflectiveTests(MemberMapTest); | 11496 runReflectiveTests(MemberMapTest); |
| 11162 runReflectiveTests(NonHintCodeTest); | 11497 runReflectiveTests(NonHintCodeTest); |
| 11163 runReflectiveTests(SimpleResolverTest); | 11498 runReflectiveTests(SimpleResolverTest); |
| 11164 runReflectiveTests(StrictModeTest); | 11499 runReflectiveTests(StrictModeTest); |
| 11165 runReflectiveTests(TypePropagationTest); | 11500 runReflectiveTests(TypePropagationTest); |
| 11166 } | 11501 } |
| OLD | NEW |