| 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 analyzer.test.generated.static_warning_code_test; | 5 library analyzer.test.generated.static_warning_code_test; |
| 6 | 6 |
| 7 import 'package:analyzer/src/generated/error.dart'; | 7 import 'package:analyzer/src/generated/error.dart'; |
| 8 import 'package:analyzer/src/generated/source_io.dart'; | 8 import 'package:analyzer/src/generated/source_io.dart'; |
| 9 import 'package:unittest/unittest.dart'; | 9 import 'package:unittest/unittest.dart'; |
| 10 | 10 |
| (...skipping 975 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 986 Stream s;'''); | 986 Stream s;'''); |
| 987 addNamedSource( | 987 addNamedSource( |
| 988 "/lib.dart", | 988 "/lib.dart", |
| 989 r''' | 989 r''' |
| 990 library lib; | 990 library lib; |
| 991 class Future {}'''); | 991 class Future {}'''); |
| 992 computeLibrarySourceErrors(source); | 992 computeLibrarySourceErrors(source); |
| 993 assertErrors(source, [StaticWarningCode.CONFLICTING_DART_IMPORT]); | 993 assertErrors(source, [StaticWarningCode.CONFLICTING_DART_IMPORT]); |
| 994 } | 994 } |
| 995 | 995 |
| 996 void test_conflictingInstanceGetterAndSuperclassMember_declField_direct_setter
() { | 996 void |
| 997 test_conflictingInstanceGetterAndSuperclassMember_declField_direct_setter(
) { |
| 997 Source source = addSource(r''' | 998 Source source = addSource(r''' |
| 998 class A { | 999 class A { |
| 999 static set v(x) {} | 1000 static set v(x) {} |
| 1000 } | 1001 } |
| 1001 class B extends A { | 1002 class B extends A { |
| 1002 var v; | 1003 var v; |
| 1003 }'''); | 1004 }'''); |
| 1004 computeLibrarySourceErrors(source); | 1005 computeLibrarySourceErrors(source); |
| 1005 assertErrors(source, | 1006 assertErrors(source, |
| 1006 [StaticWarningCode.CONFLICTING_INSTANCE_GETTER_AND_SUPERCLASS_MEMBER]); | 1007 [StaticWarningCode.CONFLICTING_INSTANCE_GETTER_AND_SUPERCLASS_MEMBER]); |
| 1007 verify([source]); | 1008 verify([source]); |
| 1008 } | 1009 } |
| 1009 | 1010 |
| 1010 void test_conflictingInstanceGetterAndSuperclassMember_declGetter_direct_gette
r() { | 1011 void |
| 1012 test_conflictingInstanceGetterAndSuperclassMember_declGetter_direct_getter
() { |
| 1011 Source source = addSource(r''' | 1013 Source source = addSource(r''' |
| 1012 class A { | 1014 class A { |
| 1013 static get v => 0; | 1015 static get v => 0; |
| 1014 } | 1016 } |
| 1015 class B extends A { | 1017 class B extends A { |
| 1016 get v => 0; | 1018 get v => 0; |
| 1017 }'''); | 1019 }'''); |
| 1018 computeLibrarySourceErrors(source); | 1020 computeLibrarySourceErrors(source); |
| 1019 assertErrors(source, | 1021 assertErrors(source, |
| 1020 [StaticWarningCode.CONFLICTING_INSTANCE_GETTER_AND_SUPERCLASS_MEMBER]); | 1022 [StaticWarningCode.CONFLICTING_INSTANCE_GETTER_AND_SUPERCLASS_MEMBER]); |
| 1021 verify([source]); | 1023 verify([source]); |
| 1022 } | 1024 } |
| 1023 | 1025 |
| 1024 void test_conflictingInstanceGetterAndSuperclassMember_declGetter_direct_metho
d() { | 1026 void |
| 1027 test_conflictingInstanceGetterAndSuperclassMember_declGetter_direct_method
() { |
| 1025 Source source = addSource(r''' | 1028 Source source = addSource(r''' |
| 1026 class A { | 1029 class A { |
| 1027 static v() {} | 1030 static v() {} |
| 1028 } | 1031 } |
| 1029 class B extends A { | 1032 class B extends A { |
| 1030 get v => 0; | 1033 get v => 0; |
| 1031 }'''); | 1034 }'''); |
| 1032 computeLibrarySourceErrors(source); | 1035 computeLibrarySourceErrors(source); |
| 1033 assertErrors(source, | 1036 assertErrors(source, |
| 1034 [StaticWarningCode.CONFLICTING_INSTANCE_GETTER_AND_SUPERCLASS_MEMBER]); | 1037 [StaticWarningCode.CONFLICTING_INSTANCE_GETTER_AND_SUPERCLASS_MEMBER]); |
| 1035 verify([source]); | 1038 verify([source]); |
| 1036 } | 1039 } |
| 1037 | 1040 |
| 1038 void test_conflictingInstanceGetterAndSuperclassMember_declGetter_direct_sette
r() { | 1041 void |
| 1042 test_conflictingInstanceGetterAndSuperclassMember_declGetter_direct_setter
() { |
| 1039 Source source = addSource(r''' | 1043 Source source = addSource(r''' |
| 1040 class A { | 1044 class A { |
| 1041 static set v(x) {} | 1045 static set v(x) {} |
| 1042 } | 1046 } |
| 1043 class B extends A { | 1047 class B extends A { |
| 1044 get v => 0; | 1048 get v => 0; |
| 1045 }'''); | 1049 }'''); |
| 1046 computeLibrarySourceErrors(source); | 1050 computeLibrarySourceErrors(source); |
| 1047 assertErrors(source, | 1051 assertErrors(source, |
| 1048 [StaticWarningCode.CONFLICTING_INSTANCE_GETTER_AND_SUPERCLASS_MEMBER]); | 1052 [StaticWarningCode.CONFLICTING_INSTANCE_GETTER_AND_SUPERCLASS_MEMBER]); |
| (...skipping 1467 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2516 p(); | 2520 p(); |
| 2517 } | 2521 } |
| 2518 class C extends A { | 2522 class C extends A { |
| 2519 }'''); | 2523 }'''); |
| 2520 computeLibrarySourceErrors(source); | 2524 computeLibrarySourceErrors(source); |
| 2521 assertErrors(source, | 2525 assertErrors(source, |
| 2522 [StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_FOUR]); | 2526 [StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_FOUR]); |
| 2523 verify([source]); | 2527 verify([source]); |
| 2524 } | 2528 } |
| 2525 | 2529 |
| 2526 void test_nonAbstractClassInheritsAbstractMemberOne_classTypeAlias_interface()
{ | 2530 void |
| 2531 test_nonAbstractClassInheritsAbstractMemberOne_classTypeAlias_interface()
{ |
| 2527 // 15979 | 2532 // 15979 |
| 2528 Source source = addSource(r''' | 2533 Source source = addSource(r''' |
| 2529 abstract class M {} | 2534 abstract class M {} |
| 2530 abstract class A {} | 2535 abstract class A {} |
| 2531 abstract class I { | 2536 abstract class I { |
| 2532 m(); | 2537 m(); |
| 2533 } | 2538 } |
| 2534 class B = A with M implements I;'''); | 2539 class B = A with M implements I;'''); |
| 2535 computeLibrarySourceErrors(source); | 2540 computeLibrarySourceErrors(source); |
| 2536 assertErrors(source, | 2541 assertErrors(source, |
| 2537 [StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_ONE]); | 2542 [StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_ONE]); |
| 2538 verify([source]); | 2543 verify([source]); |
| 2539 } | 2544 } |
| 2540 | 2545 |
| 2541 void test_nonAbstractClassInheritsAbstractMemberOne_classTypeAlias_mixin() { | 2546 void test_nonAbstractClassInheritsAbstractMemberOne_classTypeAlias_mixin() { |
| 2542 // 15979 | 2547 // 15979 |
| 2543 Source source = addSource(r''' | 2548 Source source = addSource(r''' |
| 2544 abstract class M { | 2549 abstract class M { |
| 2545 m(); | 2550 m(); |
| 2546 } | 2551 } |
| 2547 abstract class A {} | 2552 abstract class A {} |
| 2548 class B = A with M;'''); | 2553 class B = A with M;'''); |
| 2549 computeLibrarySourceErrors(source); | 2554 computeLibrarySourceErrors(source); |
| 2550 assertErrors(source, | 2555 assertErrors(source, |
| 2551 [StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_ONE]); | 2556 [StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_ONE]); |
| 2552 verify([source]); | 2557 verify([source]); |
| 2553 } | 2558 } |
| 2554 | 2559 |
| 2555 void test_nonAbstractClassInheritsAbstractMemberOne_classTypeAlias_superclass(
) { | 2560 void |
| 2561 test_nonAbstractClassInheritsAbstractMemberOne_classTypeAlias_superclass()
{ |
| 2556 // 15979 | 2562 // 15979 |
| 2557 Source source = addSource(r''' | 2563 Source source = addSource(r''' |
| 2558 class M {} | 2564 class M {} |
| 2559 abstract class A { | 2565 abstract class A { |
| 2560 m(); | 2566 m(); |
| 2561 } | 2567 } |
| 2562 class B = A with M;'''); | 2568 class B = A with M;'''); |
| 2563 computeLibrarySourceErrors(source); | 2569 computeLibrarySourceErrors(source); |
| 2564 assertErrors(source, | 2570 assertErrors(source, |
| 2565 [StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_ONE]); | 2571 [StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_ONE]); |
| 2566 verify([source]); | 2572 verify([source]); |
| 2567 } | 2573 } |
| 2568 | 2574 |
| 2569 void test_nonAbstractClassInheritsAbstractMemberOne_ensureCorrectFunctionSubty
peIsUsedInImplementation() { | 2575 void |
| 2576 test_nonAbstractClassInheritsAbstractMemberOne_ensureCorrectFunctionSubtyp
eIsUsedInImplementation() { |
| 2570 // 15028 | 2577 // 15028 |
| 2571 Source source = addSource(r''' | 2578 Source source = addSource(r''' |
| 2572 class C { | 2579 class C { |
| 2573 foo(int x) => x; | 2580 foo(int x) => x; |
| 2574 } | 2581 } |
| 2575 abstract class D { | 2582 abstract class D { |
| 2576 foo(x, [y]); | 2583 foo(x, [y]); |
| 2577 } | 2584 } |
| 2578 class E extends C implements D {}'''); | 2585 class E extends C implements D {}'''); |
| 2579 computeLibrarySourceErrors(source); | 2586 computeLibrarySourceErrors(source); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2627 m(p); | 2634 m(p); |
| 2628 } | 2635 } |
| 2629 class C extends A { | 2636 class C extends A { |
| 2630 }'''); | 2637 }'''); |
| 2631 computeLibrarySourceErrors(source); | 2638 computeLibrarySourceErrors(source); |
| 2632 assertErrors(source, | 2639 assertErrors(source, |
| 2633 [StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_ONE]); | 2640 [StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_ONE]); |
| 2634 verify([source]); | 2641 verify([source]); |
| 2635 } | 2642 } |
| 2636 | 2643 |
| 2637 void test_nonAbstractClassInheritsAbstractMemberOne_method_optionalParamCount(
) { | 2644 void |
| 2645 test_nonAbstractClassInheritsAbstractMemberOne_method_optionalParamCount()
{ |
| 2638 // 7640 | 2646 // 7640 |
| 2639 Source source = addSource(r''' | 2647 Source source = addSource(r''' |
| 2640 abstract class A { | 2648 abstract class A { |
| 2641 int x(int a); | 2649 int x(int a); |
| 2642 } | 2650 } |
| 2643 abstract class B { | 2651 abstract class B { |
| 2644 int x(int a, [int b]); | 2652 int x(int a, [int b]); |
| 2645 } | 2653 } |
| 2646 class C implements A, B { | 2654 class C implements A, B { |
| 2647 }'''); | 2655 }'''); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2694 m(); | 2702 m(); |
| 2695 } | 2703 } |
| 2696 class B extends A implements I { | 2704 class B extends A implements I { |
| 2697 }'''); | 2705 }'''); |
| 2698 computeLibrarySourceErrors(source); | 2706 computeLibrarySourceErrors(source); |
| 2699 assertErrors(source, | 2707 assertErrors(source, |
| 2700 [StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_ONE]); | 2708 [StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_ONE]); |
| 2701 verify([source]); | 2709 verify([source]); |
| 2702 } | 2710 } |
| 2703 | 2711 |
| 2704 void test_nonAbstractClassInheritsAbstractMemberOne_setter_and_implicitSetter(
) { | 2712 void |
| 2713 test_nonAbstractClassInheritsAbstractMemberOne_setter_and_implicitSetter()
{ |
| 2705 // test from language/override_inheritance_abstract_test_14.dart | 2714 // test from language/override_inheritance_abstract_test_14.dart |
| 2706 Source source = addSource(r''' | 2715 Source source = addSource(r''' |
| 2707 abstract class A { | 2716 abstract class A { |
| 2708 set field(_); | 2717 set field(_); |
| 2709 } | 2718 } |
| 2710 abstract class I { | 2719 abstract class I { |
| 2711 var field; | 2720 var field; |
| 2712 } | 2721 } |
| 2713 class B extends A implements I { | 2722 class B extends A implements I { |
| 2714 get field => 0; | 2723 get field => 0; |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2755 get b => 'b'; | 2764 get b => 'b'; |
| 2756 } | 2765 } |
| 2757 class C extends B { | 2766 class C extends B { |
| 2758 }'''); | 2767 }'''); |
| 2759 computeLibrarySourceErrors(source); | 2768 computeLibrarySourceErrors(source); |
| 2760 assertErrors(source, | 2769 assertErrors(source, |
| 2761 [StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_ONE]); | 2770 [StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_ONE]); |
| 2762 verify([source]); | 2771 verify([source]); |
| 2763 } | 2772 } |
| 2764 | 2773 |
| 2765 void test_nonAbstractClassInheritsAbstractMemberOne_variable_fromInterface_mis
singGetter() { | 2774 void |
| 2775 test_nonAbstractClassInheritsAbstractMemberOne_variable_fromInterface_miss
ingGetter() { |
| 2766 // 16133 | 2776 // 16133 |
| 2767 Source source = addSource(r''' | 2777 Source source = addSource(r''' |
| 2768 class I { | 2778 class I { |
| 2769 var v; | 2779 var v; |
| 2770 } | 2780 } |
| 2771 class C implements I { | 2781 class C implements I { |
| 2772 set v(_) {} | 2782 set v(_) {} |
| 2773 }'''); | 2783 }'''); |
| 2774 computeLibrarySourceErrors(source); | 2784 computeLibrarySourceErrors(source); |
| 2775 assertErrors(source, | 2785 assertErrors(source, |
| 2776 [StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_ONE]); | 2786 [StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_ONE]); |
| 2777 verify([source]); | 2787 verify([source]); |
| 2778 } | 2788 } |
| 2779 | 2789 |
| 2780 void test_nonAbstractClassInheritsAbstractMemberOne_variable_fromInterface_mis
singSetter() { | 2790 void |
| 2791 test_nonAbstractClassInheritsAbstractMemberOne_variable_fromInterface_miss
ingSetter() { |
| 2781 // 16133 | 2792 // 16133 |
| 2782 Source source = addSource(r''' | 2793 Source source = addSource(r''' |
| 2783 class I { | 2794 class I { |
| 2784 var v; | 2795 var v; |
| 2785 } | 2796 } |
| 2786 class C implements I { | 2797 class C implements I { |
| 2787 get v => 1; | 2798 get v => 1; |
| 2788 }'''); | 2799 }'''); |
| 2789 computeLibrarySourceErrors(source); | 2800 computeLibrarySourceErrors(source); |
| 2790 assertErrors(source, | 2801 assertErrors(source, |
| (...skipping 23 matching lines...) Expand all Loading... |
| 2814 n(); | 2825 n(); |
| 2815 } | 2826 } |
| 2816 class C extends A { | 2827 class C extends A { |
| 2817 }'''); | 2828 }'''); |
| 2818 computeLibrarySourceErrors(source); | 2829 computeLibrarySourceErrors(source); |
| 2819 assertErrors(source, | 2830 assertErrors(source, |
| 2820 [StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_TWO]); | 2831 [StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_TWO]); |
| 2821 verify([source]); | 2832 verify([source]); |
| 2822 } | 2833 } |
| 2823 | 2834 |
| 2824 void test_nonAbstractClassInheritsAbstractMemberTwo_variable_fromInterface_mis
singBoth() { | 2835 void |
| 2836 test_nonAbstractClassInheritsAbstractMemberTwo_variable_fromInterface_miss
ingBoth() { |
| 2825 // 16133 | 2837 // 16133 |
| 2826 Source source = addSource(r''' | 2838 Source source = addSource(r''' |
| 2827 class I { | 2839 class I { |
| 2828 var v; | 2840 var v; |
| 2829 } | 2841 } |
| 2830 class C implements I { | 2842 class C implements I { |
| 2831 }'''); | 2843 }'''); |
| 2832 computeLibrarySourceErrors(source); | 2844 computeLibrarySourceErrors(source); |
| 2833 assertErrors(source, | 2845 assertErrors(source, |
| 2834 [StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_TWO]); | 2846 [StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_TWO]); |
| (...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3200 class A {}''', | 3212 class A {}''', |
| 3201 r''' | 3213 r''' |
| 3202 library root; | 3214 library root; |
| 3203 import 'lib1.dart' deferred as a; | 3215 import 'lib1.dart' deferred as a; |
| 3204 a.A f() { return null; }''' | 3216 a.A f() { return null; }''' |
| 3205 ], <ErrorCode>[ | 3217 ], <ErrorCode>[ |
| 3206 StaticWarningCode.TYPE_ANNOTATION_DEFERRED_CLASS | 3218 StaticWarningCode.TYPE_ANNOTATION_DEFERRED_CLASS |
| 3207 ]); | 3219 ]); |
| 3208 } | 3220 } |
| 3209 | 3221 |
| 3210 void test_typeAnnotationDeferredClass_functionTypedFormalParameter_returnType(
) { | 3222 void |
| 3223 test_typeAnnotationDeferredClass_functionTypedFormalParameter_returnType()
{ |
| 3211 resolveWithErrors(<String>[ | 3224 resolveWithErrors(<String>[ |
| 3212 r''' | 3225 r''' |
| 3213 library lib1; | 3226 library lib1; |
| 3214 class A {}''', | 3227 class A {}''', |
| 3215 r''' | 3228 r''' |
| 3216 library root; | 3229 library root; |
| 3217 import 'lib1.dart' deferred as a; | 3230 import 'lib1.dart' deferred as a; |
| 3218 f(a.A g()) {}''' | 3231 f(a.A g()) {}''' |
| 3219 ], <ErrorCode>[ | 3232 ], <ErrorCode>[ |
| 3220 StaticWarningCode.TYPE_ANNOTATION_DEFERRED_CLASS | 3233 StaticWarningCode.TYPE_ANNOTATION_DEFERRED_CLASS |
| (...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3628 | 3641 |
| 3629 void test_voidReturnForGetter() { | 3642 void test_voidReturnForGetter() { |
| 3630 Source source = addSource(r''' | 3643 Source source = addSource(r''' |
| 3631 class S { | 3644 class S { |
| 3632 void get value {} | 3645 void get value {} |
| 3633 }'''); | 3646 }'''); |
| 3634 computeLibrarySourceErrors(source); | 3647 computeLibrarySourceErrors(source); |
| 3635 assertErrors(source, [StaticWarningCode.VOID_RETURN_FOR_GETTER]); | 3648 assertErrors(source, [StaticWarningCode.VOID_RETURN_FOR_GETTER]); |
| 3636 } | 3649 } |
| 3637 } | 3650 } |
| OLD | NEW |