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

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

Issue 2626653002: Remove computeLibrarySourceErrors(). (Closed)
Patch Set: Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 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.non_hint_code_test; 5 library analyzer.test.generated.non_hint_code_test;
6 6
7 import 'package:analyzer/error/error.dart'; 7 import 'package:analyzer/error/error.dart';
8 import 'package:analyzer/src/error/codes.dart'; 8 import 'package:analyzer/src/error/codes.dart';
9 import 'package:analyzer/src/generated/engine.dart'; 9 import 'package:analyzer/src/generated/engine.dart';
10 import 'package:analyzer/src/generated/source_io.dart'; 10 import 'package:analyzer/src/generated/source_io.dart';
(...skipping 14 matching lines...) Expand all
25 Source source = addSource(r''' 25 Source source = addSource(r'''
26 abstract class A { 26 abstract class A {
27 void test(); 27 void test();
28 } 28 }
29 class B extends A { 29 class B extends A {
30 void test() { 30 void test() {
31 super.test; 31 super.test;
32 } 32 }
33 } 33 }
34 '''); 34 ''');
35 computeLibrarySourceErrors(source);
36 assertNoErrors(source); 35 assertNoErrors(source);
37 verify([source]); 36 verify([source]);
38 } 37 }
39 38
40 void test_deadCode_afterTryCatch() { 39 void test_deadCode_afterTryCatch() {
41 Source source = addSource(''' 40 Source source = addSource('''
42 main() { 41 main() {
43 try { 42 try {
44 return f(); 43 return f();
45 } catch (e) { 44 } catch (e) {
46 print(e); 45 print(e);
47 } 46 }
48 print('not dead'); 47 print('not dead');
49 } 48 }
50 f() { 49 f() {
51 throw 'foo'; 50 throw 'foo';
52 } 51 }
53 '''); 52 ''');
54 computeLibrarySourceErrors(source);
55 assertNoErrors(source); 53 assertNoErrors(source);
56 verify([source]); 54 verify([source]);
57 } 55 }
58 56
59 void test_deadCode_deadBlock_conditionalElse_debugConst() { 57 void test_deadCode_deadBlock_conditionalElse_debugConst() {
60 Source source = addSource(r''' 58 Source source = addSource(r'''
61 const bool DEBUG = true; 59 const bool DEBUG = true;
62 f() { 60 f() {
63 DEBUG ? 1 : 2; 61 DEBUG ? 1 : 2;
64 }'''); 62 }''');
65 computeLibrarySourceErrors(source);
66 assertNoErrors(source); 63 assertNoErrors(source);
67 verify([source]); 64 verify([source]);
68 } 65 }
69 66
70 void test_deadCode_deadBlock_conditionalIf_debugConst() { 67 void test_deadCode_deadBlock_conditionalIf_debugConst() {
71 Source source = addSource(r''' 68 Source source = addSource(r'''
72 const bool DEBUG = false; 69 const bool DEBUG = false;
73 f() { 70 f() {
74 DEBUG ? 1 : 2; 71 DEBUG ? 1 : 2;
75 }'''); 72 }''');
76 computeLibrarySourceErrors(source);
77 assertNoErrors(source); 73 assertNoErrors(source);
78 verify([source]); 74 verify([source]);
79 } 75 }
80 76
81 void test_deadCode_deadBlock_else() { 77 void test_deadCode_deadBlock_else() {
82 Source source = addSource(r''' 78 Source source = addSource(r'''
83 const bool DEBUG = true; 79 const bool DEBUG = true;
84 f() { 80 f() {
85 if(DEBUG) {} else {} 81 if(DEBUG) {} else {}
86 }'''); 82 }''');
87 computeLibrarySourceErrors(source);
88 assertNoErrors(source); 83 assertNoErrors(source);
89 verify([source]); 84 verify([source]);
90 } 85 }
91 86
92 void test_deadCode_deadBlock_if_debugConst_prefixedIdentifier() { 87 void test_deadCode_deadBlock_if_debugConst_prefixedIdentifier() {
93 Source source = addSource(r''' 88 Source source = addSource(r'''
94 class A { 89 class A {
95 static const bool DEBUG = false; 90 static const bool DEBUG = false;
96 } 91 }
97 f() { 92 f() {
98 if(A.DEBUG) {} 93 if(A.DEBUG) {}
99 }'''); 94 }''');
100 computeLibrarySourceErrors(source);
101 assertNoErrors(source); 95 assertNoErrors(source);
102 verify([source]); 96 verify([source]);
103 } 97 }
104 98
105 void test_deadCode_deadBlock_if_debugConst_prefixedIdentifier2() { 99 void test_deadCode_deadBlock_if_debugConst_prefixedIdentifier2() {
106 Source source = addSource(r''' 100 Source source = addSource(r'''
107 library L; 101 library L;
108 import 'lib2.dart'; 102 import 'lib2.dart';
109 f() { 103 f() {
110 if(A.DEBUG) {} 104 if(A.DEBUG) {}
111 }'''); 105 }''');
112 addNamedSource( 106 addNamedSource(
113 "/lib2.dart", 107 "/lib2.dart",
114 r''' 108 r'''
115 library lib2; 109 library lib2;
116 class A { 110 class A {
117 static const bool DEBUG = false; 111 static const bool DEBUG = false;
118 }'''); 112 }''');
119 computeLibrarySourceErrors(source);
120 assertNoErrors(source); 113 assertNoErrors(source);
121 verify([source]); 114 verify([source]);
122 } 115 }
123 116
124 void test_deadCode_deadBlock_if_debugConst_propertyAccessor() { 117 void test_deadCode_deadBlock_if_debugConst_propertyAccessor() {
125 Source source = addSource(r''' 118 Source source = addSource(r'''
126 library L; 119 library L;
127 import 'lib2.dart' as LIB; 120 import 'lib2.dart' as LIB;
128 f() { 121 f() {
129 if(LIB.A.DEBUG) {} 122 if(LIB.A.DEBUG) {}
130 }'''); 123 }''');
131 addNamedSource( 124 addNamedSource(
132 "/lib2.dart", 125 "/lib2.dart",
133 r''' 126 r'''
134 library lib2; 127 library lib2;
135 class A { 128 class A {
136 static const bool DEBUG = false; 129 static const bool DEBUG = false;
137 }'''); 130 }''');
138 computeLibrarySourceErrors(source);
139 assertNoErrors(source); 131 assertNoErrors(source);
140 verify([source]); 132 verify([source]);
141 } 133 }
142 134
143 void test_deadCode_deadBlock_if_debugConst_simpleIdentifier() { 135 void test_deadCode_deadBlock_if_debugConst_simpleIdentifier() {
144 Source source = addSource(r''' 136 Source source = addSource(r'''
145 const bool DEBUG = false; 137 const bool DEBUG = false;
146 f() { 138 f() {
147 if(DEBUG) {} 139 if(DEBUG) {}
148 }'''); 140 }''');
149 computeLibrarySourceErrors(source);
150 assertNoErrors(source); 141 assertNoErrors(source);
151 verify([source]); 142 verify([source]);
152 } 143 }
153 144
154 void test_deadCode_deadBlock_while_debugConst() { 145 void test_deadCode_deadBlock_while_debugConst() {
155 Source source = addSource(r''' 146 Source source = addSource(r'''
156 const bool DEBUG = false; 147 const bool DEBUG = false;
157 f() { 148 f() {
158 while(DEBUG) {} 149 while(DEBUG) {}
159 }'''); 150 }''');
160 computeLibrarySourceErrors(source);
161 assertNoErrors(source); 151 assertNoErrors(source);
162 verify([source]); 152 verify([source]);
163 } 153 }
164 154
165 void test_deadCode_deadCatch_onCatchSubtype() { 155 void test_deadCode_deadCatch_onCatchSubtype() {
166 Source source = addSource(r''' 156 Source source = addSource(r'''
167 class A {} 157 class A {}
168 class B extends A {} 158 class B extends A {}
169 f() { 159 f() {
170 try {} on B catch (e) {} on A catch (e) {} catch (e) {} 160 try {} on B catch (e) {} on A catch (e) {} catch (e) {}
171 }'''); 161 }''');
172 computeLibrarySourceErrors(source);
173 assertNoErrors(source); 162 assertNoErrors(source);
174 verify([source]); 163 verify([source]);
175 } 164 }
176 165
177 void test_deadCode_deadFinalBreakInCase() { 166 void test_deadCode_deadFinalBreakInCase() {
178 Source source = addSource(r''' 167 Source source = addSource(r'''
179 f() { 168 f() {
180 switch (true) { 169 switch (true) {
181 case true: 170 case true:
182 try { 171 try {
183 int a = 1; 172 int a = 1;
184 } finally { 173 } finally {
185 return; 174 return;
186 } 175 }
187 break; 176 break;
188 default: 177 default:
189 break; 178 break;
190 } 179 }
191 }'''); 180 }''');
192 computeLibrarySourceErrors(source);
193 assertNoErrors(source); 181 assertNoErrors(source);
194 verify([source]); 182 verify([source]);
195 } 183 }
196 184
197 void test_deadCode_deadOperandLHS_and_debugConst() { 185 void test_deadCode_deadOperandLHS_and_debugConst() {
198 Source source = addSource(r''' 186 Source source = addSource(r'''
199 const bool DEBUG = false; 187 const bool DEBUG = false;
200 f() { 188 f() {
201 bool b = DEBUG && false; 189 bool b = DEBUG && false;
202 }'''); 190 }''');
203 computeLibrarySourceErrors(source);
204 assertNoErrors(source); 191 assertNoErrors(source);
205 verify([source]); 192 verify([source]);
206 } 193 }
207 194
208 void test_deadCode_deadOperandLHS_or_debugConst() { 195 void test_deadCode_deadOperandLHS_or_debugConst() {
209 Source source = addSource(r''' 196 Source source = addSource(r'''
210 const bool DEBUG = true; 197 const bool DEBUG = true;
211 f() { 198 f() {
212 bool b = DEBUG || true; 199 bool b = DEBUG || true;
213 }'''); 200 }''');
214 computeLibrarySourceErrors(source);
215 assertNoErrors(source); 201 assertNoErrors(source);
216 verify([source]); 202 verify([source]);
217 } 203 }
218 204
219 void test_deadCode_statementAfterIfWithoutElse() { 205 void test_deadCode_statementAfterIfWithoutElse() {
220 Source source = addSource(r''' 206 Source source = addSource(r'''
221 f() { 207 f() {
222 if (1 < 0) { 208 if (1 < 0) {
223 return; 209 return;
224 } 210 }
225 int a = 1; 211 int a = 1;
226 }'''); 212 }''');
227 computeLibrarySourceErrors(source);
228 assertNoErrors(source); 213 assertNoErrors(source);
229 verify([source]); 214 verify([source]);
230 } 215 }
231 216
232 void test_deprecatedMemberUse_inDeprecatedClass() { 217 void test_deprecatedMemberUse_inDeprecatedClass() {
233 Source source = addSource(r''' 218 Source source = addSource(r'''
234 @deprecated 219 @deprecated
235 f() {} 220 f() {}
236 221
237 @deprecated 222 @deprecated
238 class C { 223 class C {
239 m() { 224 m() {
240 f(); 225 f();
241 } 226 }
242 } 227 }
243 '''); 228 ''');
244 computeLibrarySourceErrors(source);
245 assertNoErrors(source); 229 assertNoErrors(source);
246 verify([source]); 230 verify([source]);
247 } 231 }
248 232
249 void test_deprecatedMemberUse_inDeprecatedFunction() { 233 void test_deprecatedMemberUse_inDeprecatedFunction() {
250 Source source = addSource(r''' 234 Source source = addSource(r'''
251 @deprecated 235 @deprecated
252 f() {} 236 f() {}
253 237
254 @deprecated 238 @deprecated
255 g() { 239 g() {
256 f(); 240 f();
257 } 241 }
258 '''); 242 ''');
259 computeLibrarySourceErrors(source);
260 assertNoErrors(source); 243 assertNoErrors(source);
261 verify([source]); 244 verify([source]);
262 } 245 }
263 246
264 void test_deprecatedMemberUse_inDeprecatedLibrary() { 247 void test_deprecatedMemberUse_inDeprecatedLibrary() {
265 Source source = addSource(r''' 248 Source source = addSource(r'''
266 @deprecated 249 @deprecated
267 library lib; 250 library lib;
268 251
269 @deprecated 252 @deprecated
270 f() {} 253 f() {}
271 254
272 class C { 255 class C {
273 m() { 256 m() {
274 f(); 257 f();
275 } 258 }
276 } 259 }
277 '''); 260 ''');
278 computeLibrarySourceErrors(source);
279 assertNoErrors(source); 261 assertNoErrors(source);
280 verify([source]); 262 verify([source]);
281 } 263 }
282 264
283 void test_deprecatedMemberUse_inDeprecatedMethod() { 265 void test_deprecatedMemberUse_inDeprecatedMethod() {
284 Source source = addSource(r''' 266 Source source = addSource(r'''
285 @deprecated 267 @deprecated
286 f() {} 268 f() {}
287 269
288 class C { 270 class C {
289 @deprecated 271 @deprecated
290 m() { 272 m() {
291 f(); 273 f();
292 } 274 }
293 } 275 }
294 '''); 276 ''');
295 computeLibrarySourceErrors(source);
296 assertNoErrors(source); 277 assertNoErrors(source);
297 verify([source]); 278 verify([source]);
298 } 279 }
299 280
300 void test_deprecatedMemberUse_inDeprecatedMethod_inDeprecatedClass() { 281 void test_deprecatedMemberUse_inDeprecatedMethod_inDeprecatedClass() {
301 Source source = addSource(r''' 282 Source source = addSource(r'''
302 @deprecated 283 @deprecated
303 f() {} 284 f() {}
304 285
305 @deprecated 286 @deprecated
306 class C { 287 class C {
307 @deprecated 288 @deprecated
308 m() { 289 m() {
309 f(); 290 f();
310 } 291 }
311 } 292 }
312 '''); 293 ''');
313 computeLibrarySourceErrors(source);
314 assertNoErrors(source); 294 assertNoErrors(source);
315 verify([source]); 295 verify([source]);
316 } 296 }
317 297
318 void test_divisionOptimization() { 298 void test_divisionOptimization() {
319 Source source = addSource(r''' 299 Source source = addSource(r'''
320 f(int x, int y) { 300 f(int x, int y) {
321 var v = x / y.toInt(); 301 var v = x / y.toInt();
322 }'''); 302 }''');
323 computeLibrarySourceErrors(source);
324 assertNoErrors(source); 303 assertNoErrors(source);
325 verify([source]); 304 verify([source]);
326 } 305 }
327 306
328 void test_divisionOptimization_supressIfDivisionNotDefinedInCore() { 307 void test_divisionOptimization_supressIfDivisionNotDefinedInCore() {
329 Source source = addSource(r''' 308 Source source = addSource(r'''
330 f(x, y) { 309 f(x, y) {
331 var v = (x / y).toInt(); 310 var v = (x / y).toInt();
332 }'''); 311 }''');
333 computeLibrarySourceErrors(source);
334 assertNoErrors(source); 312 assertNoErrors(source);
335 verify([source]); 313 verify([source]);
336 } 314 }
337 315
338 void test_divisionOptimization_supressIfDivisionOverridden() { 316 void test_divisionOptimization_supressIfDivisionOverridden() {
339 Source source = addSource(r''' 317 Source source = addSource(r'''
340 class A { 318 class A {
341 num operator /(x) { return x; } 319 num operator /(x) { return x; }
342 } 320 }
343 f(A x, A y) { 321 f(A x, A y) {
344 var v = (x / y).toInt(); 322 var v = (x / y).toInt();
345 }'''); 323 }''');
346 computeLibrarySourceErrors(source);
347 assertNoErrors(source); 324 assertNoErrors(source);
348 verify([source]); 325 verify([source]);
349 } 326 }
350 327
351 void test_duplicateImport_as() { 328 void test_duplicateImport_as() {
352 Source source = addSource(r''' 329 Source source = addSource(r'''
353 library L; 330 library L;
354 import 'lib1.dart'; 331 import 'lib1.dart';
355 import 'lib1.dart' as one; 332 import 'lib1.dart' as one;
356 A a; 333 A a;
357 one.A a2;'''); 334 one.A a2;''');
358 addNamedSource( 335 addNamedSource(
359 "/lib1.dart", 336 "/lib1.dart",
360 r''' 337 r'''
361 library lib1; 338 library lib1;
362 class A {}'''); 339 class A {}''');
363 computeLibrarySourceErrors(source);
364 assertNoErrors(source); 340 assertNoErrors(source);
365 verify([source]); 341 verify([source]);
366 } 342 }
367 343
368 void test_duplicateImport_hide() { 344 void test_duplicateImport_hide() {
369 Source source = addSource(r''' 345 Source source = addSource(r'''
370 library L; 346 library L;
371 import 'lib1.dart'; 347 import 'lib1.dart';
372 import 'lib1.dart' hide A; 348 import 'lib1.dart' hide A;
373 A a; 349 A a;
374 B b;'''); 350 B b;''');
375 addNamedSource( 351 addNamedSource(
376 "/lib1.dart", 352 "/lib1.dart",
377 r''' 353 r'''
378 library lib1; 354 library lib1;
379 class A {} 355 class A {}
380 class B {}'''); 356 class B {}''');
381 computeLibrarySourceErrors(source);
382 assertNoErrors(source); 357 assertNoErrors(source);
383 verify([source]); 358 verify([source]);
384 } 359 }
385 360
386 void test_duplicateImport_show() { 361 void test_duplicateImport_show() {
387 Source source = addSource(r''' 362 Source source = addSource(r'''
388 library L; 363 library L;
389 import 'lib1.dart'; 364 import 'lib1.dart';
390 import 'lib1.dart' show A; 365 import 'lib1.dart' show A;
391 A a; 366 A a;
392 B b;'''); 367 B b;''');
393 addNamedSource( 368 addNamedSource(
394 "/lib1.dart", 369 "/lib1.dart",
395 r''' 370 r'''
396 library lib1; 371 library lib1;
397 class A {} 372 class A {}
398 class B {}'''); 373 class B {}''');
399 computeLibrarySourceErrors(source);
400 assertNoErrors(source); 374 assertNoErrors(source);
401 verify([source]); 375 verify([source]);
402 } 376 }
403 377
404 void test_importDeferredLibraryWithLoadFunction() { 378 void test_importDeferredLibraryWithLoadFunction() {
405 resolveWithErrors(<String>[ 379 resolveWithErrors(<String>[
406 r''' 380 r'''
407 library lib1; 381 library lib1;
408 f() {}''', 382 f() {}''',
409 r''' 383 r'''
410 library root; 384 library root;
411 import 'lib1.dart' deferred as lib1; 385 import 'lib1.dart' deferred as lib1;
412 main() { lib1.f(); }''' 386 main() { lib1.f(); }'''
413 ], const <ErrorCode>[]); 387 ], const <ErrorCode>[]);
414 } 388 }
415 389
416 void test_issue20904BuggyTypePromotionAtIfJoin_1() { 390 void test_issue20904BuggyTypePromotionAtIfJoin_1() {
417 // https://code.google.com/p/dart/issues/detail?id=20904 391 // https://code.google.com/p/dart/issues/detail?id=20904
418 Source source = addSource(r''' 392 Source source = addSource(r'''
419 f(var message, var dynamic_) { 393 f(var message, var dynamic_) {
420 if (message is Function) { 394 if (message is Function) {
421 message = dynamic_; 395 message = dynamic_;
422 } 396 }
423 int s = message; 397 int s = message;
424 }'''); 398 }''');
425 computeLibrarySourceErrors(source);
426 assertNoErrors(source); 399 assertNoErrors(source);
427 verify([source]); 400 verify([source]);
428 } 401 }
429 402
430 void test_issue20904BuggyTypePromotionAtIfJoin_3() { 403 void test_issue20904BuggyTypePromotionAtIfJoin_3() {
431 // https://code.google.com/p/dart/issues/detail?id=20904 404 // https://code.google.com/p/dart/issues/detail?id=20904
432 Source source = addSource(r''' 405 Source source = addSource(r'''
433 f(var message) { 406 f(var message) {
434 var dynamic_; 407 var dynamic_;
435 if (message is Function) { 408 if (message is Function) {
436 message = dynamic_; 409 message = dynamic_;
437 } else { 410 } else {
438 return; 411 return;
439 } 412 }
440 int s = message; 413 int s = message;
441 }'''); 414 }''');
442 computeLibrarySourceErrors(source);
443 assertNoErrors(source); 415 assertNoErrors(source);
444 verify([source]); 416 verify([source]);
445 } 417 }
446 418
447 void test_issue20904BuggyTypePromotionAtIfJoin_4() { 419 void test_issue20904BuggyTypePromotionAtIfJoin_4() {
448 // https://code.google.com/p/dart/issues/detail?id=20904 420 // https://code.google.com/p/dart/issues/detail?id=20904
449 Source source = addSource(r''' 421 Source source = addSource(r'''
450 f(var message) { 422 f(var message) {
451 if (message is Function) { 423 if (message is Function) {
452 message = ''; 424 message = '';
453 } else { 425 } else {
454 return; 426 return;
455 } 427 }
456 String s = message; 428 String s = message;
457 }'''); 429 }''');
458 computeLibrarySourceErrors(source);
459 assertNoErrors(source); 430 assertNoErrors(source);
460 verify([source]); 431 verify([source]);
461 } 432 }
462 433
463 void test_missingReturn_emptyFunctionBody() { 434 void test_missingReturn_emptyFunctionBody() {
464 Source source = addSource(r''' 435 Source source = addSource(r'''
465 abstract class A { 436 abstract class A {
466 int m(); 437 int m();
467 }'''); 438 }''');
468 computeLibrarySourceErrors(source);
469 assertNoErrors(source); 439 assertNoErrors(source);
470 verify([source]); 440 verify([source]);
471 } 441 }
472 442
473 void test_missingReturn_expressionFunctionBody() { 443 void test_missingReturn_expressionFunctionBody() {
474 Source source = addSource("int f() => 0;"); 444 Source source = addSource("int f() => 0;");
475 computeLibrarySourceErrors(source);
476 assertNoErrors(source); 445 assertNoErrors(source);
477 verify([source]); 446 verify([source]);
478 } 447 }
479 448
480 void test_missingReturn_noReturnType() { 449 void test_missingReturn_noReturnType() {
481 Source source = addSource("f() {}"); 450 Source source = addSource("f() {}");
482 computeLibrarySourceErrors(source);
483 assertNoErrors(source); 451 assertNoErrors(source);
484 verify([source]); 452 verify([source]);
485 } 453 }
486 454
487 void test_missingReturn_voidReturnType() { 455 void test_missingReturn_voidReturnType() {
488 Source source = addSource("void f() {}"); 456 Source source = addSource("void f() {}");
489 computeLibrarySourceErrors(source);
490 assertNoErrors(source); 457 assertNoErrors(source);
491 verify([source]); 458 verify([source]);
492 } 459 }
493 460
494 void test_nullAwareInCondition_for_noCondition() { 461 void test_nullAwareInCondition_for_noCondition() {
495 Source source = addSource(r''' 462 Source source = addSource(r'''
496 m(x) { 463 m(x) {
497 for (var v = x; ; v++) {} 464 for (var v = x; ; v++) {}
498 } 465 }
499 '''); 466 ''');
500 computeLibrarySourceErrors(source);
501 assertNoErrors(source); 467 assertNoErrors(source);
502 verify([source]); 468 verify([source]);
503 } 469 }
504 470
505 void test_nullAwareInCondition_if_notTopLevel() { 471 void test_nullAwareInCondition_if_notTopLevel() {
506 Source source = addSource(r''' 472 Source source = addSource(r'''
507 m(x) { 473 m(x) {
508 if (x?.y == null) {} 474 if (x?.y == null) {}
509 } 475 }
510 '''); 476 ''');
511 computeLibrarySourceErrors(source);
512 assertNoErrors(source); 477 assertNoErrors(source);
513 verify([source]); 478 verify([source]);
514 } 479 }
515 480
516 void test_overrideEqualsButNotHashCode() { 481 void test_overrideEqualsButNotHashCode() {
517 Source source = addSource(r''' 482 Source source = addSource(r'''
518 class A { 483 class A {
519 bool operator ==(x) { return x; } 484 bool operator ==(x) { return x; }
520 get hashCode => 0; 485 get hashCode => 0;
521 }'''); 486 }''');
522 computeLibrarySourceErrors(source);
523 assertNoErrors(source); 487 assertNoErrors(source);
524 verify([source]); 488 verify([source]);
525 } 489 }
526 490
527 void test_overrideOnNonOverridingField_inInterface() { 491 void test_overrideOnNonOverridingField_inInterface() {
528 Source source = addSource(r''' 492 Source source = addSource(r'''
529 class A { 493 class A {
530 int get a => 0; 494 int get a => 0;
531 void set b(_) {} 495 void set b(_) {}
532 int c; 496 int c;
533 } 497 }
534 class B implements A { 498 class B implements A {
535 @override 499 @override
536 final int a = 1; 500 final int a = 1;
537 @override 501 @override
538 int b; 502 int b;
539 @override 503 @override
540 int c; 504 int c;
541 }'''); 505 }''');
542 computeLibrarySourceErrors(source);
543 assertNoErrors(source); 506 assertNoErrors(source);
544 verify([source]); 507 verify([source]);
545 } 508 }
546 509
547 void test_overrideOnNonOverridingField_inSuperclass() { 510 void test_overrideOnNonOverridingField_inSuperclass() {
548 Source source = addSource(r''' 511 Source source = addSource(r'''
549 class A { 512 class A {
550 int get a => 0; 513 int get a => 0;
551 void set b(_) {} 514 void set b(_) {}
552 int c; 515 int c;
553 } 516 }
554 class B extends A { 517 class B extends A {
555 @override 518 @override
556 final int a = 1; 519 final int a = 1;
557 @override 520 @override
558 int b; 521 int b;
559 @override 522 @override
560 int c; 523 int c;
561 }'''); 524 }''');
562 computeLibrarySourceErrors(source);
563 assertNoErrors(source); 525 assertNoErrors(source);
564 verify([source]); 526 verify([source]);
565 } 527 }
566 528
567 void test_overrideOnNonOverridingGetter_inInterface() { 529 void test_overrideOnNonOverridingGetter_inInterface() {
568 Source source = addSource(r''' 530 Source source = addSource(r'''
569 class A { 531 class A {
570 int get m => 0; 532 int get m => 0;
571 } 533 }
572 class B implements A { 534 class B implements A {
573 @override 535 @override
574 int get m => 1; 536 int get m => 1;
575 }'''); 537 }''');
576 computeLibrarySourceErrors(source);
577 assertNoErrors(source); 538 assertNoErrors(source);
578 verify([source]); 539 verify([source]);
579 } 540 }
580 541
581 void test_overrideOnNonOverridingGetter_inSuperclass() { 542 void test_overrideOnNonOverridingGetter_inSuperclass() {
582 Source source = addSource(r''' 543 Source source = addSource(r'''
583 class A { 544 class A {
584 int get m => 0; 545 int get m => 0;
585 } 546 }
586 class B extends A { 547 class B extends A {
587 @override 548 @override
588 int get m => 1; 549 int get m => 1;
589 }'''); 550 }''');
590 computeLibrarySourceErrors(source);
591 assertNoErrors(source); 551 assertNoErrors(source);
592 verify([source]); 552 verify([source]);
593 } 553 }
594 554
595 void test_overrideOnNonOverridingMethod_inInterface() { 555 void test_overrideOnNonOverridingMethod_inInterface() {
596 Source source = addSource(r''' 556 Source source = addSource(r'''
597 class A { 557 class A {
598 int m() => 0; 558 int m() => 0;
599 } 559 }
600 class B implements A { 560 class B implements A {
601 @override 561 @override
602 int m() => 1; 562 int m() => 1;
603 }'''); 563 }''');
604 computeLibrarySourceErrors(source);
605 assertNoErrors(source); 564 assertNoErrors(source);
606 verify([source]); 565 verify([source]);
607 } 566 }
608 567
609 void test_overrideOnNonOverridingMethod_inSuperclass() { 568 void test_overrideOnNonOverridingMethod_inSuperclass() {
610 Source source = addSource(r''' 569 Source source = addSource(r'''
611 class A { 570 class A {
612 int m() => 0; 571 int m() => 0;
613 } 572 }
614 class B extends A { 573 class B extends A {
615 @override 574 @override
616 int m() => 1; 575 int m() => 1;
617 }'''); 576 }''');
618 computeLibrarySourceErrors(source);
619 assertNoErrors(source); 577 assertNoErrors(source);
620 verify([source]); 578 verify([source]);
621 } 579 }
622 580
623 void test_overrideOnNonOverridingMethod_inSuperclass_abstract() { 581 void test_overrideOnNonOverridingMethod_inSuperclass_abstract() {
624 Source source = addSource(r''' 582 Source source = addSource(r'''
625 abstract class A { 583 abstract class A {
626 int m(); 584 int m();
627 } 585 }
628 class B extends A { 586 class B extends A {
629 @override 587 @override
630 int m() => 1; 588 int m() => 1;
631 }'''); 589 }''');
632 computeLibrarySourceErrors(source);
633 assertNoErrors(source); 590 assertNoErrors(source);
634 verify([source]); 591 verify([source]);
635 } 592 }
636 593
637 void test_overrideOnNonOverridingSetter_inInterface() { 594 void test_overrideOnNonOverridingSetter_inInterface() {
638 Source source = addSource(r''' 595 Source source = addSource(r'''
639 class A { 596 class A {
640 set m(int x) {} 597 set m(int x) {}
641 } 598 }
642 class B implements A { 599 class B implements A {
643 @override 600 @override
644 set m(int x) {} 601 set m(int x) {}
645 }'''); 602 }''');
646 computeLibrarySourceErrors(source);
647 assertNoErrors(source); 603 assertNoErrors(source);
648 verify([source]); 604 verify([source]);
649 } 605 }
650 606
651 void test_overrideOnNonOverridingSetter_inSuperclass() { 607 void test_overrideOnNonOverridingSetter_inSuperclass() {
652 Source source = addSource(r''' 608 Source source = addSource(r'''
653 class A { 609 class A {
654 set m(int x) {} 610 set m(int x) {}
655 } 611 }
656 class B extends A { 612 class B extends A {
657 @override 613 @override
658 set m(int x) {} 614 set m(int x) {}
659 }'''); 615 }''');
660 computeLibrarySourceErrors(source);
661 assertNoErrors(source); 616 assertNoErrors(source);
662 verify([source]); 617 verify([source]);
663 } 618 }
664 619
665 void test_propagatedFieldType() { 620 void test_propagatedFieldType() {
666 Source source = addSource(r''' 621 Source source = addSource(r'''
667 class A { } 622 class A { }
668 class X<T> { 623 class X<T> {
669 final x = new List<T>(); 624 final x = new List<T>();
670 } 625 }
671 class Z { 626 class Z {
672 final X<A> y = new X<A>(); 627 final X<A> y = new X<A>();
673 foo() { 628 foo() {
674 y.x.add(new A()); 629 y.x.add(new A());
675 } 630 }
676 }'''); 631 }''');
677 computeLibrarySourceErrors(source);
678 assertNoErrors(source); 632 assertNoErrors(source);
679 verify([source]); 633 verify([source]);
680 } 634 }
681 635
682 void test_proxy_annotation_prefixed() { 636 void test_proxy_annotation_prefixed() {
683 Source source = addSource(r''' 637 Source source = addSource(r'''
684 library L; 638 library L;
685 @proxy 639 @proxy
686 class A {} 640 class A {}
687 f(var a) { 641 f(var a) {
688 a = new A(); 642 a = new A();
689 a.m(); 643 a.m();
690 var x = a.g; 644 var x = a.g;
691 a.s = 1; 645 a.s = 1;
692 var y = a + a; 646 var y = a + a;
693 a++; 647 a++;
694 ++a; 648 ++a;
695 }'''); 649 }''');
696 computeLibrarySourceErrors(source);
697 assertNoErrors(source); 650 assertNoErrors(source);
698 } 651 }
699 652
700 void test_proxy_annotation_prefixed2() { 653 void test_proxy_annotation_prefixed2() {
701 Source source = addSource(r''' 654 Source source = addSource(r'''
702 library L; 655 library L;
703 @proxy 656 @proxy
704 class A {} 657 class A {}
705 class B { 658 class B {
706 f(var a) { 659 f(var a) {
707 a = new A(); 660 a = new A();
708 a.m(); 661 a.m();
709 var x = a.g; 662 var x = a.g;
710 a.s = 1; 663 a.s = 1;
711 var y = a + a; 664 var y = a + a;
712 a++; 665 a++;
713 ++a; 666 ++a;
714 } 667 }
715 }'''); 668 }''');
716 computeLibrarySourceErrors(source);
717 assertNoErrors(source); 669 assertNoErrors(source);
718 } 670 }
719 671
720 void test_proxy_annotation_prefixed3() { 672 void test_proxy_annotation_prefixed3() {
721 Source source = addSource(r''' 673 Source source = addSource(r'''
722 library L; 674 library L;
723 class B { 675 class B {
724 f(var a) { 676 f(var a) {
725 a = new A(); 677 a = new A();
726 a.m(); 678 a.m();
727 var x = a.g; 679 var x = a.g;
728 a.s = 1; 680 a.s = 1;
729 var y = a + a; 681 var y = a + a;
730 a++; 682 a++;
731 ++a; 683 ++a;
732 } 684 }
733 } 685 }
734 @proxy 686 @proxy
735 class A {}'''); 687 class A {}''');
736 computeLibrarySourceErrors(source);
737 assertNoErrors(source); 688 assertNoErrors(source);
738 } 689 }
739 690
740 void test_undefinedGetter_inSubtype() { 691 void test_undefinedGetter_inSubtype() {
741 Source source = addSource(r''' 692 Source source = addSource(r'''
742 class A {} 693 class A {}
743 class B extends A { 694 class B extends A {
744 get b => 0; 695 get b => 0;
745 } 696 }
746 f(var a) { 697 f(var a) {
747 if(a is A) { 698 if(a is A) {
748 return a.b; 699 return a.b;
749 } 700 }
750 }'''); 701 }''');
751 computeLibrarySourceErrors(source);
752 assertNoErrors(source); 702 assertNoErrors(source);
753 } 703 }
754 704
755 void test_undefinedMethod_assignmentExpression_inSubtype() { 705 void test_undefinedMethod_assignmentExpression_inSubtype() {
756 Source source = addSource(r''' 706 Source source = addSource(r'''
757 class A {} 707 class A {}
758 class B extends A { 708 class B extends A {
759 operator +(B b) {return new B();} 709 operator +(B b) {return new B();}
760 } 710 }
761 f(var a, var a2) { 711 f(var a, var a2) {
762 a = new A(); 712 a = new A();
763 a2 = new A(); 713 a2 = new A();
764 a += a2; 714 a += a2;
765 }'''); 715 }''');
766 computeLibrarySourceErrors(source);
767 assertNoErrors(source); 716 assertNoErrors(source);
768 } 717 }
769 718
770 void test_undefinedMethod_dynamic() { 719 void test_undefinedMethod_dynamic() {
771 Source source = addSource(r''' 720 Source source = addSource(r'''
772 class D<T extends dynamic> { 721 class D<T extends dynamic> {
773 fieldAccess(T t) => t.abc; 722 fieldAccess(T t) => t.abc;
774 methodAccess(T t) => t.xyz(1, 2, 'three'); 723 methodAccess(T t) => t.xyz(1, 2, 'three');
775 }'''); 724 }''');
776 computeLibrarySourceErrors(source);
777 assertNoErrors(source); 725 assertNoErrors(source);
778 } 726 }
779 727
780 void test_undefinedMethod_inSubtype() { 728 void test_undefinedMethod_inSubtype() {
781 Source source = addSource(r''' 729 Source source = addSource(r'''
782 class A {} 730 class A {}
783 class B extends A { 731 class B extends A {
784 b() {} 732 b() {}
785 } 733 }
786 f() { 734 f() {
787 var a = new A(); 735 var a = new A();
788 a.b(); 736 a.b();
789 }'''); 737 }''');
790 computeLibrarySourceErrors(source);
791 assertNoErrors(source); 738 assertNoErrors(source);
792 } 739 }
793 740
794 void test_undefinedMethod_unionType_all() { 741 void test_undefinedMethod_unionType_all() {
795 Source source = addSource(r''' 742 Source source = addSource(r'''
796 class A { 743 class A {
797 int m(int x) => 0; 744 int m(int x) => 0;
798 } 745 }
799 class B { 746 class B {
800 String m() => '0'; 747 String m() => '0';
801 } 748 }
802 f(A a, B b) { 749 f(A a, B b) {
803 var ab; 750 var ab;
804 if (0 < 1) { 751 if (0 < 1) {
805 ab = a; 752 ab = a;
806 } else { 753 } else {
807 ab = b; 754 ab = b;
808 } 755 }
809 ab.m(); 756 ab.m();
810 }'''); 757 }''');
811 computeLibrarySourceErrors(source);
812 assertNoErrors(source); 758 assertNoErrors(source);
813 } 759 }
814 760
815 void test_undefinedMethod_unionType_some() { 761 void test_undefinedMethod_unionType_some() {
816 Source source = addSource(r''' 762 Source source = addSource(r'''
817 class A { 763 class A {
818 int m(int x) => 0; 764 int m(int x) => 0;
819 } 765 }
820 class B {} 766 class B {}
821 f(A a, B b) { 767 f(A a, B b) {
822 var ab; 768 var ab;
823 if (0 < 1) { 769 if (0 < 1) {
824 ab = a; 770 ab = a;
825 } else { 771 } else {
826 ab = b; 772 ab = b;
827 } 773 }
828 ab.m(0); 774 ab.m(0);
829 }'''); 775 }''');
830 computeLibrarySourceErrors(source);
831 assertNoErrors(source); 776 assertNoErrors(source);
832 } 777 }
833 778
834 void test_undefinedOperator_binaryExpression_inSubtype() { 779 void test_undefinedOperator_binaryExpression_inSubtype() {
835 Source source = addSource(r''' 780 Source source = addSource(r'''
836 class A {} 781 class A {}
837 class B extends A { 782 class B extends A {
838 operator +(B b) {} 783 operator +(B b) {}
839 } 784 }
840 f(var a) { 785 f(var a) {
841 if(a is A) { 786 if(a is A) {
842 a + 1; 787 a + 1;
843 } 788 }
844 }'''); 789 }''');
845 computeLibrarySourceErrors(source);
846 assertNoErrors(source); 790 assertNoErrors(source);
847 } 791 }
848 792
849 void test_undefinedOperator_indexBoth_inSubtype() { 793 void test_undefinedOperator_indexBoth_inSubtype() {
850 Source source = addSource(r''' 794 Source source = addSource(r'''
851 class A {} 795 class A {}
852 class B extends A { 796 class B extends A {
853 operator [](int index) {} 797 operator [](int index) {}
854 } 798 }
855 f(var a) { 799 f(var a) {
856 if(a is A) { 800 if(a is A) {
857 a[0]++; 801 a[0]++;
858 } 802 }
859 }'''); 803 }''');
860 computeLibrarySourceErrors(source);
861 assertNoErrors(source); 804 assertNoErrors(source);
862 } 805 }
863 806
864 void test_undefinedOperator_indexGetter_inSubtype() { 807 void test_undefinedOperator_indexGetter_inSubtype() {
865 Source source = addSource(r''' 808 Source source = addSource(r'''
866 class A {} 809 class A {}
867 class B extends A { 810 class B extends A {
868 operator [](int index) {} 811 operator [](int index) {}
869 } 812 }
870 f(var a) { 813 f(var a) {
871 if(a is A) { 814 if(a is A) {
872 a[0]; 815 a[0];
873 } 816 }
874 }'''); 817 }''');
875 computeLibrarySourceErrors(source);
876 assertNoErrors(source); 818 assertNoErrors(source);
877 } 819 }
878 820
879 void test_undefinedOperator_indexSetter_inSubtype() { 821 void test_undefinedOperator_indexSetter_inSubtype() {
880 Source source = addSource(r''' 822 Source source = addSource(r'''
881 class A {} 823 class A {}
882 class B extends A { 824 class B extends A {
883 operator []=(i, v) {} 825 operator []=(i, v) {}
884 } 826 }
885 f(var a) { 827 f(var a) {
886 if(a is A) { 828 if(a is A) {
887 a[0] = 1; 829 a[0] = 1;
888 } 830 }
889 }'''); 831 }''');
890 computeLibrarySourceErrors(source);
891 assertNoErrors(source); 832 assertNoErrors(source);
892 } 833 }
893 834
894 void test_undefinedOperator_postfixExpression() { 835 void test_undefinedOperator_postfixExpression() {
895 Source source = addSource(r''' 836 Source source = addSource(r'''
896 class A {} 837 class A {}
897 class B extends A { 838 class B extends A {
898 operator +(B b) {return new B();} 839 operator +(B b) {return new B();}
899 } 840 }
900 f(var a) { 841 f(var a) {
901 if(a is A) { 842 if(a is A) {
902 a++; 843 a++;
903 } 844 }
904 }'''); 845 }''');
905 computeLibrarySourceErrors(source);
906 assertNoErrors(source); 846 assertNoErrors(source);
907 } 847 }
908 848
909 void test_undefinedOperator_prefixExpression() { 849 void test_undefinedOperator_prefixExpression() {
910 Source source = addSource(r''' 850 Source source = addSource(r'''
911 class A {} 851 class A {}
912 class B extends A { 852 class B extends A {
913 operator +(B b) {return new B();} 853 operator +(B b) {return new B();}
914 } 854 }
915 f(var a) { 855 f(var a) {
916 if(a is A) { 856 if(a is A) {
917 ++a; 857 ++a;
918 } 858 }
919 }'''); 859 }''');
920 computeLibrarySourceErrors(source);
921 assertNoErrors(source); 860 assertNoErrors(source);
922 } 861 }
923 862
924 void test_undefinedSetter_inSubtype() { 863 void test_undefinedSetter_inSubtype() {
925 Source source = addSource(r''' 864 Source source = addSource(r'''
926 class A {} 865 class A {}
927 class B extends A { 866 class B extends A {
928 set b(x) {} 867 set b(x) {}
929 } 868 }
930 f(var a) { 869 f(var a) {
931 if(a is A) { 870 if(a is A) {
932 a.b = 0; 871 a.b = 0;
933 } 872 }
934 }'''); 873 }''');
935 computeLibrarySourceErrors(source);
936 assertNoErrors(source); 874 assertNoErrors(source);
937 } 875 }
938 876
939 void test_unnecessaryCast_13855_parameter_A() { 877 void test_unnecessaryCast_13855_parameter_A() {
940 // dartbug.com/13855, dartbug.com/13732 878 // dartbug.com/13855, dartbug.com/13732
941 Source source = addSource(r''' 879 Source source = addSource(r'''
942 class A{ 880 class A{
943 a() {} 881 a() {}
944 } 882 }
945 class B<E> { 883 class B<E> {
946 E e; 884 E e;
947 m() { 885 m() {
948 (e as A).a(); 886 (e as A).a();
949 } 887 }
950 }'''); 888 }''');
951 computeLibrarySourceErrors(source);
952 assertNoErrors(source); 889 assertNoErrors(source);
953 verify([source]); 890 verify([source]);
954 } 891 }
955 892
956 void test_unnecessaryCast_conditionalExpression() { 893 void test_unnecessaryCast_conditionalExpression() {
957 Source source = addSource(r''' 894 Source source = addSource(r'''
958 abstract class I {} 895 abstract class I {}
959 class A implements I {} 896 class A implements I {}
960 class B implements I {} 897 class B implements I {}
961 I m(A a, B b) { 898 I m(A a, B b) {
962 return a == null ? b as I : a as I; 899 return a == null ? b as I : a as I;
963 }'''); 900 }''');
964 computeLibrarySourceErrors(source);
965 assertNoErrors(source); 901 assertNoErrors(source);
966 verify([source]); 902 verify([source]);
967 } 903 }
968 904
969 void test_unnecessaryCast_dynamic_type() { 905 void test_unnecessaryCast_dynamic_type() {
970 Source source = addSource(r''' 906 Source source = addSource(r'''
971 m(v) { 907 m(v) {
972 var b = v as Object; 908 var b = v as Object;
973 }'''); 909 }''');
974 computeLibrarySourceErrors(source);
975 assertNoErrors(source); 910 assertNoErrors(source);
976 verify([source]); 911 verify([source]);
977 } 912 }
978 913
979 void test_unnecessaryCast_generics() { 914 void test_unnecessaryCast_generics() {
980 // dartbug.com/18953 915 // dartbug.com/18953
981 Source source = addSource(r''' 916 Source source = addSource(r'''
982 import 'dart:async'; 917 import 'dart:async';
983 Future<int> f() => new Future.value(0); 918 Future<int> f() => new Future.value(0);
984 void g(bool c) { 919 void g(bool c) {
985 (c ? f(): new Future.value(0) as Future<int>).then((int value) {}); 920 (c ? f(): new Future.value(0) as Future<int>).then((int value) {});
986 }'''); 921 }''');
987 computeLibrarySourceErrors(source);
988 assertNoErrors(source); 922 assertNoErrors(source);
989 verify([source]); 923 verify([source]);
990 } 924 }
991 925
992 void test_unnecessaryCast_type_dynamic() { 926 void test_unnecessaryCast_type_dynamic() {
993 Source source = addSource(r''' 927 Source source = addSource(r'''
994 m(v) { 928 m(v) {
995 var b = Object as dynamic; 929 var b = Object as dynamic;
996 }'''); 930 }''');
997 computeLibrarySourceErrors(source);
998 assertNoErrors(source); 931 assertNoErrors(source);
999 verify([source]); 932 verify([source]);
1000 } 933 }
1001 934
1002 void test_unnecessaryNoSuchMethod_blockBody_notReturnStatement() { 935 void test_unnecessaryNoSuchMethod_blockBody_notReturnStatement() {
1003 Source source = addSource(r''' 936 Source source = addSource(r'''
1004 class A { 937 class A {
1005 noSuchMethod(x) => super.noSuchMethod(x); 938 noSuchMethod(x) => super.noSuchMethod(x);
1006 } 939 }
1007 class B extends A { 940 class B extends A {
1008 mmm(); 941 mmm();
1009 noSuchMethod(y) { 942 noSuchMethod(y) {
1010 print(y); 943 print(y);
1011 } 944 }
1012 }'''); 945 }''');
1013 computeLibrarySourceErrors(source);
1014 assertNoErrors(source); 946 assertNoErrors(source);
1015 verify([source]); 947 verify([source]);
1016 } 948 }
1017 949
1018 void test_unnecessaryNoSuchMethod_blockBody_notSingleStatement() { 950 void test_unnecessaryNoSuchMethod_blockBody_notSingleStatement() {
1019 Source source = addSource(r''' 951 Source source = addSource(r'''
1020 class A { 952 class A {
1021 noSuchMethod(x) => super.noSuchMethod(x); 953 noSuchMethod(x) => super.noSuchMethod(x);
1022 } 954 }
1023 class B extends A { 955 class B extends A {
1024 mmm(); 956 mmm();
1025 noSuchMethod(y) { 957 noSuchMethod(y) {
1026 print(y); 958 print(y);
1027 return super.noSuchMethod(y); 959 return super.noSuchMethod(y);
1028 } 960 }
1029 }'''); 961 }''');
1030 computeLibrarySourceErrors(source);
1031 assertNoErrors(source); 962 assertNoErrors(source);
1032 verify([source]); 963 verify([source]);
1033 } 964 }
1034 965
1035 void test_unnecessaryNoSuchMethod_expressionBody_notNoSuchMethod() { 966 void test_unnecessaryNoSuchMethod_expressionBody_notNoSuchMethod() {
1036 Source source = addSource(r''' 967 Source source = addSource(r'''
1037 class A { 968 class A {
1038 noSuchMethod(x) => super.noSuchMethod(x); 969 noSuchMethod(x) => super.noSuchMethod(x);
1039 } 970 }
1040 class B extends A { 971 class B extends A {
1041 mmm(); 972 mmm();
1042 noSuchMethod(y) => super.hashCode; 973 noSuchMethod(y) => super.hashCode;
1043 }'''); 974 }''');
1044 computeLibrarySourceErrors(source);
1045 assertNoErrors(source); 975 assertNoErrors(source);
1046 verify([source]); 976 verify([source]);
1047 } 977 }
1048 978
1049 void test_unnecessaryNoSuchMethod_expressionBody_notSuper() { 979 void test_unnecessaryNoSuchMethod_expressionBody_notSuper() {
1050 Source source = addSource(r''' 980 Source source = addSource(r'''
1051 class A { 981 class A {
1052 noSuchMethod(x) => super.noSuchMethod(x); 982 noSuchMethod(x) => super.noSuchMethod(x);
1053 } 983 }
1054 class B extends A { 984 class B extends A {
1055 mmm(); 985 mmm();
1056 noSuchMethod(y) => 42; 986 noSuchMethod(y) => 42;
1057 }'''); 987 }''');
1058 computeLibrarySourceErrors(source);
1059 assertNoErrors(source); 988 assertNoErrors(source);
1060 verify([source]); 989 verify([source]);
1061 } 990 }
1062 991
1063 void test_unusedImport_annotationOnDirective() { 992 void test_unusedImport_annotationOnDirective() {
1064 Source source = addSource(r''' 993 Source source = addSource(r'''
1065 library L; 994 library L;
1066 @A() 995 @A()
1067 import 'lib1.dart';'''); 996 import 'lib1.dart';''');
1068 Source source2 = addNamedSource( 997 Source source2 = addNamedSource(
1069 "/lib1.dart", 998 "/lib1.dart",
1070 r''' 999 r'''
1071 library lib1; 1000 library lib1;
1072 class A { 1001 class A {
1073 const A() {} 1002 const A() {}
1074 }'''); 1003 }''');
1075 computeLibrarySourceErrors(source);
1076 assertErrors(source); 1004 assertErrors(source);
1077 verify([source, source2]); 1005 verify([source, source2]);
1078 } 1006 }
1079 1007
1080 void test_unusedImport_as_equalPrefixes() { 1008 void test_unusedImport_as_equalPrefixes() {
1081 // 18818 1009 // 18818
1082 Source source = addSource(r''' 1010 Source source = addSource(r'''
1083 library L; 1011 library L;
1084 import 'lib1.dart' as one; 1012 import 'lib1.dart' as one;
1085 import 'lib2.dart' as one; 1013 import 'lib2.dart' as one;
1086 one.A a; 1014 one.A a;
1087 one.B b;'''); 1015 one.B b;''');
1088 Source source2 = addNamedSource( 1016 Source source2 = addNamedSource(
1089 "/lib1.dart", 1017 "/lib1.dart",
1090 r''' 1018 r'''
1091 library lib1; 1019 library lib1;
1092 class A {}'''); 1020 class A {}''');
1093 Source source3 = addNamedSource( 1021 Source source3 = addNamedSource(
1094 "/lib2.dart", 1022 "/lib2.dart",
1095 r''' 1023 r'''
1096 library lib2; 1024 library lib2;
1097 class B {}'''); 1025 class B {}''');
1098 computeLibrarySourceErrors(source);
1099 assertErrors(source); 1026 assertErrors(source);
1100 assertNoErrors(source2); 1027 assertNoErrors(source2);
1101 assertNoErrors(source3); 1028 assertNoErrors(source3);
1102 verify([source, source2, source3]); 1029 verify([source, source2, source3]);
1103 } 1030 }
1104 1031
1105 void test_unusedImport_core_library() { 1032 void test_unusedImport_core_library() {
1106 Source source = addSource(r''' 1033 Source source = addSource(r'''
1107 library L; 1034 library L;
1108 import 'dart:core';'''); 1035 import 'dart:core';''');
1109 computeLibrarySourceErrors(source);
1110 assertNoErrors(source); 1036 assertNoErrors(source);
1111 verify([source]); 1037 verify([source]);
1112 } 1038 }
1113 1039
1114 void test_unusedImport_export() { 1040 void test_unusedImport_export() {
1115 Source source = addSource(r''' 1041 Source source = addSource(r'''
1116 library L; 1042 library L;
1117 import 'lib1.dart'; 1043 import 'lib1.dart';
1118 Two two;'''); 1044 Two two;''');
1119 addNamedSource( 1045 addNamedSource(
1120 "/lib1.dart", 1046 "/lib1.dart",
1121 r''' 1047 r'''
1122 library lib1; 1048 library lib1;
1123 export 'lib2.dart'; 1049 export 'lib2.dart';
1124 class One {}'''); 1050 class One {}''');
1125 addNamedSource( 1051 addNamedSource(
1126 "/lib2.dart", 1052 "/lib2.dart",
1127 r''' 1053 r'''
1128 library lib2; 1054 library lib2;
1129 class Two {}'''); 1055 class Two {}''');
1130 computeLibrarySourceErrors(source);
1131 assertNoErrors(source); 1056 assertNoErrors(source);
1132 verify([source]); 1057 verify([source]);
1133 } 1058 }
1134 1059
1135 void test_unusedImport_export2() { 1060 void test_unusedImport_export2() {
1136 Source source = addSource(r''' 1061 Source source = addSource(r'''
1137 library L; 1062 library L;
1138 import 'lib1.dart'; 1063 import 'lib1.dart';
1139 Three three;'''); 1064 Three three;''');
1140 addNamedSource( 1065 addNamedSource(
1141 "/lib1.dart", 1066 "/lib1.dart",
1142 r''' 1067 r'''
1143 library lib1; 1068 library lib1;
1144 export 'lib2.dart'; 1069 export 'lib2.dart';
1145 class One {}'''); 1070 class One {}''');
1146 addNamedSource( 1071 addNamedSource(
1147 "/lib2.dart", 1072 "/lib2.dart",
1148 r''' 1073 r'''
1149 library lib2; 1074 library lib2;
1150 export 'lib3.dart'; 1075 export 'lib3.dart';
1151 class Two {}'''); 1076 class Two {}''');
1152 addNamedSource( 1077 addNamedSource(
1153 "/lib3.dart", 1078 "/lib3.dart",
1154 r''' 1079 r'''
1155 library lib3; 1080 library lib3;
1156 class Three {}'''); 1081 class Three {}''');
1157 computeLibrarySourceErrors(source);
1158 assertNoErrors(source); 1082 assertNoErrors(source);
1159 verify([source]); 1083 verify([source]);
1160 } 1084 }
1161 1085
1162 void test_unusedImport_export_infiniteLoop() { 1086 void test_unusedImport_export_infiniteLoop() {
1163 Source source = addSource(r''' 1087 Source source = addSource(r'''
1164 library L; 1088 library L;
1165 import 'lib1.dart'; 1089 import 'lib1.dart';
1166 Two two;'''); 1090 Two two;''');
1167 addNamedSource( 1091 addNamedSource(
1168 "/lib1.dart", 1092 "/lib1.dart",
1169 r''' 1093 r'''
1170 library lib1; 1094 library lib1;
1171 export 'lib2.dart'; 1095 export 'lib2.dart';
1172 class One {}'''); 1096 class One {}''');
1173 addNamedSource( 1097 addNamedSource(
1174 "/lib2.dart", 1098 "/lib2.dart",
1175 r''' 1099 r'''
1176 library lib2; 1100 library lib2;
1177 export 'lib3.dart'; 1101 export 'lib3.dart';
1178 class Two {}'''); 1102 class Two {}''');
1179 addNamedSource( 1103 addNamedSource(
1180 "/lib3.dart", 1104 "/lib3.dart",
1181 r''' 1105 r'''
1182 library lib3; 1106 library lib3;
1183 export 'lib2.dart'; 1107 export 'lib2.dart';
1184 class Three {}'''); 1108 class Three {}''');
1185 computeLibrarySourceErrors(source);
1186 assertNoErrors(source); 1109 assertNoErrors(source);
1187 verify([source]); 1110 verify([source]);
1188 } 1111 }
1189 1112
1190 void test_unusedImport_metadata() { 1113 void test_unusedImport_metadata() {
1191 Source source = addSource(r''' 1114 Source source = addSource(r'''
1192 library L; 1115 library L;
1193 @A(x) 1116 @A(x)
1194 import 'lib1.dart'; 1117 import 'lib1.dart';
1195 class A { 1118 class A {
1196 final int value; 1119 final int value;
1197 const A(this.value); 1120 const A(this.value);
1198 }'''); 1121 }''');
1199 addNamedSource( 1122 addNamedSource(
1200 "/lib1.dart", 1123 "/lib1.dart",
1201 r''' 1124 r'''
1202 library lib1; 1125 library lib1;
1203 const x = 0;'''); 1126 const x = 0;''');
1204 computeLibrarySourceErrors(source);
1205 assertNoErrors(source); 1127 assertNoErrors(source);
1206 verify([source]); 1128 verify([source]);
1207 } 1129 }
1208 1130
1209 void test_unusedImport_prefix_topLevelFunction() { 1131 void test_unusedImport_prefix_topLevelFunction() {
1210 Source source = addSource(r''' 1132 Source source = addSource(r'''
1211 library L; 1133 library L;
1212 import 'lib1.dart' hide topLevelFunction; 1134 import 'lib1.dart' hide topLevelFunction;
1213 import 'lib1.dart' as one show topLevelFunction; 1135 import 'lib1.dart' as one show topLevelFunction;
1214 class A { 1136 class A {
1215 static void x() { 1137 static void x() {
1216 One o; 1138 One o;
1217 one.topLevelFunction(); 1139 one.topLevelFunction();
1218 } 1140 }
1219 }'''); 1141 }''');
1220 addNamedSource( 1142 addNamedSource(
1221 "/lib1.dart", 1143 "/lib1.dart",
1222 r''' 1144 r'''
1223 library lib1; 1145 library lib1;
1224 class One {} 1146 class One {}
1225 topLevelFunction() {}'''); 1147 topLevelFunction() {}''');
1226 computeLibrarySourceErrors(source);
1227 assertNoErrors(source); 1148 assertNoErrors(source);
1228 verify([source]); 1149 verify([source]);
1229 } 1150 }
1230 1151
1231 void test_unusedImport_prefix_topLevelFunction2() { 1152 void test_unusedImport_prefix_topLevelFunction2() {
1232 Source source = addSource(r''' 1153 Source source = addSource(r'''
1233 library L; 1154 library L;
1234 import 'lib1.dart' hide topLevelFunction; 1155 import 'lib1.dart' hide topLevelFunction;
1235 import 'lib1.dart' as one show topLevelFunction; 1156 import 'lib1.dart' as one show topLevelFunction;
1236 import 'lib1.dart' as two show topLevelFunction; 1157 import 'lib1.dart' as two show topLevelFunction;
1237 class A { 1158 class A {
1238 static void x() { 1159 static void x() {
1239 One o; 1160 One o;
1240 one.topLevelFunction(); 1161 one.topLevelFunction();
1241 two.topLevelFunction(); 1162 two.topLevelFunction();
1242 } 1163 }
1243 }'''); 1164 }''');
1244 addNamedSource( 1165 addNamedSource(
1245 "/lib1.dart", 1166 "/lib1.dart",
1246 r''' 1167 r'''
1247 library lib1; 1168 library lib1;
1248 class One {} 1169 class One {}
1249 topLevelFunction() {}'''); 1170 topLevelFunction() {}''');
1250 computeLibrarySourceErrors(source);
1251 assertNoErrors(source); 1171 assertNoErrors(source);
1252 verify([source]); 1172 verify([source]);
1253 } 1173 }
1254 1174
1255 void test_useOfVoidResult_implicitReturnValue() { 1175 void test_useOfVoidResult_implicitReturnValue() {
1256 Source source = addSource(r''' 1176 Source source = addSource(r'''
1257 f() {} 1177 f() {}
1258 class A { 1178 class A {
1259 n() { 1179 n() {
1260 var a = f(); 1180 var a = f();
1261 } 1181 }
1262 }'''); 1182 }''');
1263 computeLibrarySourceErrors(source);
1264 assertNoErrors(source); 1183 assertNoErrors(source);
1265 verify([source]); 1184 verify([source]);
1266 } 1185 }
1267 1186
1268 void test_useOfVoidResult_nonVoidReturnValue() { 1187 void test_useOfVoidResult_nonVoidReturnValue() {
1269 Source source = addSource(r''' 1188 Source source = addSource(r'''
1270 int f() => 1; 1189 int f() => 1;
1271 g() { 1190 g() {
1272 var a = f(); 1191 var a = f();
1273 }'''); 1192 }''');
1274 computeLibrarySourceErrors(source);
1275 assertNoErrors(source); 1193 assertNoErrors(source);
1276 verify([source]); 1194 verify([source]);
1277 } 1195 }
1278 } 1196 }
1279 1197
1280 class PubSuggestionCodeTest extends ResolverTestCase { 1198 class PubSuggestionCodeTest extends ResolverTestCase {
1281 void test_import_package() { 1199 void test_import_package() {
1282 Source source = addSource("import 'package:somepackage/other.dart';"); 1200 Source source = addSource("import 'package:somepackage/other.dart';");
1283 computeLibrarySourceErrors(source);
1284 assertErrors(source, [CompileTimeErrorCode.URI_DOES_NOT_EXIST]); 1201 assertErrors(source, [CompileTimeErrorCode.URI_DOES_NOT_EXIST]);
1285 } 1202 }
1286 1203
1287 void test_import_packageWithDotDot() { 1204 void test_import_packageWithDotDot() {
1288 Source source = addSource("import 'package:somepackage/../other.dart';"); 1205 Source source = addSource("import 'package:somepackage/../other.dart';");
1289 computeLibrarySourceErrors(source);
1290 assertErrors(source, [ 1206 assertErrors(source, [
1291 CompileTimeErrorCode.URI_DOES_NOT_EXIST, 1207 CompileTimeErrorCode.URI_DOES_NOT_EXIST,
1292 HintCode.PACKAGE_IMPORT_CONTAINS_DOT_DOT 1208 HintCode.PACKAGE_IMPORT_CONTAINS_DOT_DOT
1293 ]); 1209 ]);
1294 } 1210 }
1295 1211
1296 void test_import_packageWithLeadingDotDot() { 1212 void test_import_packageWithLeadingDotDot() {
1297 Source source = addSource("import 'package:../other.dart';"); 1213 Source source = addSource("import 'package:../other.dart';");
1298 computeLibrarySourceErrors(source);
1299 assertErrors(source, [ 1214 assertErrors(source, [
1300 CompileTimeErrorCode.URI_DOES_NOT_EXIST, 1215 CompileTimeErrorCode.URI_DOES_NOT_EXIST,
1301 HintCode.PACKAGE_IMPORT_CONTAINS_DOT_DOT 1216 HintCode.PACKAGE_IMPORT_CONTAINS_DOT_DOT
1302 ]); 1217 ]);
1303 } 1218 }
1304 1219
1305 void test_import_referenceIntoLibDirectory() { 1220 void test_import_referenceIntoLibDirectory() {
1306 cacheSource("/myproj/pubspec.yaml", ""); 1221 cacheSource("/myproj/pubspec.yaml", "");
1307 cacheSource("/myproj/lib/other.dart", ""); 1222 cacheSource("/myproj/lib/other.dart", "");
1308 Source source = 1223 Source source =
1309 addNamedSource("/myproj/web/test.dart", "import '../lib/other.dart';"); 1224 addNamedSource("/myproj/web/test.dart", "import '../lib/other.dart';");
1310 computeLibrarySourceErrors(source);
1311 assertErrors( 1225 assertErrors(
1312 source, [HintCode.FILE_IMPORT_OUTSIDE_LIB_REFERENCES_FILE_INSIDE]); 1226 source, [HintCode.FILE_IMPORT_OUTSIDE_LIB_REFERENCES_FILE_INSIDE]);
1313 } 1227 }
1314 1228
1315 void test_import_referenceIntoLibDirectory_no_pubspec() { 1229 void test_import_referenceIntoLibDirectory_no_pubspec() {
1316 cacheSource("/myproj/lib/other.dart", ""); 1230 cacheSource("/myproj/lib/other.dart", "");
1317 Source source = 1231 Source source =
1318 addNamedSource("/myproj/web/test.dart", "import '../lib/other.dart';"); 1232 addNamedSource("/myproj/web/test.dart", "import '../lib/other.dart';");
1319 computeLibrarySourceErrors(source);
1320 assertNoErrors(source); 1233 assertNoErrors(source);
1321 } 1234 }
1322 1235
1323 void test_import_referenceOutOfLibDirectory() { 1236 void test_import_referenceOutOfLibDirectory() {
1324 cacheSource("/myproj/pubspec.yaml", ""); 1237 cacheSource("/myproj/pubspec.yaml", "");
1325 cacheSource("/myproj/web/other.dart", ""); 1238 cacheSource("/myproj/web/other.dart", "");
1326 Source source = 1239 Source source =
1327 addNamedSource("/myproj/lib/test.dart", "import '../web/other.dart';"); 1240 addNamedSource("/myproj/lib/test.dart", "import '../web/other.dart';");
1328 computeLibrarySourceErrors(source);
1329 assertErrors( 1241 assertErrors(
1330 source, [HintCode.FILE_IMPORT_INSIDE_LIB_REFERENCES_FILE_OUTSIDE]); 1242 source, [HintCode.FILE_IMPORT_INSIDE_LIB_REFERENCES_FILE_OUTSIDE]);
1331 } 1243 }
1332 1244
1333 void test_import_referenceOutOfLibDirectory_no_pubspec() { 1245 void test_import_referenceOutOfLibDirectory_no_pubspec() {
1334 cacheSource("/myproj/web/other.dart", ""); 1246 cacheSource("/myproj/web/other.dart", "");
1335 Source source = 1247 Source source =
1336 addNamedSource("/myproj/lib/test.dart", "import '../web/other.dart';"); 1248 addNamedSource("/myproj/lib/test.dart", "import '../web/other.dart';");
1337 computeLibrarySourceErrors(source);
1338 assertNoErrors(source); 1249 assertNoErrors(source);
1339 } 1250 }
1340 1251
1341 void test_import_valid_inside_lib1() { 1252 void test_import_valid_inside_lib1() {
1342 cacheSource("/myproj/pubspec.yaml", ""); 1253 cacheSource("/myproj/pubspec.yaml", "");
1343 cacheSource("/myproj/lib/other.dart", ""); 1254 cacheSource("/myproj/lib/other.dart", "");
1344 Source source = 1255 Source source =
1345 addNamedSource("/myproj/lib/test.dart", "import 'other.dart';"); 1256 addNamedSource("/myproj/lib/test.dart", "import 'other.dart';");
1346 computeLibrarySourceErrors(source);
1347 assertNoErrors(source); 1257 assertNoErrors(source);
1348 } 1258 }
1349 1259
1350 void test_import_valid_inside_lib2() { 1260 void test_import_valid_inside_lib2() {
1351 cacheSource("/myproj/pubspec.yaml", ""); 1261 cacheSource("/myproj/pubspec.yaml", "");
1352 cacheSource("/myproj/lib/bar/other.dart", ""); 1262 cacheSource("/myproj/lib/bar/other.dart", "");
1353 Source source = addNamedSource( 1263 Source source = addNamedSource(
1354 "/myproj/lib/foo/test.dart", "import '../bar/other.dart';"); 1264 "/myproj/lib/foo/test.dart", "import '../bar/other.dart';");
1355 computeLibrarySourceErrors(source);
1356 assertNoErrors(source); 1265 assertNoErrors(source);
1357 } 1266 }
1358 1267
1359 void test_import_valid_outside_lib() { 1268 void test_import_valid_outside_lib() {
1360 cacheSource("/myproj/pubspec.yaml", ""); 1269 cacheSource("/myproj/pubspec.yaml", "");
1361 cacheSource("/myproj/web/other.dart", ""); 1270 cacheSource("/myproj/web/other.dart", "");
1362 Source source = 1271 Source source =
1363 addNamedSource("/myproj/lib2/test.dart", "import '../web/other.dart';"); 1272 addNamedSource("/myproj/lib2/test.dart", "import '../web/other.dart';");
1364 computeLibrarySourceErrors(source);
1365 assertNoErrors(source); 1273 assertNoErrors(source);
1366 } 1274 }
1367 } 1275 }
OLDNEW
« no previous file with comments | « pkg/analyzer/test/generated/non_error_resolver_test.dart ('k') | pkg/analyzer/test/generated/resolver_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698