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

Side by Side Diff: pkg/analyzer/test/generated/hint_code_test.dart

Issue 2031053002: Extend @protected to include implemented interfaces. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « pkg/analyzer/lib/src/generated/resolver.dart ('k') | pkg/meta/CHANGELOG.md » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2016, 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.hint_code_test; 5 library analyzer.test.generated.hint_code_test;
6 6
7 import 'package:analyzer/src/generated/engine.dart'; 7 import 'package:analyzer/src/generated/engine.dart';
8 import 'package:analyzer/src/generated/error.dart'; 8 import 'package:analyzer/src/generated/error.dart';
9 import 'package:analyzer/src/generated/source_io.dart'; 9 import 'package:analyzer/src/generated/source_io.dart';
10 import 'package:unittest/unittest.dart'; 10 import 'package:unittest/unittest.dart';
(...skipping 616 matching lines...) Expand 10 before | Expand all | Expand 10 after
627 } 627 }
628 f(A a) { 628 f(A a) {
629 A b; 629 A b;
630 a += b; 630 a += b;
631 }'''); 631 }''');
632 computeLibrarySourceErrors(source); 632 computeLibrarySourceErrors(source);
633 assertErrors(source, [HintCode.DEPRECATED_MEMBER_USE]); 633 assertErrors(source, [HintCode.DEPRECATED_MEMBER_USE]);
634 verify([source]); 634 verify([source]);
635 } 635 }
636 636
637 void test_deprecatedAnnotationUse_call() {
638 Source source = addSource(r'''
639 class A {
640 @deprecated
641 call() {}
642 m() {
643 A a = new A();
644 a();
645 }
646 }''');
647 computeLibrarySourceErrors(source);
648 assertErrors(source, [HintCode.DEPRECATED_MEMBER_USE]);
649 verify([source]);
650 }
651
637 void test_deprecatedAnnotationUse_Deprecated() { 652 void test_deprecatedAnnotationUse_Deprecated() {
638 Source source = addSource(r''' 653 Source source = addSource(r'''
639 class A { 654 class A {
640 @Deprecated('0.9') 655 @Deprecated('0.9')
641 m() {} 656 m() {}
642 n() {m();} 657 n() {m();}
643 }'''); 658 }''');
644 computeLibrarySourceErrors(source);
645 assertErrors(source, [HintCode.DEPRECATED_MEMBER_USE]);
646 verify([source]);
647 }
648
649 void test_deprecatedAnnotationUse_deprecated() {
650 Source source = addSource(r'''
651 class A {
652 @deprecated
653 m() {}
654 n() {m();}
655 }''');
656 computeLibrarySourceErrors(source); 659 computeLibrarySourceErrors(source);
657 assertErrors(source, [HintCode.DEPRECATED_MEMBER_USE]); 660 assertErrors(source, [HintCode.DEPRECATED_MEMBER_USE]);
658 verify([source]); 661 verify([source]);
659 } 662 }
660 663
661 void test_deprecatedAnnotationUse_positional() { 664 void test_deprecatedAnnotationUse_deprecated() {
662 Source source = addSource(r''' 665 Source source = addSource(r'''
663 class A { 666 class A {
664 m([@deprecated int x]) {} 667 @deprecated
665 n() {m(1);} 668 m() {}
669 n() {m();}
666 }'''); 670 }''');
667 computeLibrarySourceErrors(source); 671 computeLibrarySourceErrors(source);
668 assertErrors(source, [HintCode.DEPRECATED_MEMBER_USE]); 672 assertErrors(source, [HintCode.DEPRECATED_MEMBER_USE]);
669 verify([source]);
670 }
671
672 void test_deprecatedAnnotationUse_named() {
673 Source source = addSource(r'''
674 class A {
675 m({@deprecated int x}) {}
676 n() {m(x: 1);}
677 }''');
678 computeLibrarySourceErrors(source);
679 assertErrors(source, [HintCode.DEPRECATED_MEMBER_USE]);
680 verify([source]); 673 verify([source]);
681 } 674 }
682 675
683 void test_deprecatedAnnotationUse_export() { 676 void test_deprecatedAnnotationUse_export() {
684 Source source = addSource("export 'deprecated_library.dart';"); 677 Source source = addSource("export 'deprecated_library.dart';");
685 addNamedSource( 678 addNamedSource(
686 "/deprecated_library.dart", 679 "/deprecated_library.dart",
687 r''' 680 r'''
688 @deprecated 681 @deprecated
689 library deprecated_library; 682 library deprecated_library;
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
771 A.named(int i) {} 764 A.named(int i) {}
772 } 765 }
773 f() { 766 f() {
774 A a = new A.named(1); 767 A a = new A.named(1);
775 }'''); 768 }''');
776 computeLibrarySourceErrors(source); 769 computeLibrarySourceErrors(source);
777 assertErrors(source, [HintCode.DEPRECATED_MEMBER_USE]); 770 assertErrors(source, [HintCode.DEPRECATED_MEMBER_USE]);
778 verify([source]); 771 verify([source]);
779 } 772 }
780 773
774 void test_deprecatedAnnotationUse_named() {
775 Source source = addSource(r'''
776 class A {
777 m({@deprecated int x}) {}
778 n() {m(x: 1);}
779 }''');
780 computeLibrarySourceErrors(source);
781 assertErrors(source, [HintCode.DEPRECATED_MEMBER_USE]);
782 verify([source]);
783 }
784
781 void test_deprecatedAnnotationUse_operator() { 785 void test_deprecatedAnnotationUse_operator() {
782 Source source = addSource(r''' 786 Source source = addSource(r'''
783 class A { 787 class A {
784 @deprecated 788 @deprecated
785 operator+(A a) {} 789 operator+(A a) {}
786 } 790 }
787 f(A a) { 791 f(A a) {
788 A b; 792 A b;
789 return a + b; 793 return a + b;
790 }'''); 794 }''');
791 computeLibrarySourceErrors(source); 795 computeLibrarySourceErrors(source);
792 assertErrors(source, [HintCode.DEPRECATED_MEMBER_USE]); 796 assertErrors(source, [HintCode.DEPRECATED_MEMBER_USE]);
793 verify([source]); 797 verify([source]);
794 } 798 }
795 799
800 void test_deprecatedAnnotationUse_positional() {
801 Source source = addSource(r'''
802 class A {
803 m([@deprecated int x]) {}
804 n() {m(1);}
805 }''');
806 computeLibrarySourceErrors(source);
807 assertErrors(source, [HintCode.DEPRECATED_MEMBER_USE]);
808 verify([source]);
809 }
810
796 void test_deprecatedAnnotationUse_setter() { 811 void test_deprecatedAnnotationUse_setter() {
797 Source source = addSource(r''' 812 Source source = addSource(r'''
798 class A { 813 class A {
799 @deprecated 814 @deprecated
800 set s(v) {} 815 set s(v) {}
801 } 816 }
802 f(A a) { 817 f(A a) {
803 return a.s = 1; 818 return a.s = 1;
804 }'''); 819 }''');
805 computeLibrarySourceErrors(source); 820 computeLibrarySourceErrors(source);
(...skipping 22 matching lines...) Expand all
828 A.named() {} 843 A.named() {}
829 } 844 }
830 class B extends A { 845 class B extends A {
831 B() : super.named() {} 846 B() : super.named() {}
832 }'''); 847 }''');
833 computeLibrarySourceErrors(source); 848 computeLibrarySourceErrors(source);
834 assertErrors(source, [HintCode.DEPRECATED_MEMBER_USE]); 849 assertErrors(source, [HintCode.DEPRECATED_MEMBER_USE]);
835 verify([source]); 850 verify([source]);
836 } 851 }
837 852
838 void test_deprecatedAnnotationUse_call() {
839 Source source = addSource(r'''
840 class A {
841 @deprecated
842 call() {}
843 m() {
844 A a = new A();
845 a();
846 }
847 }''');
848 computeLibrarySourceErrors(source);
849 assertErrors(source, [HintCode.DEPRECATED_MEMBER_USE]);
850 verify([source]);
851 }
852
853 void test_divisionOptimization_double() { 853 void test_divisionOptimization_double() {
854 Source source = addSource(r''' 854 Source source = addSource(r'''
855 f(double x, double y) { 855 f(double x, double y) {
856 var v = (x / y).toInt(); 856 var v = (x / y).toInt();
857 }'''); 857 }''');
858 computeLibrarySourceErrors(source); 858 computeLibrarySourceErrors(source);
859 assertErrors(source, [HintCode.DIVISION_OPTIMIZATION]); 859 assertErrors(source, [HintCode.DIVISION_OPTIMIZATION]);
860 verify([source]); 860 verify([source]);
861 } 861 }
862 862
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
1029 verify([source]); 1029 verify([source]);
1030 } 1030 }
1031 1031
1032 void test_invalidUseOfProtectedMember_field() { 1032 void test_invalidUseOfProtectedMember_field() {
1033 Source source = addSource(r''' 1033 Source source = addSource(r'''
1034 import 'package:meta/meta.dart'; 1034 import 'package:meta/meta.dart';
1035 class A { 1035 class A {
1036 @protected 1036 @protected
1037 int a; 1037 int a;
1038 } 1038 }
1039 abstract class B {
1040 int b() => new A().a;
1041 }''');
1042 computeLibrarySourceErrors(source);
1043 assertErrors(source, [HintCode.INVALID_USE_OF_PROTECTED_MEMBER]);
1044 verify([source]);
1045 }
1046
1047 void test_invalidUseOfProtectedMember_field_OK() {
1048 Source source = addSource(r'''
1049 import 'package:meta/meta.dart';
1050 class A {
1051 @protected
1052 int a;
1053 }
1039 abstract class B implements A { 1054 abstract class B implements A {
1040 int b() => a; 1055 int b() => a;
1041 }'''); 1056 }''');
1042 computeLibrarySourceErrors(source); 1057 computeLibrarySourceErrors(source);
1043 assertErrors(source, [HintCode.INVALID_USE_OF_PROTECTED_MEMBER]); 1058 assertNoErrors(source);
1044 verify([source]); 1059 verify([source]);
1045 } 1060 }
1046 1061
1047 void test_invalidUseOfProtectedMember_function() { 1062 void test_invalidUseOfProtectedMember_function() {
1048 Source source = addSource(r''' 1063 Source source = addSource(r'''
1049 import 'package:meta/meta.dart'; 1064 import 'package:meta/meta.dart';
1050 class A { 1065 class A {
1051 @protected 1066 @protected
1052 void a(){ } 1067 void a(){ }
1053 } 1068 }
1054 main() { 1069 main() {
1055 new A().a(); 1070 new A().a();
1056 }'''); 1071 }''');
1057 computeLibrarySourceErrors(source); 1072 computeLibrarySourceErrors(source);
1058 assertErrors(source, [HintCode.INVALID_USE_OF_PROTECTED_MEMBER]); 1073 assertErrors(source, [HintCode.INVALID_USE_OF_PROTECTED_MEMBER]);
1059 verify([source]); 1074 verify([source]);
1060 } 1075 }
1061 1076
1077 void test_invalidUseOfProtectedMember_function_OK() {
1078 Source source = addSource(r'''
1079 import 'package:meta/meta.dart';
1080 class A {
1081 @protected
1082 int a() => 0;
1083 }
1084
1085 abstract class B implements A {
1086 int b() => a();
1087 }''');
1088 computeLibrarySourceErrors(source);
1089 assertNoErrors(source);
1090 verify([source]);
1091 }
1092
1062 void test_invalidUseOfProtectedMember_getter() { 1093 void test_invalidUseOfProtectedMember_getter() {
1063 Source source = addSource(r''' 1094 Source source = addSource(r'''
1064 import 'package:meta/meta.dart'; 1095 import 'package:meta/meta.dart';
1065 class A { 1096 class A {
1066 @protected 1097 @protected
1067 int get a => 42; 1098 int get a => 42;
1068 } 1099 }
1100 class B {
1101 A a;
1102 int b() => a.a;
1103 }''');
1104 computeLibrarySourceErrors(source);
1105 assertErrors(source, [HintCode.INVALID_USE_OF_PROTECTED_MEMBER]);
1106 verify([source]);
1107 }
1108
1109 void test_invalidUseOfProtectedMember_getter_OK() {
1110 Source source = addSource(r'''
1111 import 'package:meta/meta.dart';
1112 class A {
1113 @protected
1114 int get a => 42;
1115 }
1069 abstract class B implements A { 1116 abstract class B implements A {
1070 int b() => a; 1117 int b() => a;
1071 }'''); 1118 }''');
1072 computeLibrarySourceErrors(source); 1119 computeLibrarySourceErrors(source);
1073 assertErrors(source, [HintCode.INVALID_USE_OF_PROTECTED_MEMBER]); 1120 assertNoErrors(source);
1074 verify([source]); 1121 verify([source]);
1075 } 1122 }
1076 1123
1077 void test_invalidUseOfProtectedMember_message() { 1124 void test_invalidUseOfProtectedMember_message() {
1078 Source source = addSource(r''' 1125 Source source = addSource(r'''
1079 import 'package:meta/meta.dart'; 1126 import 'package:meta/meta.dart';
1080 class A { 1127 class A {
1081 @protected 1128 @protected
1082 void a(){ } 1129 void a(){ }
1083 } 1130 }
(...skipping 14 matching lines...) Expand all
1098 void a(){ } 1145 void a(){ }
1099 } 1146 }
1100 class B { 1147 class B {
1101 void b() => new A().a(); 1148 void b() => new A().a();
1102 }'''); 1149 }''');
1103 computeLibrarySourceErrors(source); 1150 computeLibrarySourceErrors(source);
1104 assertErrors(source, [HintCode.INVALID_USE_OF_PROTECTED_MEMBER]); 1151 assertErrors(source, [HintCode.INVALID_USE_OF_PROTECTED_MEMBER]);
1105 verify([source]); 1152 verify([source]);
1106 } 1153 }
1107 1154
1108 void test_invalidUseOfProtectedMember_method_2() {
1109 Source source = addSource(r'''
1110 import 'package:meta/meta.dart';
1111 class A {
1112 @protected
1113 void a(){ }
1114 }
1115 abstract class B implements A {
1116 void b() => a();
1117 }''');
1118 computeLibrarySourceErrors(source);
1119 assertErrors(source, [HintCode.INVALID_USE_OF_PROTECTED_MEMBER]);
1120 verify([source]);
1121 }
1122
1123 void test_invalidUseOfProtectedMember_OK_1() { 1155 void test_invalidUseOfProtectedMember_OK_1() {
1124 Source source = addSource(r''' 1156 Source source = addSource(r'''
1125 import 'package:meta/meta.dart'; 1157 import 'package:meta/meta.dart';
1126 class A { 1158 class A {
1127 @protected 1159 @protected
1128 void a(){ } 1160 void a(){ }
1129 } 1161 }
1130 class B extends A { 1162 class B extends A {
1131 void b() => a(); 1163 void b() => a();
1132 }'''); 1164 }''');
1133 computeLibrarySourceErrors(source); 1165 computeLibrarySourceErrors(source);
1134 assertErrors(source, []); 1166 assertNoErrors(source);
1135 verify([source]); 1167 verify([source]);
1136 } 1168 }
1137 1169
1138 void test_invalidUseOfProtectedMember_OK_2() { 1170 void test_invalidUseOfProtectedMember_OK_2() {
1139 Source source = addSource(r''' 1171 Source source = addSource(r'''
1140 import 'package:meta/meta.dart'; 1172 import 'package:meta/meta.dart';
1141 class A { 1173 class A {
1142 @protected 1174 @protected
1143 void a(){ } 1175 void a(){ }
1144 } 1176 }
1145 class B extends Object with A { 1177 class B extends Object with A {
1146 void b() => a(); 1178 void b() => a();
1147 }'''); 1179 }''');
1148 computeLibrarySourceErrors(source); 1180 computeLibrarySourceErrors(source);
1149 assertErrors(source, []); 1181 assertNoErrors(source);
1150 verify([source]); 1182 verify([source]);
1151 } 1183 }
1152 1184
1153 void test_invalidUseOfProtectedMember_OK_3() { 1185 void test_invalidUseOfProtectedMember_OK_3() {
1154 Source source = addSource(r''' 1186 Source source = addSource(r'''
1155 import 'package:meta/meta.dart'; 1187 import 'package:meta/meta.dart';
1156 class A { 1188 class A {
1157 @protected m1() {} 1189 @protected m1() {}
1158 } 1190 }
1159 class B extends A { 1191 class B extends A {
1160 static m2(A a) => a.m1(); 1192 static m2(A a) => a.m1();
1161 }'''); 1193 }''');
1162 computeLibrarySourceErrors(source); 1194 computeLibrarySourceErrors(source);
1163 assertErrors(source, []); 1195 assertNoErrors(source);
1164 verify([source]); 1196 verify([source]);
1165 } 1197 }
1166 1198
1167 void test_invalidUseOfProtectedMember_OK_4() { 1199 void test_invalidUseOfProtectedMember_OK_4() {
1168 Source source = addSource(r''' 1200 Source source = addSource(r'''
1169 import 'package:meta/meta.dart'; 1201 import 'package:meta/meta.dart';
1170 class A { 1202 class A {
1171 @protected 1203 @protected
1172 void a(){ } 1204 void a(){ }
1173 } 1205 }
1174 class B extends A { 1206 class B extends A {
1175 void a() => a(); 1207 void a() => a();
1176 } 1208 }
1177 main() { 1209 main() {
1178 new B().a(); 1210 new B().a();
1179 }'''); 1211 }''');
1180 computeLibrarySourceErrors(source); 1212 computeLibrarySourceErrors(source);
1181 assertErrors(source, []); 1213 assertNoErrors(source);
1182 verify([source]); 1214 verify([source]);
1183 } 1215 }
1184 1216
1185 void test_invalidUseOfProtectedMember_OK_field() { 1217 void test_invalidUseOfProtectedMember_OK_field() {
1186 Source source = addSource(r''' 1218 Source source = addSource(r'''
1187 import 'package:meta/meta.dart'; 1219 import 'package:meta/meta.dart';
1188 class A { 1220 class A {
1189 @protected 1221 @protected
1190 int a = 42; 1222 int a = 42;
1191 } 1223 }
1192 class B extends A { 1224 class B extends A {
1193 int b() => a; 1225 int b() => a;
1194 } 1226 }
1195 '''); 1227 ''');
1196 computeLibrarySourceErrors(source); 1228 computeLibrarySourceErrors(source);
1197 assertErrors(source, []); 1229 assertNoErrors(source);
1198 verify([source]); 1230 verify([source]);
1199 } 1231 }
1200 1232
1201 void test_invalidUseOfProtectedMember_OK_getter() { 1233 void test_invalidUseOfProtectedMember_OK_getter() {
1202 Source source = addSource(r''' 1234 Source source = addSource(r'''
1203 import 'package:meta/meta.dart'; 1235 import 'package:meta/meta.dart';
1204 class A { 1236 class A {
1205 @protected 1237 @protected
1206 int get a => 42; 1238 int get a => 42;
1207 } 1239 }
1208 class B extends A { 1240 class B extends A {
1209 int b() => a; 1241 int b() => a;
1210 } 1242 }
1211 '''); 1243 ''');
1212 computeLibrarySourceErrors(source); 1244 computeLibrarySourceErrors(source);
1213 assertErrors(source, []); 1245 assertNoErrors(source);
1214 verify([source]); 1246 verify([source]);
1215 } 1247 }
1216 1248
1217 void test_invalidUseOfProtectedMember_OK_setter() { 1249 void test_invalidUseOfProtectedMember_OK_setter() {
1218 Source source = addSource(r''' 1250 Source source = addSource(r'''
1219 import 'package:meta/meta.dart'; 1251 import 'package:meta/meta.dart';
1220 class A { 1252 class A {
1221 @protected 1253 @protected
1222 void set a(int i) { } 1254 void set a(int i) { }
1223 } 1255 }
1224 class B extends A { 1256 class B extends A {
1225 void b(int i) { 1257 void b(int i) {
1226 a = i; 1258 a = i;
1227 } 1259 }
1228 } 1260 }
1229 '''); 1261 ''');
1230 computeLibrarySourceErrors(source); 1262 computeLibrarySourceErrors(source);
1231 assertErrors(source, []); 1263 assertNoErrors(source);
1232 verify([source]); 1264 verify([source]);
1233 } 1265 }
1234 1266
1235 void test_invalidUseOfProtectedMember_setter() { 1267 void test_invalidUseOfProtectedMember_setter() {
1236 Source source = addSource(r''' 1268 Source source = addSource(r'''
1237 import 'package:meta/meta.dart'; 1269 import 'package:meta/meta.dart';
1238 class A { 1270 class A {
1239 @protected 1271 @protected
1240 void set a(int i) { } 1272 void set a(int i) { }
1241 } 1273 }
1274 class B{
1275 A a;
1276 b(int i) {
1277 a.a = i;
1278 }
1279 }''');
1280 computeLibrarySourceErrors(source);
1281 assertErrors(source, [HintCode.INVALID_USE_OF_PROTECTED_MEMBER]);
1282 verify([source]);
1283 }
1284
1285 void test_invalidUseOfProtectedMember_setter_OK() {
1286 Source source = addSource(r'''
1287 import 'package:meta/meta.dart';
1288 class A {
1289 @protected
1290 void set a(int i) { }
1291 }
1242 abstract class B implements A { 1292 abstract class B implements A {
1243 b(int i) { 1293 b(int i) {
1244 a = i; 1294 a = i;
1245 } 1295 }
1246 }'''); 1296 }''');
1247 computeLibrarySourceErrors(source); 1297 computeLibrarySourceErrors(source);
1248 assertErrors(source, [HintCode.INVALID_USE_OF_PROTECTED_MEMBER]); 1298 assertNoErrors(source);
1249 verify([source]); 1299 verify([source]);
1250 } 1300 }
1251 1301
1252 void test_invalidUseOfProtectedMember_topLevelVariable() { 1302 void test_invalidUseOfProtectedMember_topLevelVariable() {
1253 Source source = addSource(r''' 1303 Source source = addSource(r'''
1254 import 'package:meta/meta.dart'; 1304 import 'package:meta/meta.dart';
1255 @protected 1305 @protected
1256 int x = 0; 1306 int x = 0;
1257 main() { 1307 main() {
1258 print(x); 1308 print(x);
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
1346 void test_missingReturn_async() { 1396 void test_missingReturn_async() {
1347 Source source = addSource(''' 1397 Source source = addSource('''
1348 import 'dart:async'; 1398 import 'dart:async';
1349 Future<int> f() async {} 1399 Future<int> f() async {}
1350 '''); 1400 ''');
1351 computeLibrarySourceErrors(source); 1401 computeLibrarySourceErrors(source);
1352 assertErrors(source, [HintCode.MISSING_RETURN]); 1402 assertErrors(source, [HintCode.MISSING_RETURN]);
1353 verify([source]); 1403 verify([source]);
1354 } 1404 }
1355 1405
1356 void test_missingReturn_function() {
1357 Source source = addSource("int f() {}");
1358 computeLibrarySourceErrors(source);
1359 assertErrors(source, [HintCode.MISSING_RETURN]);
1360 verify([source]);
1361 }
1362
1363 void test_missingReturn_factory() { 1406 void test_missingReturn_factory() {
1364 Source source = addSource(r''' 1407 Source source = addSource(r'''
1365 class A { 1408 class A {
1366 factory A() {} 1409 factory A() {}
1367 } 1410 }
1368 '''); 1411 ''');
1369 computeLibrarySourceErrors(source); 1412 computeLibrarySourceErrors(source);
1370 assertErrors(source, [HintCode.MISSING_RETURN]); 1413 assertErrors(source, [HintCode.MISSING_RETURN]);
1371 verify([source]); 1414 verify([source]);
1372 } 1415 }
1373 1416
1417 void test_missingReturn_function() {
1418 Source source = addSource("int f() {}");
1419 computeLibrarySourceErrors(source);
1420 assertErrors(source, [HintCode.MISSING_RETURN]);
1421 verify([source]);
1422 }
1423
1374 void test_missingReturn_method() { 1424 void test_missingReturn_method() {
1375 Source source = addSource(r''' 1425 Source source = addSource(r'''
1376 class A { 1426 class A {
1377 int m() {} 1427 int m() {}
1378 }'''); 1428 }''');
1379 computeLibrarySourceErrors(source); 1429 computeLibrarySourceErrors(source);
1380 assertErrors(source, [HintCode.MISSING_RETURN]); 1430 assertErrors(source, [HintCode.MISSING_RETURN]);
1381 verify([source]); 1431 verify([source]);
1382 } 1432 }
1383 1433
(...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after
1774 void test_typeCheck_type_not_Null() { 1824 void test_typeCheck_type_not_Null() {
1775 Source source = addSource(r''' 1825 Source source = addSource(r'''
1776 m(i) { 1826 m(i) {
1777 bool b = i is! Null; 1827 bool b = i is! Null;
1778 }'''); 1828 }''');
1779 computeLibrarySourceErrors(source); 1829 computeLibrarySourceErrors(source);
1780 assertErrors(source, [HintCode.TYPE_CHECK_IS_NOT_NULL]); 1830 assertErrors(source, [HintCode.TYPE_CHECK_IS_NOT_NULL]);
1781 verify([source]); 1831 verify([source]);
1782 } 1832 }
1783 1833
1784 void test_undefinedIdentifier_importHide() { 1834 void test_undefinedGetter() {
1785 Source source = addSource(r''' 1835 Source source = addSource(r'''
1786 library L; 1836 class A {}
1787 import 'lib1.dart' hide a;'''); 1837 f(var a) {
1788 addNamedSource("/lib1.dart", "library lib1;"); 1838 if(a is A) {
1839 return a.m;
1840 }
1841 }''');
1789 computeLibrarySourceErrors(source); 1842 computeLibrarySourceErrors(source);
1790 assertErrors( 1843 assertErrors(source, [HintCode.UNDEFINED_GETTER]);
1791 source, [HintCode.UNUSED_IMPORT, HintCode.UNDEFINED_HIDDEN_NAME]);
1792 verify([source]);
1793 } 1844 }
1794 1845
1795 void test_undefinedIdentifier_importShow() { 1846 void test_undefinedGetter_message() {
1796 Source source = addSource(r''' 1847 // The implementation of HintCode.UNDEFINED_SETTER assumes that
1797 library L; 1848 // UNDEFINED_SETTER in StaticTypeWarningCode and StaticWarningCode are the
1798 import 'lib1.dart' show a;'''); 1849 // same, this verifies that assumption.
1799 addNamedSource("/lib1.dart", "library lib1;"); 1850 expect(StaticWarningCode.UNDEFINED_GETTER.message,
1800 computeLibrarySourceErrors(source); 1851 StaticTypeWarningCode.UNDEFINED_GETTER.message);
1801 assertErrors(
1802 source, [HintCode.UNUSED_IMPORT, HintCode.UNDEFINED_SHOWN_NAME]);
1803 verify([source]);
1804 } 1852 }
1805 1853
1806 void test_undefinedIdentifier_exportHide() { 1854 void test_undefinedIdentifier_exportHide() {
1807 Source source = addSource(r''' 1855 Source source = addSource(r'''
1808 library L; 1856 library L;
1809 export 'lib1.dart' hide a;'''); 1857 export 'lib1.dart' hide a;''');
1810 addNamedSource("/lib1.dart", "library lib1;"); 1858 addNamedSource("/lib1.dart", "library lib1;");
1811 computeLibrarySourceErrors(source); 1859 computeLibrarySourceErrors(source);
1812 assertErrors(source, [HintCode.UNDEFINED_HIDDEN_NAME]); 1860 assertErrors(source, [HintCode.UNDEFINED_HIDDEN_NAME]);
1813 verify([source]); 1861 verify([source]);
1814 } 1862 }
1815 1863
1816 void test_undefinedIdentifier_exportShow() { 1864 void test_undefinedIdentifier_exportShow() {
1817 Source source = addSource(r''' 1865 Source source = addSource(r'''
1818 library L; 1866 library L;
1819 export 'lib1.dart' show a;'''); 1867 export 'lib1.dart' show a;''');
1820 addNamedSource("/lib1.dart", "library lib1;"); 1868 addNamedSource("/lib1.dart", "library lib1;");
1821 computeLibrarySourceErrors(source); 1869 computeLibrarySourceErrors(source);
1822 assertErrors(source, [HintCode.UNDEFINED_SHOWN_NAME]); 1870 assertErrors(source, [HintCode.UNDEFINED_SHOWN_NAME]);
1823 verify([source]); 1871 verify([source]);
1824 } 1872 }
1825 1873
1826 void test_undefinedGetter() { 1874 void test_undefinedIdentifier_importHide() {
1827 Source source = addSource(r''' 1875 Source source = addSource(r'''
1828 class A {} 1876 library L;
1829 f(var a) { 1877 import 'lib1.dart' hide a;''');
1830 if(a is A) { 1878 addNamedSource("/lib1.dart", "library lib1;");
1831 return a.m;
1832 }
1833 }''');
1834 computeLibrarySourceErrors(source); 1879 computeLibrarySourceErrors(source);
1835 assertErrors(source, [HintCode.UNDEFINED_GETTER]); 1880 assertErrors(
1881 source, [HintCode.UNUSED_IMPORT, HintCode.UNDEFINED_HIDDEN_NAME]);
1882 verify([source]);
1836 } 1883 }
1837 1884
1838 void test_undefinedGetter_message() { 1885 void test_undefinedIdentifier_importShow() {
1839 // The implementation of HintCode.UNDEFINED_SETTER assumes that 1886 Source source = addSource(r'''
1840 // UNDEFINED_SETTER in StaticTypeWarningCode and StaticWarningCode are the 1887 library L;
1841 // same, this verifies that assumption. 1888 import 'lib1.dart' show a;''');
1842 expect(StaticWarningCode.UNDEFINED_GETTER.message, 1889 addNamedSource("/lib1.dart", "library lib1;");
1843 StaticTypeWarningCode.UNDEFINED_GETTER.message); 1890 computeLibrarySourceErrors(source);
1891 assertErrors(
1892 source, [HintCode.UNUSED_IMPORT, HintCode.UNDEFINED_SHOWN_NAME]);
1893 verify([source]);
1844 } 1894 }
1845 1895
1846 void test_undefinedMethod() { 1896 void test_undefinedMethod() {
1847 Source source = addSource(r''' 1897 Source source = addSource(r'''
1848 f() { 1898 f() {
1849 var a = 'str'; 1899 var a = 'str';
1850 a.notAMethodOnString(); 1900 a.notAMethodOnString();
1851 }'''); 1901 }''');
1852 computeLibrarySourceErrors(source); 1902 computeLibrarySourceErrors(source);
1853 assertErrors(source, [HintCode.UNDEFINED_METHOD]); 1903 assertErrors(source, [HintCode.UNDEFINED_METHOD]);
(...skipping 1179 matching lines...) Expand 10 before | Expand all | Expand 10 after
3033 r''' 3083 r'''
3034 library lib1; 3084 library lib1;
3035 class A {} 3085 class A {}
3036 class B {}'''); 3086 class B {}''');
3037 computeLibrarySourceErrors(source); 3087 computeLibrarySourceErrors(source);
3038 assertErrors(source, [HintCode.UNUSED_IMPORT]); 3088 assertErrors(source, [HintCode.UNUSED_IMPORT]);
3039 assertNoErrors(source2); 3089 assertNoErrors(source2);
3040 verify([source, source2]); 3090 verify([source, source2]);
3041 } 3091 }
3042 3092
3043 void test_unusedShownName() {
3044 Source source = addSource(r'''
3045 library L;
3046 import 'lib1.dart' show A, B;
3047 A a;''');
3048 Source source2 = addNamedSource(
3049 "/lib1.dart",
3050 r'''
3051 library lib1;
3052 class A {}
3053 class B {}''');
3054 computeLibrarySourceErrors(source);
3055 assertErrors(source, [HintCode.UNUSED_SHOWN_NAME]);
3056 assertNoErrors(source2);
3057 verify([source, source2]);
3058 }
3059
3060 void test_unusedShownName_topLevelVariable() {
3061 Source source = addSource(r'''
3062 library L;
3063 import 'lib1.dart' show var1, var2;
3064 import 'lib1.dart' show var3, var4;
3065 int a = var1;
3066 int b = var2;
3067 int c = var3;''');
3068 Source source2 = addNamedSource(
3069 "/lib1.dart",
3070 r'''
3071 library lib1;
3072 const int var1 = 1;
3073 const int var2 = 2;
3074 const int var3 = 3;
3075 const int var4 = 4;''');
3076 computeLibrarySourceErrors(source);
3077 assertErrors(source, [HintCode.UNUSED_SHOWN_NAME]);
3078 assertNoErrors(source2);
3079 verify([source, source2]);
3080 }
3081
3082 void test_unusedShownName_as() {
3083 Source source = addSource(r'''
3084 library L;
3085 import 'lib1.dart' as p show A, B;
3086 p.A a;''');
3087 Source source2 = addNamedSource(
3088 "/lib1.dart",
3089 r'''
3090 library lib1;
3091 class A {}
3092 class B {}''');
3093 computeLibrarySourceErrors(source);
3094 assertErrors(source, [HintCode.UNUSED_SHOWN_NAME]);
3095 assertNoErrors(source2);
3096 verify([source, source2]);
3097 }
3098
3099 void test_unusedShownName_duplicates() {
3100 Source source = addSource(r'''
3101 library L;
3102 import 'lib1.dart' show A, B;
3103 import 'lib1.dart' show C, D;
3104 A a;
3105 C c;''');
3106 Source source2 = addNamedSource(
3107 "/lib1.dart",
3108 r'''
3109 library lib1;
3110 class A {}
3111 class B {}
3112 class C {}
3113 class D {}''');
3114 computeLibrarySourceErrors(source);
3115 assertErrors(
3116 source, [HintCode.UNUSED_SHOWN_NAME, HintCode.UNUSED_SHOWN_NAME]);
3117 assertNoErrors(source2);
3118 verify([source, source2]);
3119 }
3120
3121 void test_unusedLocalVariable_inCatch_exception() { 3093 void test_unusedLocalVariable_inCatch_exception() {
3122 enableUnusedLocalVariable = true; 3094 enableUnusedLocalVariable = true;
3123 Source source = addSource(r''' 3095 Source source = addSource(r'''
3124 main() { 3096 main() {
3125 try { 3097 try {
3126 } on String catch (exception) { 3098 } on String catch (exception) {
3127 } 3099 }
3128 }'''); 3100 }''');
3129 computeLibrarySourceErrors(source); 3101 computeLibrarySourceErrors(source);
3130 assertErrors(source, [HintCode.UNUSED_CATCH_CLAUSE]); 3102 assertErrors(source, [HintCode.UNUSED_CATCH_CLAUSE]);
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
3298 main() { 3270 main() {
3299 var a = new A(); 3271 var a = new A();
3300 a.foo(); 3272 a.foo();
3301 } 3273 }
3302 '''); 3274 ''');
3303 computeLibrarySourceErrors(source); 3275 computeLibrarySourceErrors(source);
3304 assertErrors(source); 3276 assertErrors(source);
3305 verify([source]); 3277 verify([source]);
3306 } 3278 }
3307 3279
3280 void test_unusedShownName() {
3281 Source source = addSource(r'''
3282 library L;
3283 import 'lib1.dart' show A, B;
3284 A a;''');
3285 Source source2 = addNamedSource(
3286 "/lib1.dart",
3287 r'''
3288 library lib1;
3289 class A {}
3290 class B {}''');
3291 computeLibrarySourceErrors(source);
3292 assertErrors(source, [HintCode.UNUSED_SHOWN_NAME]);
3293 assertNoErrors(source2);
3294 verify([source, source2]);
3295 }
3296
3297 void test_unusedShownName_as() {
3298 Source source = addSource(r'''
3299 library L;
3300 import 'lib1.dart' as p show A, B;
3301 p.A a;''');
3302 Source source2 = addNamedSource(
3303 "/lib1.dart",
3304 r'''
3305 library lib1;
3306 class A {}
3307 class B {}''');
3308 computeLibrarySourceErrors(source);
3309 assertErrors(source, [HintCode.UNUSED_SHOWN_NAME]);
3310 assertNoErrors(source2);
3311 verify([source, source2]);
3312 }
3313
3314 void test_unusedShownName_duplicates() {
3315 Source source = addSource(r'''
3316 library L;
3317 import 'lib1.dart' show A, B;
3318 import 'lib1.dart' show C, D;
3319 A a;
3320 C c;''');
3321 Source source2 = addNamedSource(
3322 "/lib1.dart",
3323 r'''
3324 library lib1;
3325 class A {}
3326 class B {}
3327 class C {}
3328 class D {}''');
3329 computeLibrarySourceErrors(source);
3330 assertErrors(
3331 source, [HintCode.UNUSED_SHOWN_NAME, HintCode.UNUSED_SHOWN_NAME]);
3332 assertNoErrors(source2);
3333 verify([source, source2]);
3334 }
3335
3336 void test_unusedShownName_topLevelVariable() {
3337 Source source = addSource(r'''
3338 library L;
3339 import 'lib1.dart' show var1, var2;
3340 import 'lib1.dart' show var3, var4;
3341 int a = var1;
3342 int b = var2;
3343 int c = var3;''');
3344 Source source2 = addNamedSource(
3345 "/lib1.dart",
3346 r'''
3347 library lib1;
3348 const int var1 = 1;
3349 const int var2 = 2;
3350 const int var3 = 3;
3351 const int var4 = 4;''');
3352 computeLibrarySourceErrors(source);
3353 assertErrors(source, [HintCode.UNUSED_SHOWN_NAME]);
3354 assertNoErrors(source2);
3355 verify([source, source2]);
3356 }
3357
3308 void test_useOfVoidResult_assignmentExpression_function() { 3358 void test_useOfVoidResult_assignmentExpression_function() {
3309 Source source = addSource(r''' 3359 Source source = addSource(r'''
3310 void f() {} 3360 void f() {}
3311 class A { 3361 class A {
3312 n() { 3362 n() {
3313 var a; 3363 var a;
3314 a = f(); 3364 a = f();
3315 } 3365 }
3316 }'''); 3366 }''');
3317 computeLibrarySourceErrors(source); 3367 computeLibrarySourceErrors(source);
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
3379 n() { 3429 n() {
3380 var a = m(), b = m(); 3430 var a = m(), b = m();
3381 } 3431 }
3382 }'''); 3432 }''');
3383 computeLibrarySourceErrors(source); 3433 computeLibrarySourceErrors(source);
3384 assertErrors( 3434 assertErrors(
3385 source, [HintCode.USE_OF_VOID_RESULT, HintCode.USE_OF_VOID_RESULT]); 3435 source, [HintCode.USE_OF_VOID_RESULT, HintCode.USE_OF_VOID_RESULT]);
3386 verify([source]); 3436 verify([source]);
3387 } 3437 }
3388 } 3438 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/generated/resolver.dart ('k') | pkg/meta/CHANGELOG.md » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698