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

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

Issue 2624793002: Make error producing tests ansynchronous. (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.hint_code_test; 5 library analyzer.test.generated.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/parser.dart'; 10 import 'package:analyzer/src/generated/parser.dart';
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 ''', 58 ''',
59 'package:js/js.dart': r''' 59 'package:js/js.dart': r'''
60 library js; 60 library js;
61 class JS { 61 class JS {
62 const JS([String js]) { } 62 const JS([String js]) { }
63 } 63 }
64 ''' 64 '''
65 }, resourceProvider: resourceProvider); 65 }, resourceProvider: resourceProvider);
66 } 66 }
67 67
68 void test_abstractSuperMemberReference_getter() { 68 test_abstractSuperMemberReference_getter() async {
69 Source source = addSource(r''' 69 Source source = addSource(r'''
70 abstract class A { 70 abstract class A {
71 int get test; 71 int get test;
72 } 72 }
73 class B extends A { 73 class B extends A {
74 int get test { 74 int get test {
75 super.test; 75 super.test;
76 return 0; 76 return 0;
77 } 77 }
78 } 78 }
79 '''); 79 ''');
80 assertErrors(source, [HintCode.ABSTRACT_SUPER_MEMBER_REFERENCE]); 80 await assertErrors(source, [HintCode.ABSTRACT_SUPER_MEMBER_REFERENCE]);
81 verify([source]); 81 verify([source]);
82 } 82 }
83 83
84 void test_abstractSuperMemberReference_method_invocation() { 84 test_abstractSuperMemberReference_method_invocation() async {
85 Source source = addSource(r''' 85 Source source = addSource(r'''
86 abstract class A { 86 abstract class A {
87 void test(); 87 void test();
88 } 88 }
89 class B extends A { 89 class B extends A {
90 void test() { 90 void test() {
91 super.test(); 91 super.test();
92 } 92 }
93 } 93 }
94 '''); 94 ''');
95 assertErrors(source, [HintCode.ABSTRACT_SUPER_MEMBER_REFERENCE]); 95 await assertErrors(source, [HintCode.ABSTRACT_SUPER_MEMBER_REFERENCE]);
96 verify([source]); 96 verify([source]);
97 } 97 }
98 98
99 void test_abstractSuperMemberReference_method_reference() { 99 test_abstractSuperMemberReference_method_reference() async {
100 Source source = addSource(r''' 100 Source source = addSource(r'''
101 abstract class A { 101 abstract class A {
102 void test(); 102 void test();
103 } 103 }
104 class B extends A { 104 class B extends A {
105 void test() { 105 void test() {
106 super.test; 106 super.test;
107 } 107 }
108 } 108 }
109 '''); 109 ''');
110 assertErrors(source, [HintCode.ABSTRACT_SUPER_MEMBER_REFERENCE]); 110 await assertErrors(source, [HintCode.ABSTRACT_SUPER_MEMBER_REFERENCE]);
111 verify([source]); 111 verify([source]);
112 } 112 }
113 113
114 void test_abstractSuperMemberReference_setter() { 114 test_abstractSuperMemberReference_setter() async {
115 Source source = addSource(r''' 115 Source source = addSource(r'''
116 abstract class A { 116 abstract class A {
117 void set test(int v); 117 void set test(int v);
118 } 118 }
119 class B extends A { 119 class B extends A {
120 void set test(int v){ 120 void set test(int v){
121 super.test = 0; 121 super.test = 0;
122 } 122 }
123 } 123 }
124 '''); 124 ''');
125 assertErrors(source, [HintCode.ABSTRACT_SUPER_MEMBER_REFERENCE]); 125 await assertErrors(source, [HintCode.ABSTRACT_SUPER_MEMBER_REFERENCE]);
126 verify([source]); 126 verify([source]);
127 } 127 }
128 128
129 void test_argumentTypeNotAssignable_functionType() { 129 test_argumentTypeNotAssignable_functionType() async {
130 Source source = addSource(r''' 130 Source source = addSource(r'''
131 m() { 131 m() {
132 var a = new A(); 132 var a = new A();
133 a.n(() => 0); 133 a.n(() => 0);
134 } 134 }
135 class A { 135 class A {
136 n(void f(int i)) {} 136 n(void f(int i)) {}
137 }'''); 137 }''');
138 assertErrors(source, [HintCode.ARGUMENT_TYPE_NOT_ASSIGNABLE]); 138 await assertErrors(source, [HintCode.ARGUMENT_TYPE_NOT_ASSIGNABLE]);
139 verify([source]); 139 verify([source]);
140 } 140 }
141 141
142 void test_argumentTypeNotAssignable_message() { 142 test_argumentTypeNotAssignable_message() async {
143 // The implementation of HintCode.ARGUMENT_TYPE_NOT_ASSIGNABLE assumes that 143 // The implementation of HintCode.ARGUMENT_TYPE_NOT_ASSIGNABLE assumes that
144 // StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE has the same message. 144 // StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE has the same message.
145 expect(StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE.message, 145 expect(StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE.message,
146 HintCode.ARGUMENT_TYPE_NOT_ASSIGNABLE.message); 146 HintCode.ARGUMENT_TYPE_NOT_ASSIGNABLE.message);
147 } 147 }
148 148
149 void test_argumentTypeNotAssignable_type() { 149 test_argumentTypeNotAssignable_type() async {
150 Source source = addSource(r''' 150 Source source = addSource(r'''
151 m() { 151 m() {
152 var i = ''; 152 var i = '';
153 n(i); 153 n(i);
154 } 154 }
155 n(int i) {}'''); 155 n(int i) {}''');
156 assertErrors(source, [HintCode.ARGUMENT_TYPE_NOT_ASSIGNABLE]); 156 await assertErrors(source, [HintCode.ARGUMENT_TYPE_NOT_ASSIGNABLE]);
157 verify([source]); 157 verify([source]);
158 } 158 }
159 159
160 void test_canBeNullAfterNullAware_false_methodInvocation() { 160 test_canBeNullAfterNullAware_false_methodInvocation() async {
161 Source source = addSource(r''' 161 Source source = addSource(r'''
162 m(x) { 162 m(x) {
163 x?.a()?.b(); 163 x?.a()?.b();
164 } 164 }
165 '''); 165 ''');
166 assertNoErrors(source); 166 await assertNoErrors(source);
167 verify([source]); 167 verify([source]);
168 } 168 }
169 169
170 void test_canBeNullAfterNullAware_false_null() { 170 test_canBeNullAfterNullAware_false_null() async {
171 Source source = addSource(r''' 171 Source source = addSource(r'''
172 m(x) { 172 m(x) {
173 x?.a.hashCode; 173 x?.a.hashCode;
174 x?.a.runtimeType; 174 x?.a.runtimeType;
175 x?.a.toString(); 175 x?.a.toString();
176 x?.b().hashCode; 176 x?.b().hashCode;
177 x?.b().runtimeType; 177 x?.b().runtimeType;
178 x?.b().toString(); 178 x?.b().toString();
179 } 179 }
180 '''); 180 ''');
181 assertNoErrors(source); 181 await assertNoErrors(source);
182 verify([source]); 182 verify([source]);
183 } 183 }
184 184
185 void test_canBeNullAfterNullAware_false_propertyAccess() { 185 test_canBeNullAfterNullAware_false_propertyAccess() async {
186 Source source = addSource(r''' 186 Source source = addSource(r'''
187 m(x) { 187 m(x) {
188 x?.a?.b; 188 x?.a?.b;
189 } 189 }
190 '''); 190 ''');
191 assertNoErrors(source); 191 await assertNoErrors(source);
192 verify([source]); 192 verify([source]);
193 } 193 }
194 194
195 void test_canBeNullAfterNullAware_methodInvocation() { 195 test_canBeNullAfterNullAware_methodInvocation() async {
196 Source source = addSource(r''' 196 Source source = addSource(r'''
197 m(x) { 197 m(x) {
198 x?.a.b(); 198 x?.a.b();
199 } 199 }
200 '''); 200 ''');
201 assertErrors(source, [HintCode.CAN_BE_NULL_AFTER_NULL_AWARE]); 201 await assertErrors(source, [HintCode.CAN_BE_NULL_AFTER_NULL_AWARE]);
202 verify([source]); 202 verify([source]);
203 } 203 }
204 204
205 void test_canBeNullAfterNullAware_parenthesized() { 205 test_canBeNullAfterNullAware_parenthesized() async {
206 Source source = addSource(r''' 206 Source source = addSource(r'''
207 m(x) { 207 m(x) {
208 (x?.a).b; 208 (x?.a).b;
209 } 209 }
210 '''); 210 ''');
211 assertErrors(source, [HintCode.CAN_BE_NULL_AFTER_NULL_AWARE]); 211 await assertErrors(source, [HintCode.CAN_BE_NULL_AFTER_NULL_AWARE]);
212 verify([source]); 212 verify([source]);
213 } 213 }
214 214
215 void test_canBeNullAfterNullAware_propertyAccess() { 215 test_canBeNullAfterNullAware_propertyAccess() async {
216 Source source = addSource(r''' 216 Source source = addSource(r'''
217 m(x) { 217 m(x) {
218 x?.a.b; 218 x?.a.b;
219 } 219 }
220 '''); 220 ''');
221 assertErrors(source, [HintCode.CAN_BE_NULL_AFTER_NULL_AWARE]); 221 await assertErrors(source, [HintCode.CAN_BE_NULL_AFTER_NULL_AWARE]);
222 verify([source]); 222 verify([source]);
223 } 223 }
224 224
225 void test_deadCode_deadBlock_conditionalElse() { 225 test_deadCode_deadBlock_conditionalElse() async {
226 Source source = addSource(r''' 226 Source source = addSource(r'''
227 f() { 227 f() {
228 true ? 1 : 2; 228 true ? 1 : 2;
229 }'''); 229 }''');
230 assertErrors(source, [HintCode.DEAD_CODE]); 230 await assertErrors(source, [HintCode.DEAD_CODE]);
231 verify([source]); 231 verify([source]);
232 } 232 }
233 233
234 void test_deadCode_deadBlock_conditionalElse_nested() { 234 test_deadCode_deadBlock_conditionalElse_nested() async {
235 // test that a dead else-statement can't generate additional violations 235 // test that a dead else-statement can't generate additional violations
236 Source source = addSource(r''' 236 Source source = addSource(r'''
237 f() { 237 f() {
238 true ? true : false && false; 238 true ? true : false && false;
239 }'''); 239 }''');
240 assertErrors(source, [HintCode.DEAD_CODE]); 240 await assertErrors(source, [HintCode.DEAD_CODE]);
241 verify([source]); 241 verify([source]);
242 } 242 }
243 243
244 void test_deadCode_deadBlock_conditionalIf() { 244 test_deadCode_deadBlock_conditionalIf() async {
245 Source source = addSource(r''' 245 Source source = addSource(r'''
246 f() { 246 f() {
247 false ? 1 : 2; 247 false ? 1 : 2;
248 }'''); 248 }''');
249 assertErrors(source, [HintCode.DEAD_CODE]); 249 await assertErrors(source, [HintCode.DEAD_CODE]);
250 verify([source]); 250 verify([source]);
251 } 251 }
252 252
253 void test_deadCode_deadBlock_conditionalIf_nested() { 253 test_deadCode_deadBlock_conditionalIf_nested() async {
254 // test that a dead then-statement can't generate additional violations 254 // test that a dead then-statement can't generate additional violations
255 Source source = addSource(r''' 255 Source source = addSource(r'''
256 f() { 256 f() {
257 false ? false && false : true; 257 false ? false && false : true;
258 }'''); 258 }''');
259 assertErrors(source, [HintCode.DEAD_CODE]); 259 await assertErrors(source, [HintCode.DEAD_CODE]);
260 verify([source]); 260 verify([source]);
261 } 261 }
262 262
263 void test_deadCode_deadBlock_else() { 263 test_deadCode_deadBlock_else() async {
264 Source source = addSource(r''' 264 Source source = addSource(r'''
265 f() { 265 f() {
266 if(true) {} else {} 266 if(true) {} else {}
267 }'''); 267 }''');
268 assertErrors(source, [HintCode.DEAD_CODE]); 268 await assertErrors(source, [HintCode.DEAD_CODE]);
269 verify([source]); 269 verify([source]);
270 } 270 }
271 271
272 void test_deadCode_deadBlock_else_nested() { 272 test_deadCode_deadBlock_else_nested() async {
273 // test that a dead else-statement can't generate additional violations 273 // test that a dead else-statement can't generate additional violations
274 Source source = addSource(r''' 274 Source source = addSource(r'''
275 f() { 275 f() {
276 if(true) {} else {if (false) {}} 276 if(true) {} else {if (false) {}}
277 }'''); 277 }''');
278 assertErrors(source, [HintCode.DEAD_CODE]); 278 await assertErrors(source, [HintCode.DEAD_CODE]);
279 verify([source]); 279 verify([source]);
280 } 280 }
281 281
282 void test_deadCode_deadBlock_if() { 282 test_deadCode_deadBlock_if() async {
283 Source source = addSource(r''' 283 Source source = addSource(r'''
284 f() { 284 f() {
285 if(false) {} 285 if(false) {}
286 }'''); 286 }''');
287 assertErrors(source, [HintCode.DEAD_CODE]); 287 await assertErrors(source, [HintCode.DEAD_CODE]);
288 verify([source]); 288 verify([source]);
289 } 289 }
290 290
291 void test_deadCode_deadBlock_if_nested() { 291 test_deadCode_deadBlock_if_nested() async {
292 // test that a dead then-statement can't generate additional violations 292 // test that a dead then-statement can't generate additional violations
293 Source source = addSource(r''' 293 Source source = addSource(r'''
294 f() { 294 f() {
295 if(false) {if(false) {}} 295 if(false) {if(false) {}}
296 }'''); 296 }''');
297 assertErrors(source, [HintCode.DEAD_CODE]); 297 await assertErrors(source, [HintCode.DEAD_CODE]);
298 verify([source]); 298 verify([source]);
299 } 299 }
300 300
301 void test_deadCode_deadBlock_while() { 301 test_deadCode_deadBlock_while() async {
302 Source source = addSource(r''' 302 Source source = addSource(r'''
303 f() { 303 f() {
304 while(false) {} 304 while(false) {}
305 }'''); 305 }''');
306 assertErrors(source, [HintCode.DEAD_CODE]); 306 await assertErrors(source, [HintCode.DEAD_CODE]);
307 verify([source]); 307 verify([source]);
308 } 308 }
309 309
310 void test_deadCode_deadBlock_while_nested() { 310 test_deadCode_deadBlock_while_nested() async {
311 // test that a dead while body can't generate additional violations 311 // test that a dead while body can't generate additional violations
312 Source source = addSource(r''' 312 Source source = addSource(r'''
313 f() { 313 f() {
314 while(false) {if(false) {}} 314 while(false) {if(false) {}}
315 }'''); 315 }''');
316 assertErrors(source, [HintCode.DEAD_CODE]); 316 await assertErrors(source, [HintCode.DEAD_CODE]);
317 verify([source]); 317 verify([source]);
318 } 318 }
319 319
320 void test_deadCode_deadCatch_catchFollowingCatch() { 320 test_deadCode_deadCatch_catchFollowingCatch() async {
321 Source source = addSource(r''' 321 Source source = addSource(r'''
322 class A {} 322 class A {}
323 f() { 323 f() {
324 try {} catch (e) {} catch (e) {} 324 try {} catch (e) {} catch (e) {}
325 }'''); 325 }''');
326 assertErrors(source, [HintCode.DEAD_CODE_CATCH_FOLLOWING_CATCH]); 326 await assertErrors(source, [HintCode.DEAD_CODE_CATCH_FOLLOWING_CATCH]);
327 verify([source]); 327 verify([source]);
328 } 328 }
329 329
330 void test_deadCode_deadCatch_catchFollowingCatch_nested() { 330 test_deadCode_deadCatch_catchFollowingCatch_nested() async {
331 // test that a dead catch clause can't generate additional violations 331 // test that a dead catch clause can't generate additional violations
332 Source source = addSource(r''' 332 Source source = addSource(r'''
333 class A {} 333 class A {}
334 f() { 334 f() {
335 try {} catch (e) {} catch (e) {if(false) {}} 335 try {} catch (e) {} catch (e) {if(false) {}}
336 }'''); 336 }''');
337 assertErrors(source, [HintCode.DEAD_CODE_CATCH_FOLLOWING_CATCH]); 337 await assertErrors(source, [HintCode.DEAD_CODE_CATCH_FOLLOWING_CATCH]);
338 verify([source]); 338 verify([source]);
339 } 339 }
340 340
341 void test_deadCode_deadCatch_catchFollowingCatch_object() { 341 test_deadCode_deadCatch_catchFollowingCatch_object() async {
342 Source source = addSource(r''' 342 Source source = addSource(r'''
343 f() { 343 f() {
344 try {} on Object catch (e) {} catch (e) {} 344 try {} on Object catch (e) {} catch (e) {}
345 }'''); 345 }''');
346 assertErrors(source, [HintCode.DEAD_CODE_CATCH_FOLLOWING_CATCH]); 346 await assertErrors(source, [HintCode.DEAD_CODE_CATCH_FOLLOWING_CATCH]);
347 verify([source]); 347 verify([source]);
348 } 348 }
349 349
350 void test_deadCode_deadCatch_catchFollowingCatch_object_nested() { 350 test_deadCode_deadCatch_catchFollowingCatch_object_nested() async {
351 // test that a dead catch clause can't generate additional violations 351 // test that a dead catch clause can't generate additional violations
352 Source source = addSource(r''' 352 Source source = addSource(r'''
353 f() { 353 f() {
354 try {} on Object catch (e) {} catch (e) {if(false) {}} 354 try {} on Object catch (e) {} catch (e) {if(false) {}}
355 }'''); 355 }''');
356 assertErrors(source, [HintCode.DEAD_CODE_CATCH_FOLLOWING_CATCH]); 356 await assertErrors(source, [HintCode.DEAD_CODE_CATCH_FOLLOWING_CATCH]);
357 verify([source]); 357 verify([source]);
358 } 358 }
359 359
360 void test_deadCode_deadCatch_onCatchSubtype() { 360 test_deadCode_deadCatch_onCatchSubtype() async {
361 Source source = addSource(r''' 361 Source source = addSource(r'''
362 class A {} 362 class A {}
363 class B extends A {} 363 class B extends A {}
364 f() { 364 f() {
365 try {} on A catch (e) {} on B catch (e) {} 365 try {} on A catch (e) {} on B catch (e) {}
366 }'''); 366 }''');
367 assertErrors(source, [HintCode.DEAD_CODE_ON_CATCH_SUBTYPE]); 367 await assertErrors(source, [HintCode.DEAD_CODE_ON_CATCH_SUBTYPE]);
368 verify([source]); 368 verify([source]);
369 } 369 }
370 370
371 void test_deadCode_deadCatch_onCatchSubtype_nested() { 371 test_deadCode_deadCatch_onCatchSubtype_nested() async {
372 // test that a dead catch clause can't generate additional violations 372 // test that a dead catch clause can't generate additional violations
373 Source source = addSource(r''' 373 Source source = addSource(r'''
374 class A {} 374 class A {}
375 class B extends A {} 375 class B extends A {}
376 f() { 376 f() {
377 try {} on A catch (e) {} on B catch (e) {if(false) {}} 377 try {} on A catch (e) {} on B catch (e) {if(false) {}}
378 }'''); 378 }''');
379 assertErrors(source, [HintCode.DEAD_CODE_ON_CATCH_SUBTYPE]); 379 await assertErrors(source, [HintCode.DEAD_CODE_ON_CATCH_SUBTYPE]);
380 verify([source]); 380 verify([source]);
381 } 381 }
382 382
383 void test_deadCode_deadFinalReturnInCase() { 383 test_deadCode_deadFinalReturnInCase() async {
384 Source source = addSource(r''' 384 Source source = addSource(r'''
385 f() { 385 f() {
386 switch (true) { 386 switch (true) {
387 case true: 387 case true:
388 try { 388 try {
389 int a = 1; 389 int a = 1;
390 } finally { 390 } finally {
391 return; 391 return;
392 } 392 }
393 return; 393 return;
394 default: 394 default:
395 break; 395 break;
396 } 396 }
397 }'''); 397 }''');
398 assertErrors(source, [HintCode.DEAD_CODE]); 398 await assertErrors(source, [HintCode.DEAD_CODE]);
399 verify([source]); 399 verify([source]);
400 } 400 }
401 401
402 void test_deadCode_deadFinalStatementInCase() { 402 test_deadCode_deadFinalStatementInCase() async {
403 Source source = addSource(r''' 403 Source source = addSource(r'''
404 f() { 404 f() {
405 switch (true) { 405 switch (true) {
406 case true: 406 case true:
407 try { 407 try {
408 int a = 1; 408 int a = 1;
409 } finally { 409 } finally {
410 return; 410 return;
411 } 411 }
412 int b = 1; 412 int b = 1;
413 default: 413 default:
414 break; 414 break;
415 } 415 }
416 }'''); 416 }''');
417 // A single dead statement at the end of a switch case that is not a 417 // A single dead statement at the end of a switch case that is not a
418 // terminating statement will yield two errors. 418 // terminating statement will yield two errors.
419 assertErrors(source, 419 await assertErrors(source,
420 [HintCode.DEAD_CODE, StaticWarningCode.CASE_BLOCK_NOT_TERMINATED]); 420 [HintCode.DEAD_CODE, StaticWarningCode.CASE_BLOCK_NOT_TERMINATED]);
421 verify([source]); 421 verify([source]);
422 } 422 }
423 423
424 void test_deadCode_deadOperandLHS_and() { 424 test_deadCode_deadOperandLHS_and() async {
425 Source source = addSource(r''' 425 Source source = addSource(r'''
426 f() { 426 f() {
427 bool b = false && false; 427 bool b = false && false;
428 }'''); 428 }''');
429 assertErrors(source, [HintCode.DEAD_CODE]); 429 await assertErrors(source, [HintCode.DEAD_CODE]);
430 verify([source]); 430 verify([source]);
431 } 431 }
432 432
433 void test_deadCode_deadOperandLHS_and_nested() { 433 test_deadCode_deadOperandLHS_and_nested() async {
434 Source source = addSource(r''' 434 Source source = addSource(r'''
435 f() { 435 f() {
436 bool b = false && (false && false); 436 bool b = false && (false && false);
437 }'''); 437 }''');
438 assertErrors(source, [HintCode.DEAD_CODE]); 438 await assertErrors(source, [HintCode.DEAD_CODE]);
439 verify([source]); 439 verify([source]);
440 } 440 }
441 441
442 void test_deadCode_deadOperandLHS_or() { 442 test_deadCode_deadOperandLHS_or() async {
443 Source source = addSource(r''' 443 Source source = addSource(r'''
444 f() { 444 f() {
445 bool b = true || true; 445 bool b = true || true;
446 }'''); 446 }''');
447 assertErrors(source, [HintCode.DEAD_CODE]); 447 await assertErrors(source, [HintCode.DEAD_CODE]);
448 verify([source]); 448 verify([source]);
449 } 449 }
450 450
451 void test_deadCode_deadOperandLHS_or_nested() { 451 test_deadCode_deadOperandLHS_or_nested() async {
452 Source source = addSource(r''' 452 Source source = addSource(r'''
453 f() { 453 f() {
454 bool b = true || (false && false); 454 bool b = true || (false && false);
455 }'''); 455 }''');
456 assertErrors(source, [HintCode.DEAD_CODE]); 456 await assertErrors(source, [HintCode.DEAD_CODE]);
457 verify([source]); 457 verify([source]);
458 } 458 }
459 459
460 void test_deadCode_statementAfterBreak_inDefaultCase() { 460 test_deadCode_statementAfterBreak_inDefaultCase() async {
461 Source source = addSource(r''' 461 Source source = addSource(r'''
462 f(v) { 462 f(v) {
463 switch(v) { 463 switch(v) {
464 case 1: 464 case 1:
465 default: 465 default:
466 break; 466 break;
467 var a; 467 var a;
468 } 468 }
469 }'''); 469 }''');
470 assertErrors(source, [HintCode.DEAD_CODE]); 470 await assertErrors(source, [HintCode.DEAD_CODE]);
471 verify([source]); 471 verify([source]);
472 } 472 }
473 473
474 void test_deadCode_statementAfterBreak_inForEachStatement() { 474 test_deadCode_statementAfterBreak_inForEachStatement() async {
475 Source source = addSource(r''' 475 Source source = addSource(r'''
476 f() { 476 f() {
477 var list; 477 var list;
478 for(var l in list) { 478 for(var l in list) {
479 break; 479 break;
480 var a; 480 var a;
481 } 481 }
482 }'''); 482 }''');
483 assertErrors(source, [HintCode.DEAD_CODE]); 483 await assertErrors(source, [HintCode.DEAD_CODE]);
484 verify([source]); 484 verify([source]);
485 } 485 }
486 486
487 void test_deadCode_statementAfterBreak_inForStatement() { 487 test_deadCode_statementAfterBreak_inForStatement() async {
488 Source source = addSource(r''' 488 Source source = addSource(r'''
489 f() { 489 f() {
490 for(;;) { 490 for(;;) {
491 break; 491 break;
492 var a; 492 var a;
493 } 493 }
494 }'''); 494 }''');
495 assertErrors(source, [HintCode.DEAD_CODE]); 495 await assertErrors(source, [HintCode.DEAD_CODE]);
496 verify([source]); 496 verify([source]);
497 } 497 }
498 498
499 void test_deadCode_statementAfterBreak_inSwitchCase() { 499 test_deadCode_statementAfterBreak_inSwitchCase() async {
500 Source source = addSource(r''' 500 Source source = addSource(r'''
501 f(v) { 501 f(v) {
502 switch(v) { 502 switch(v) {
503 case 1: 503 case 1:
504 break; 504 break;
505 var a; 505 var a;
506 } 506 }
507 }'''); 507 }''');
508 assertErrors(source, [HintCode.DEAD_CODE]); 508 await assertErrors(source, [HintCode.DEAD_CODE]);
509 verify([source]); 509 verify([source]);
510 } 510 }
511 511
512 void test_deadCode_statementAfterBreak_inWhileStatement() { 512 test_deadCode_statementAfterBreak_inWhileStatement() async {
513 Source source = addSource(r''' 513 Source source = addSource(r'''
514 f(v) { 514 f(v) {
515 while(v) { 515 while(v) {
516 break; 516 break;
517 var a; 517 var a;
518 } 518 }
519 }'''); 519 }''');
520 assertErrors(source, [HintCode.DEAD_CODE]); 520 await assertErrors(source, [HintCode.DEAD_CODE]);
521 verify([source]); 521 verify([source]);
522 } 522 }
523 523
524 void test_deadCode_statementAfterContinue_inForEachStatement() { 524 test_deadCode_statementAfterContinue_inForEachStatement() async {
525 Source source = addSource(r''' 525 Source source = addSource(r'''
526 f() { 526 f() {
527 var list; 527 var list;
528 for(var l in list) { 528 for(var l in list) {
529 continue; 529 continue;
530 var a; 530 var a;
531 } 531 }
532 }'''); 532 }''');
533 assertErrors(source, [HintCode.DEAD_CODE]); 533 await assertErrors(source, [HintCode.DEAD_CODE]);
534 verify([source]); 534 verify([source]);
535 } 535 }
536 536
537 void test_deadCode_statementAfterContinue_inForStatement() { 537 test_deadCode_statementAfterContinue_inForStatement() async {
538 Source source = addSource(r''' 538 Source source = addSource(r'''
539 f() { 539 f() {
540 for(;;) { 540 for(;;) {
541 continue; 541 continue;
542 var a; 542 var a;
543 } 543 }
544 }'''); 544 }''');
545 assertErrors(source, [HintCode.DEAD_CODE]); 545 await assertErrors(source, [HintCode.DEAD_CODE]);
546 verify([source]); 546 verify([source]);
547 } 547 }
548 548
549 void test_deadCode_statementAfterContinue_inWhileStatement() { 549 test_deadCode_statementAfterContinue_inWhileStatement() async {
550 Source source = addSource(r''' 550 Source source = addSource(r'''
551 f(v) { 551 f(v) {
552 while(v) { 552 while(v) {
553 continue; 553 continue;
554 var a; 554 var a;
555 } 555 }
556 }'''); 556 }''');
557 assertErrors(source, [HintCode.DEAD_CODE]); 557 await assertErrors(source, [HintCode.DEAD_CODE]);
558 verify([source]); 558 verify([source]);
559 } 559 }
560 560
561 void test_deadCode_statementAfterExitingIf_returns() { 561 test_deadCode_statementAfterExitingIf_returns() async {
562 Source source = addSource(r''' 562 Source source = addSource(r'''
563 f() { 563 f() {
564 if (1 > 2) { 564 if (1 > 2) {
565 return; 565 return;
566 } else { 566 } else {
567 return; 567 return;
568 } 568 }
569 var one = 1; 569 var one = 1;
570 }'''); 570 }''');
571 assertErrors(source, [HintCode.DEAD_CODE]); 571 await assertErrors(source, [HintCode.DEAD_CODE]);
572 verify([source]); 572 verify([source]);
573 } 573 }
574 574
575 void test_deadCode_statementAfterRethrow() { 575 test_deadCode_statementAfterRethrow() async {
576 Source source = addSource(r''' 576 Source source = addSource(r'''
577 f() { 577 f() {
578 try { 578 try {
579 var one = 1; 579 var one = 1;
580 } catch (e) { 580 } catch (e) {
581 rethrow; 581 rethrow;
582 var two = 2; 582 var two = 2;
583 } 583 }
584 }'''); 584 }''');
585 assertErrors(source, [HintCode.DEAD_CODE]); 585 await assertErrors(source, [HintCode.DEAD_CODE]);
586 verify([source]); 586 verify([source]);
587 } 587 }
588 588
589 void test_deadCode_statementAfterReturn_function() { 589 test_deadCode_statementAfterReturn_function() async {
590 Source source = addSource(r''' 590 Source source = addSource(r'''
591 f() { 591 f() {
592 var one = 1; 592 var one = 1;
593 return; 593 return;
594 var two = 2; 594 var two = 2;
595 }'''); 595 }''');
596 assertErrors(source, [HintCode.DEAD_CODE]); 596 await assertErrors(source, [HintCode.DEAD_CODE]);
597 verify([source]); 597 verify([source]);
598 } 598 }
599 599
600 void test_deadCode_statementAfterReturn_ifStatement() { 600 test_deadCode_statementAfterReturn_ifStatement() async {
601 Source source = addSource(r''' 601 Source source = addSource(r'''
602 f(bool b) { 602 f(bool b) {
603 if(b) { 603 if(b) {
604 var one = 1; 604 var one = 1;
605 return; 605 return;
606 var two = 2; 606 var two = 2;
607 } 607 }
608 }'''); 608 }''');
609 assertErrors(source, [HintCode.DEAD_CODE]); 609 await assertErrors(source, [HintCode.DEAD_CODE]);
610 verify([source]); 610 verify([source]);
611 } 611 }
612 612
613 void test_deadCode_statementAfterReturn_method() { 613 test_deadCode_statementAfterReturn_method() async {
614 Source source = addSource(r''' 614 Source source = addSource(r'''
615 class A { 615 class A {
616 m() { 616 m() {
617 var one = 1; 617 var one = 1;
618 return; 618 return;
619 var two = 2; 619 var two = 2;
620 } 620 }
621 }'''); 621 }''');
622 assertErrors(source, [HintCode.DEAD_CODE]); 622 await assertErrors(source, [HintCode.DEAD_CODE]);
623 verify([source]); 623 verify([source]);
624 } 624 }
625 625
626 void test_deadCode_statementAfterReturn_nested() { 626 test_deadCode_statementAfterReturn_nested() async {
627 Source source = addSource(r''' 627 Source source = addSource(r'''
628 f() { 628 f() {
629 var one = 1; 629 var one = 1;
630 return; 630 return;
631 if(false) {} 631 if(false) {}
632 }'''); 632 }''');
633 assertErrors(source, [HintCode.DEAD_CODE]); 633 await assertErrors(source, [HintCode.DEAD_CODE]);
634 verify([source]); 634 verify([source]);
635 } 635 }
636 636
637 void test_deadCode_statementAfterReturn_twoReturns() { 637 test_deadCode_statementAfterReturn_twoReturns() async {
638 Source source = addSource(r''' 638 Source source = addSource(r'''
639 f() { 639 f() {
640 var one = 1; 640 var one = 1;
641 return; 641 return;
642 var two = 2; 642 var two = 2;
643 return; 643 return;
644 var three = 3; 644 var three = 3;
645 }'''); 645 }''');
646 assertErrors(source, [HintCode.DEAD_CODE]); 646 await assertErrors(source, [HintCode.DEAD_CODE]);
647 verify([source]); 647 verify([source]);
648 } 648 }
649 649
650 void test_deadCode_statementAfterThrow() { 650 test_deadCode_statementAfterThrow() async {
651 Source source = addSource(r''' 651 Source source = addSource(r'''
652 f() { 652 f() {
653 var one = 1; 653 var one = 1;
654 throw 'Stop here'; 654 throw 'Stop here';
655 var two = 2; 655 var two = 2;
656 }'''); 656 }''');
657 assertErrors(source, [HintCode.DEAD_CODE]); 657 await assertErrors(source, [HintCode.DEAD_CODE]);
658 verify([source]); 658 verify([source]);
659 } 659 }
660 660
661 void test_deprecatedAnnotationUse_assignment() { 661 test_deprecatedAnnotationUse_assignment() async {
662 Source source = addSource(r''' 662 Source source = addSource(r'''
663 class A { 663 class A {
664 @deprecated 664 @deprecated
665 A operator+(A a) { return a; } 665 A operator+(A a) { return a; }
666 } 666 }
667 f(A a) { 667 f(A a) {
668 A b; 668 A b;
669 a += b; 669 a += b;
670 }'''); 670 }''');
671 assertErrors(source, [HintCode.DEPRECATED_MEMBER_USE]); 671 await assertErrors(source, [HintCode.DEPRECATED_MEMBER_USE]);
672 verify([source]); 672 verify([source]);
673 } 673 }
674 674
675 void test_deprecatedAnnotationUse_call() { 675 test_deprecatedAnnotationUse_call() async {
676 Source source = addSource(r''' 676 Source source = addSource(r'''
677 class A { 677 class A {
678 @deprecated 678 @deprecated
679 call() {} 679 call() {}
680 m() { 680 m() {
681 A a = new A(); 681 A a = new A();
682 a(); 682 a();
683 } 683 }
684 }'''); 684 }''');
685 assertErrors(source, [HintCode.DEPRECATED_MEMBER_USE]); 685 await assertErrors(source, [HintCode.DEPRECATED_MEMBER_USE]);
686 verify([source]); 686 verify([source]);
687 } 687 }
688 688
689 void test_deprecatedAnnotationUse_deprecated() { 689 test_deprecatedAnnotationUse_deprecated() async {
690 Source source = addSource(r''' 690 Source source = addSource(r'''
691 class A { 691 class A {
692 @deprecated 692 @deprecated
693 m() {} 693 m() {}
694 n() {m();} 694 n() {m();}
695 }'''); 695 }''');
696 assertErrors(source, [HintCode.DEPRECATED_MEMBER_USE]); 696 await assertErrors(source, [HintCode.DEPRECATED_MEMBER_USE]);
697 verify([source]); 697 verify([source]);
698 } 698 }
699 699
700 void test_deprecatedAnnotationUse_Deprecated() { 700 test_deprecatedAnnotationUse_Deprecated() async {
701 Source source = addSource(r''' 701 Source source = addSource(r'''
702 class A { 702 class A {
703 @Deprecated('0.9') 703 @Deprecated('0.9')
704 m() {} 704 m() {}
705 n() {m();} 705 n() {m();}
706 }'''); 706 }''');
707 assertErrors(source, [HintCode.DEPRECATED_MEMBER_USE]); 707 await assertErrors(source, [HintCode.DEPRECATED_MEMBER_USE]);
708 verify([source]); 708 verify([source]);
709 } 709 }
710 710
711 void test_deprecatedAnnotationUse_export() { 711 test_deprecatedAnnotationUse_export() async {
712 Source source = addSource("export 'deprecated_library.dart';"); 712 Source source = addSource("export 'deprecated_library.dart';");
713 addNamedSource( 713 addNamedSource(
714 "/deprecated_library.dart", 714 "/deprecated_library.dart",
715 r''' 715 r'''
716 @deprecated 716 @deprecated
717 library deprecated_library; 717 library deprecated_library;
718 class A {}'''); 718 class A {}''');
719 assertErrors(source, [HintCode.DEPRECATED_MEMBER_USE]); 719 await assertErrors(source, [HintCode.DEPRECATED_MEMBER_USE]);
720 verify([source]); 720 verify([source]);
721 } 721 }
722 722
723 void test_deprecatedAnnotationUse_field() { 723 test_deprecatedAnnotationUse_field() async {
724 Source source = addSource(r''' 724 Source source = addSource(r'''
725 class A { 725 class A {
726 @deprecated 726 @deprecated
727 int x = 1; 727 int x = 1;
728 } 728 }
729 f(A a) { 729 f(A a) {
730 return a.x; 730 return a.x;
731 }'''); 731 }''');
732 assertErrors(source, [HintCode.DEPRECATED_MEMBER_USE]); 732 await assertErrors(source, [HintCode.DEPRECATED_MEMBER_USE]);
733 verify([source]); 733 verify([source]);
734 } 734 }
735 735
736 void test_deprecatedAnnotationUse_getter() { 736 test_deprecatedAnnotationUse_getter() async {
737 Source source = addSource(r''' 737 Source source = addSource(r'''
738 class A { 738 class A {
739 @deprecated 739 @deprecated
740 get m => 1; 740 get m => 1;
741 } 741 }
742 f(A a) { 742 f(A a) {
743 return a.m; 743 return a.m;
744 }'''); 744 }''');
745 assertErrors(source, [HintCode.DEPRECATED_MEMBER_USE]); 745 await assertErrors(source, [HintCode.DEPRECATED_MEMBER_USE]);
746 verify([source]); 746 verify([source]);
747 } 747 }
748 748
749 void test_deprecatedAnnotationUse_import() { 749 test_deprecatedAnnotationUse_import() async {
750 Source source = addSource(r''' 750 Source source = addSource(r'''
751 import 'deprecated_library.dart'; 751 import 'deprecated_library.dart';
752 f(A a) {}'''); 752 f(A a) {}''');
753 addNamedSource( 753 addNamedSource(
754 "/deprecated_library.dart", 754 "/deprecated_library.dart",
755 r''' 755 r'''
756 @deprecated 756 @deprecated
757 library deprecated_library; 757 library deprecated_library;
758 class A {}'''); 758 class A {}''');
759 assertErrors(source, [HintCode.DEPRECATED_MEMBER_USE]); 759 await assertErrors(source, [HintCode.DEPRECATED_MEMBER_USE]);
760 verify([source]); 760 verify([source]);
761 } 761 }
762 762
763 void test_deprecatedAnnotationUse_indexExpression() { 763 test_deprecatedAnnotationUse_indexExpression() async {
764 Source source = addSource(r''' 764 Source source = addSource(r'''
765 class A { 765 class A {
766 @deprecated 766 @deprecated
767 operator[](int i) {} 767 operator[](int i) {}
768 } 768 }
769 f(A a) { 769 f(A a) {
770 return a[1]; 770 return a[1];
771 }'''); 771 }''');
772 assertErrors(source, [HintCode.DEPRECATED_MEMBER_USE]); 772 await assertErrors(source, [HintCode.DEPRECATED_MEMBER_USE]);
773 verify([source]); 773 verify([source]);
774 } 774 }
775 775
776 void test_deprecatedAnnotationUse_instanceCreation() { 776 test_deprecatedAnnotationUse_instanceCreation() async {
777 Source source = addSource(r''' 777 Source source = addSource(r'''
778 class A { 778 class A {
779 @deprecated 779 @deprecated
780 A(int i) {} 780 A(int i) {}
781 } 781 }
782 f() { 782 f() {
783 A a = new A(1); 783 A a = new A(1);
784 }'''); 784 }''');
785 assertErrors(source, [HintCode.DEPRECATED_MEMBER_USE]); 785 await assertErrors(source, [HintCode.DEPRECATED_MEMBER_USE]);
786 verify([source]); 786 verify([source]);
787 } 787 }
788 788
789 void test_deprecatedAnnotationUse_instanceCreation_namedConstructor() { 789 test_deprecatedAnnotationUse_instanceCreation_namedConstructor() async {
790 Source source = addSource(r''' 790 Source source = addSource(r'''
791 class A { 791 class A {
792 @deprecated 792 @deprecated
793 A.named(int i) {} 793 A.named(int i) {}
794 } 794 }
795 f() { 795 f() {
796 A a = new A.named(1); 796 A a = new A.named(1);
797 }'''); 797 }''');
798 assertErrors(source, [HintCode.DEPRECATED_MEMBER_USE]); 798 await assertErrors(source, [HintCode.DEPRECATED_MEMBER_USE]);
799 verify([source]); 799 verify([source]);
800 } 800 }
801 801
802 void test_deprecatedAnnotationUse_named() { 802 test_deprecatedAnnotationUse_named() async {
803 Source source = addSource(r''' 803 Source source = addSource(r'''
804 class A { 804 class A {
805 m({@deprecated int x}) {} 805 m({@deprecated int x}) {}
806 n() {m(x: 1);} 806 n() {m(x: 1);}
807 }'''); 807 }''');
808 assertErrors(source, [HintCode.DEPRECATED_MEMBER_USE]); 808 await assertErrors(source, [HintCode.DEPRECATED_MEMBER_USE]);
809 verify([source]); 809 verify([source]);
810 } 810 }
811 811
812 void test_deprecatedAnnotationUse_operator() { 812 test_deprecatedAnnotationUse_operator() async {
813 Source source = addSource(r''' 813 Source source = addSource(r'''
814 class A { 814 class A {
815 @deprecated 815 @deprecated
816 operator+(A a) {} 816 operator+(A a) {}
817 } 817 }
818 f(A a) { 818 f(A a) {
819 A b; 819 A b;
820 return a + b; 820 return a + b;
821 }'''); 821 }''');
822 assertErrors(source, [HintCode.DEPRECATED_MEMBER_USE]); 822 await assertErrors(source, [HintCode.DEPRECATED_MEMBER_USE]);
823 verify([source]); 823 verify([source]);
824 } 824 }
825 825
826 void test_deprecatedAnnotationUse_positional() { 826 test_deprecatedAnnotationUse_positional() async {
827 Source source = addSource(r''' 827 Source source = addSource(r'''
828 class A { 828 class A {
829 m([@deprecated int x]) {} 829 m([@deprecated int x]) {}
830 n() {m(1);} 830 n() {m(1);}
831 }'''); 831 }''');
832 assertErrors(source, [HintCode.DEPRECATED_MEMBER_USE]); 832 await assertErrors(source, [HintCode.DEPRECATED_MEMBER_USE]);
833 verify([source]); 833 verify([source]);
834 } 834 }
835 835
836 void test_deprecatedAnnotationUse_setter() { 836 test_deprecatedAnnotationUse_setter() async {
837 Source source = addSource(r''' 837 Source source = addSource(r'''
838 class A { 838 class A {
839 @deprecated 839 @deprecated
840 set s(v) {} 840 set s(v) {}
841 } 841 }
842 f(A a) { 842 f(A a) {
843 return a.s = 1; 843 return a.s = 1;
844 }'''); 844 }''');
845 assertErrors(source, [HintCode.DEPRECATED_MEMBER_USE]); 845 await assertErrors(source, [HintCode.DEPRECATED_MEMBER_USE]);
846 verify([source]); 846 verify([source]);
847 } 847 }
848 848
849 void test_deprecatedAnnotationUse_superConstructor() { 849 test_deprecatedAnnotationUse_superConstructor() async {
850 Source source = addSource(r''' 850 Source source = addSource(r'''
851 class A { 851 class A {
852 @deprecated 852 @deprecated
853 A() {} 853 A() {}
854 } 854 }
855 class B extends A { 855 class B extends A {
856 B() : super() {} 856 B() : super() {}
857 }'''); 857 }''');
858 assertErrors(source, [HintCode.DEPRECATED_MEMBER_USE]); 858 await assertErrors(source, [HintCode.DEPRECATED_MEMBER_USE]);
859 verify([source]); 859 verify([source]);
860 } 860 }
861 861
862 void test_deprecatedAnnotationUse_superConstructor_namedConstructor() { 862 test_deprecatedAnnotationUse_superConstructor_namedConstructor() async {
863 Source source = addSource(r''' 863 Source source = addSource(r'''
864 class A { 864 class A {
865 @deprecated 865 @deprecated
866 A.named() {} 866 A.named() {}
867 } 867 }
868 class B extends A { 868 class B extends A {
869 B() : super.named() {} 869 B() : super.named() {}
870 }'''); 870 }''');
871 assertErrors(source, [HintCode.DEPRECATED_MEMBER_USE]); 871 await assertErrors(source, [HintCode.DEPRECATED_MEMBER_USE]);
872 verify([source]); 872 verify([source]);
873 } 873 }
874 874
875 void test_divisionOptimization_double() { 875 test_divisionOptimization_double() async {
876 Source source = addSource(r''' 876 Source source = addSource(r'''
877 f(double x, double y) { 877 f(double x, double y) {
878 var v = (x / y).toInt(); 878 var v = (x / y).toInt();
879 }'''); 879 }''');
880 assertErrors(source, [HintCode.DIVISION_OPTIMIZATION]); 880 await assertErrors(source, [HintCode.DIVISION_OPTIMIZATION]);
881 verify([source]); 881 verify([source]);
882 } 882 }
883 883
884 void test_divisionOptimization_int() { 884 test_divisionOptimization_int() async {
885 Source source = addSource(r''' 885 Source source = addSource(r'''
886 f(int x, int y) { 886 f(int x, int y) {
887 var v = (x / y).toInt(); 887 var v = (x / y).toInt();
888 }'''); 888 }''');
889 assertErrors(source, [HintCode.DIVISION_OPTIMIZATION]); 889 await assertErrors(source, [HintCode.DIVISION_OPTIMIZATION]);
890 verify([source]); 890 verify([source]);
891 } 891 }
892 892
893 void test_divisionOptimization_propagatedType() { 893 test_divisionOptimization_propagatedType() async {
894 // Tests the propagated type information of the '/' method 894 // Tests the propagated type information of the '/' method
895 Source source = addSource(r''' 895 Source source = addSource(r'''
896 f(x, y) { 896 f(x, y) {
897 x = 1; 897 x = 1;
898 y = 1; 898 y = 1;
899 var v = (x / y).toInt(); 899 var v = (x / y).toInt();
900 }'''); 900 }''');
901 assertErrors(source, [HintCode.DIVISION_OPTIMIZATION]); 901 await assertErrors(source, [HintCode.DIVISION_OPTIMIZATION]);
902 verify([source]); 902 verify([source]);
903 } 903 }
904 904
905 void test_divisionOptimization_wrappedBinaryExpression() { 905 test_divisionOptimization_wrappedBinaryExpression() async {
906 Source source = addSource(r''' 906 Source source = addSource(r'''
907 f(int x, int y) { 907 f(int x, int y) {
908 var v = (((x / y))).toInt(); 908 var v = (((x / y))).toInt();
909 }'''); 909 }''');
910 assertErrors(source, [HintCode.DIVISION_OPTIMIZATION]); 910 await assertErrors(source, [HintCode.DIVISION_OPTIMIZATION]);
911 verify([source]); 911 verify([source]);
912 } 912 }
913 913
914 void test_duplicateImport() { 914 test_duplicateImport() async {
915 Source source = addSource(r''' 915 Source source = addSource(r'''
916 library L; 916 library L;
917 import 'lib1.dart'; 917 import 'lib1.dart';
918 import 'lib1.dart'; 918 import 'lib1.dart';
919 A a;'''); 919 A a;''');
920 addNamedSource( 920 addNamedSource(
921 "/lib1.dart", 921 "/lib1.dart",
922 r''' 922 r'''
923 library lib1; 923 library lib1;
924 class A {}'''); 924 class A {}''');
925 assertErrors(source, [HintCode.DUPLICATE_IMPORT]); 925 await assertErrors(source, [HintCode.DUPLICATE_IMPORT]);
926 verify([source]); 926 verify([source]);
927 } 927 }
928 928
929 void test_duplicateImport2() { 929 test_duplicateImport2() async {
930 Source source = addSource(r''' 930 Source source = addSource(r'''
931 library L; 931 library L;
932 import 'lib1.dart'; 932 import 'lib1.dart';
933 import 'lib1.dart'; 933 import 'lib1.dart';
934 import 'lib1.dart'; 934 import 'lib1.dart';
935 A a;'''); 935 A a;''');
936 addNamedSource( 936 addNamedSource(
937 "/lib1.dart", 937 "/lib1.dart",
938 r''' 938 r'''
939 library lib1; 939 library lib1;
940 class A {}'''); 940 class A {}''');
941 assertErrors( 941 await assertErrors(
942 source, [HintCode.DUPLICATE_IMPORT, HintCode.DUPLICATE_IMPORT]); 942 source, [HintCode.DUPLICATE_IMPORT, HintCode.DUPLICATE_IMPORT]);
943 verify([source]); 943 verify([source]);
944 } 944 }
945 945
946 void test_duplicateImport3() { 946 test_duplicateImport3() async {
947 Source source = addSource(r''' 947 Source source = addSource(r'''
948 library L; 948 library L;
949 import 'lib1.dart' as M show A hide B; 949 import 'lib1.dart' as M show A hide B;
950 import 'lib1.dart' as M show A hide B; 950 import 'lib1.dart' as M show A hide B;
951 M.A a;'''); 951 M.A a;''');
952 addNamedSource( 952 addNamedSource(
953 "/lib1.dart", 953 "/lib1.dart",
954 r''' 954 r'''
955 library lib1; 955 library lib1;
956 class A {} 956 class A {}
957 class B {}'''); 957 class B {}''');
958 assertErrors(source, [HintCode.DUPLICATE_IMPORT]); 958 await assertErrors(source, [HintCode.DUPLICATE_IMPORT]);
959 verify([source]); 959 verify([source]);
960 } 960 }
961 961
962 void test_factory__expr_return_null_OK() { 962 test_factory__expr_return_null_OK() async {
963 Source source = addSource(r''' 963 Source source = addSource(r'''
964 import 'package:meta/meta.dart'; 964 import 'package:meta/meta.dart';
965 965
966 class Stateful { 966 class Stateful {
967 @factory 967 @factory
968 State createState() => null; 968 State createState() => null;
969 } 969 }
970 970
971 class State { } 971 class State { }
972 '''); 972 ''');
973 assertNoErrors(source); 973 await assertNoErrors(source);
974 verify([source]); 974 verify([source]);
975 } 975 }
976 976
977 void test_factory_abstract_OK() { 977 test_factory_abstract_OK() async {
978 Source source = addSource(r''' 978 Source source = addSource(r'''
979 import 'package:meta/meta.dart'; 979 import 'package:meta/meta.dart';
980 980
981 abstract class Stateful { 981 abstract class Stateful {
982 @factory 982 @factory
983 State createState(); 983 State createState();
984 } 984 }
985 985
986 class State { } 986 class State { }
987 '''); 987 ''');
988 assertNoErrors(source); 988 await assertNoErrors(source);
989 verify([source]); 989 verify([source]);
990 } 990 }
991 991
992 void test_factory_bad_return() { 992 test_factory_bad_return() async {
993 Source source = addSource(r''' 993 Source source = addSource(r'''
994 import 'package:meta/meta.dart'; 994 import 'package:meta/meta.dart';
995 995
996 class Stateful { 996 class Stateful {
997 State _s = new State(); 997 State _s = new State();
998 998
999 @factory 999 @factory
1000 State createState() => _s; 1000 State createState() => _s;
1001 } 1001 }
1002 1002
1003 class State { } 1003 class State { }
1004 '''); 1004 ''');
1005 assertErrors(source, [HintCode.INVALID_FACTORY_METHOD_IMPL]); 1005 await assertErrors(source, [HintCode.INVALID_FACTORY_METHOD_IMPL]);
1006 verify([source]); 1006 verify([source]);
1007 } 1007 }
1008 1008
1009 void test_factory_block_OK() { 1009 test_factory_block_OK() async {
1010 Source source = addSource(r''' 1010 Source source = addSource(r'''
1011 import 'package:meta/meta.dart'; 1011 import 'package:meta/meta.dart';
1012 1012
1013 class Stateful { 1013 class Stateful {
1014 @factory 1014 @factory
1015 State createState() { 1015 State createState() {
1016 return new State(); 1016 return new State();
1017 } 1017 }
1018 } 1018 }
1019 1019
1020 class State { } 1020 class State { }
1021 '''); 1021 ''');
1022 assertNoErrors(source); 1022 await assertNoErrors(source);
1023 verify([source]); 1023 verify([source]);
1024 } 1024 }
1025 1025
1026 void test_factory_block_return_null_OK() { 1026 test_factory_block_return_null_OK() async {
1027 Source source = addSource(r''' 1027 Source source = addSource(r'''
1028 import 'package:meta/meta.dart'; 1028 import 'package:meta/meta.dart';
1029 1029
1030 class Stateful { 1030 class Stateful {
1031 @factory 1031 @factory
1032 State createState() { 1032 State createState() {
1033 return null; 1033 return null;
1034 } 1034 }
1035 } 1035 }
1036 1036
1037 class State { } 1037 class State { }
1038 '''); 1038 ''');
1039 assertNoErrors(source); 1039 await assertNoErrors(source);
1040 verify([source]); 1040 verify([source]);
1041 } 1041 }
1042 1042
1043 void test_factory_expr_OK() { 1043 test_factory_expr_OK() async {
1044 Source source = addSource(r''' 1044 Source source = addSource(r'''
1045 import 'package:meta/meta.dart'; 1045 import 'package:meta/meta.dart';
1046 1046
1047 class Stateful { 1047 class Stateful {
1048 @factory 1048 @factory
1049 State createState() => new State(); 1049 State createState() => new State();
1050 } 1050 }
1051 1051
1052 class State { } 1052 class State { }
1053 '''); 1053 ''');
1054 assertNoErrors(source); 1054 await assertNoErrors(source);
1055 verify([source]); 1055 verify([source]);
1056 } 1056 }
1057 1057
1058 void test_factory_misplaced_annotation() { 1058 test_factory_misplaced_annotation() async {
1059 Source source = addSource(r''' 1059 Source source = addSource(r'''
1060 import 'package:meta/meta.dart'; 1060 import 'package:meta/meta.dart';
1061 1061
1062 @factory 1062 @factory
1063 class X { 1063 class X {
1064 @factory 1064 @factory
1065 int x; 1065 int x;
1066 } 1066 }
1067 1067
1068 @factory 1068 @factory
1069 main() { } 1069 main() { }
1070 '''); 1070 ''');
1071 assertErrors(source, [ 1071 await assertErrors(source, [
1072 HintCode.INVALID_FACTORY_ANNOTATION, 1072 HintCode.INVALID_FACTORY_ANNOTATION,
1073 HintCode.INVALID_FACTORY_ANNOTATION, 1073 HintCode.INVALID_FACTORY_ANNOTATION,
1074 HintCode.INVALID_FACTORY_ANNOTATION 1074 HintCode.INVALID_FACTORY_ANNOTATION
1075 ]); 1075 ]);
1076 verify([source]); 1076 verify([source]);
1077 } 1077 }
1078 1078
1079 void test_factory_no_return_type_OK() { 1079 test_factory_no_return_type_OK() async {
1080 Source source = addSource(r''' 1080 Source source = addSource(r'''
1081 import 'package:meta/meta.dart'; 1081 import 'package:meta/meta.dart';
1082 1082
1083 class Stateful { 1083 class Stateful {
1084 @factory 1084 @factory
1085 createState() { 1085 createState() {
1086 return new Stateful(); 1086 return new Stateful();
1087 } 1087 }
1088 } 1088 }
1089 '''); 1089 ''');
1090 // Null return types will get flagged elsewhere, no need to pile-on here. 1090 // Null return types will get flagged elsewhere, no need to pile-on here.
1091 assertNoErrors(source); 1091 await assertNoErrors(source);
1092 verify([source]); 1092 verify([source]);
1093 } 1093 }
1094 1094
1095 void test_factory_subclass_OK() { 1095 test_factory_subclass_OK() async {
1096 Source source = addSource(r''' 1096 Source source = addSource(r'''
1097 import 'package:meta/meta.dart'; 1097 import 'package:meta/meta.dart';
1098 1098
1099 abstract class Stateful { 1099 abstract class Stateful {
1100 @factory 1100 @factory
1101 State createState(); 1101 State createState();
1102 } 1102 }
1103 1103
1104 class MyThing extends Stateful { 1104 class MyThing extends Stateful {
1105 @override 1105 @override
1106 State createState() { 1106 State createState() {
1107 print('my state'); 1107 print('my state');
1108 return new MyState(); 1108 return new MyState();
1109 } 1109 }
1110 } 1110 }
1111 1111
1112 class State { } 1112 class State { }
1113 class MyState extends State { } 1113 class MyState extends State { }
1114 '''); 1114 ''');
1115 assertNoErrors(source); 1115 await assertNoErrors(source);
1116 verify([source]); 1116 verify([source]);
1117 } 1117 }
1118 1118
1119 void test_factory_void_return() { 1119 test_factory_void_return() async {
1120 Source source = addSource(r''' 1120 Source source = addSource(r'''
1121 import 'package:meta/meta.dart'; 1121 import 'package:meta/meta.dart';
1122 1122
1123 class Stateful { 1123 class Stateful {
1124 @factory 1124 @factory
1125 void createState() {} 1125 void createState() {}
1126 } 1126 }
1127 '''); 1127 ''');
1128 assertErrors(source, [HintCode.INVALID_FACTORY_METHOD_DECL]); 1128 await assertErrors(source, [HintCode.INVALID_FACTORY_METHOD_DECL]);
1129 verify([source]); 1129 verify([source]);
1130 } 1130 }
1131 1131
1132 void test_importDeferredLibraryWithLoadFunction() { 1132 test_importDeferredLibraryWithLoadFunction() async {
1133 resolveWithErrors(<String>[ 1133 await resolveWithErrors(<String>[
1134 r''' 1134 r'''
1135 library lib1; 1135 library lib1;
1136 loadLibrary() {} 1136 loadLibrary() {}
1137 f() {}''', 1137 f() {}''',
1138 r''' 1138 r'''
1139 library root; 1139 library root;
1140 import 'lib1.dart' deferred as lib1; 1140 import 'lib1.dart' deferred as lib1;
1141 main() { lib1.f(); }''' 1141 main() { lib1.f(); }'''
1142 ], <ErrorCode>[ 1142 ], <ErrorCode>[
1143 HintCode.IMPORT_DEFERRED_LIBRARY_WITH_LOAD_FUNCTION 1143 HintCode.IMPORT_DEFERRED_LIBRARY_WITH_LOAD_FUNCTION
1144 ]); 1144 ]);
1145 } 1145 }
1146 1146
1147 void test_invalidAssignment_instanceVariable() { 1147 test_invalidAssignment_instanceVariable() async {
1148 Source source = addSource(r''' 1148 Source source = addSource(r'''
1149 class A { 1149 class A {
1150 int x; 1150 int x;
1151 } 1151 }
1152 f(var y) { 1152 f(var y) {
1153 A a; 1153 A a;
1154 if(y is String) { 1154 if(y is String) {
1155 a.x = y; 1155 a.x = y;
1156 } 1156 }
1157 }'''); 1157 }''');
1158 assertErrors(source, [HintCode.INVALID_ASSIGNMENT]); 1158 await assertErrors(source, [HintCode.INVALID_ASSIGNMENT]);
1159 verify([source]); 1159 verify([source]);
1160 } 1160 }
1161 1161
1162 void test_invalidAssignment_localVariable() { 1162 test_invalidAssignment_localVariable() async {
1163 Source source = addSource(r''' 1163 Source source = addSource(r'''
1164 f(var y) { 1164 f(var y) {
1165 if(y is String) { 1165 if(y is String) {
1166 int x = y; 1166 int x = y;
1167 } 1167 }
1168 }'''); 1168 }''');
1169 assertErrors(source, [HintCode.INVALID_ASSIGNMENT]); 1169 await assertErrors(source, [HintCode.INVALID_ASSIGNMENT]);
1170 verify([source]); 1170 verify([source]);
1171 } 1171 }
1172 1172
1173 void test_invalidAssignment_message() { 1173 test_invalidAssignment_message() async {
1174 // The implementation of HintCode.INVALID_ASSIGNMENT assumes that 1174 // The implementation of HintCode.INVALID_ASSIGNMENT assumes that
1175 // StaticTypeWarningCode.INVALID_ASSIGNMENT has the same message. 1175 // StaticTypeWarningCode.INVALID_ASSIGNMENT has the same message.
1176 expect(StaticTypeWarningCode.INVALID_ASSIGNMENT.message, 1176 expect(StaticTypeWarningCode.INVALID_ASSIGNMENT.message,
1177 HintCode.INVALID_ASSIGNMENT.message); 1177 HintCode.INVALID_ASSIGNMENT.message);
1178 } 1178 }
1179 1179
1180 void test_invalidAssignment_staticVariable() { 1180 test_invalidAssignment_staticVariable() async {
1181 Source source = addSource(r''' 1181 Source source = addSource(r'''
1182 class A { 1182 class A {
1183 static int x; 1183 static int x;
1184 } 1184 }
1185 f(var y) { 1185 f(var y) {
1186 if(y is String) { 1186 if(y is String) {
1187 A.x = y; 1187 A.x = y;
1188 } 1188 }
1189 }'''); 1189 }''');
1190 assertErrors(source, [HintCode.INVALID_ASSIGNMENT]); 1190 await assertErrors(source, [HintCode.INVALID_ASSIGNMENT]);
1191 verify([source]); 1191 verify([source]);
1192 } 1192 }
1193 1193
1194 void test_invalidAssignment_variableDeclaration() { 1194 test_invalidAssignment_variableDeclaration() async {
1195 // 17971 1195 // 17971
1196 Source source = addSource(r''' 1196 Source source = addSource(r'''
1197 class Point { 1197 class Point {
1198 final num x, y; 1198 final num x, y;
1199 Point(this.x, this.y); 1199 Point(this.x, this.y);
1200 Point operator +(Point other) { 1200 Point operator +(Point other) {
1201 return new Point(x+other.x, y+other.y); 1201 return new Point(x+other.x, y+other.y);
1202 } 1202 }
1203 } 1203 }
1204 main() { 1204 main() {
1205 var p1 = new Point(0, 0); 1205 var p1 = new Point(0, 0);
1206 var p2 = new Point(10, 10); 1206 var p2 = new Point(10, 10);
1207 int n = p1 + p2; 1207 int n = p1 + p2;
1208 }'''); 1208 }''');
1209 assertErrors(source, [HintCode.INVALID_ASSIGNMENT]); 1209 await assertErrors(source, [HintCode.INVALID_ASSIGNMENT]);
1210 verify([source]); 1210 verify([source]);
1211 } 1211 }
1212 1212
1213 void test_invalidUseOfProtectedMember_closure() { 1213 test_invalidUseOfProtectedMember_closure() async {
1214 Source source = addNamedSource( 1214 Source source = addNamedSource(
1215 '/lib1.dart', 1215 '/lib1.dart',
1216 r''' 1216 r'''
1217 import 'package:meta/meta.dart'; 1217 import 'package:meta/meta.dart';
1218 1218
1219 class A { 1219 class A {
1220 @protected 1220 @protected
1221 int a() => 42; 1221 int a() => 42;
1222 } 1222 }
1223 '''); 1223 ''');
1224 Source source2 = addNamedSource( 1224 Source source2 = addNamedSource(
1225 '/lib2.dart', 1225 '/lib2.dart',
1226 r''' 1226 r'''
1227 import 'lib1.dart'; 1227 import 'lib1.dart';
1228 1228
1229 void main() { 1229 void main() {
1230 var leak = new A().a; 1230 var leak = new A().a;
1231 print(leak); 1231 print(leak);
1232 } 1232 }
1233 '''); 1233 ''');
1234 assertErrors(source2, [HintCode.INVALID_USE_OF_PROTECTED_MEMBER]); 1234 await assertErrors(source2, [HintCode.INVALID_USE_OF_PROTECTED_MEMBER]);
1235 assertNoErrors(source); 1235 await assertNoErrors(source);
1236 verify([source, source2]); 1236 verify([source, source2]);
1237 } 1237 }
1238 1238
1239 void test_invalidUseOfProtectedMember_field() { 1239 test_invalidUseOfProtectedMember_field() async {
1240 Source source = addNamedSource( 1240 Source source = addNamedSource(
1241 '/lib1.dart', 1241 '/lib1.dart',
1242 r''' 1242 r'''
1243 import 'package:meta/meta.dart'; 1243 import 'package:meta/meta.dart';
1244 class A { 1244 class A {
1245 @protected 1245 @protected
1246 int a; 1246 int a;
1247 } 1247 }
1248 '''); 1248 ''');
1249 Source source2 = addNamedSource( 1249 Source source2 = addNamedSource(
1250 '/lib2.dart', 1250 '/lib2.dart',
1251 r''' 1251 r'''
1252 import 'lib1.dart'; 1252 import 'lib1.dart';
1253 1253
1254 abstract class B { 1254 abstract class B {
1255 int b() => new A().a; 1255 int b() => new A().a;
1256 } 1256 }
1257 '''); 1257 ''');
1258 assertErrors(source2, [HintCode.INVALID_USE_OF_PROTECTED_MEMBER]); 1258 await assertErrors(source2, [HintCode.INVALID_USE_OF_PROTECTED_MEMBER]);
1259 assertNoErrors(source); 1259 await assertNoErrors(source);
1260 verify([source, source2]); 1260 verify([source, source2]);
1261 } 1261 }
1262 1262
1263 void test_invalidUseOfProtectedMember_field_OK() { 1263 test_invalidUseOfProtectedMember_field_OK() async {
1264 Source source = addSource(r''' 1264 Source source = addSource(r'''
1265 import 'package:meta/meta.dart'; 1265 import 'package:meta/meta.dart';
1266 class A { 1266 class A {
1267 @protected 1267 @protected
1268 int a; 1268 int a;
1269 } 1269 }
1270 abstract class B implements A { 1270 abstract class B implements A {
1271 int b() => a; 1271 int b() => a;
1272 }'''); 1272 }''');
1273 assertNoErrors(source); 1273 await assertNoErrors(source);
1274 verify([source]); 1274 verify([source]);
1275 } 1275 }
1276 1276
1277 void test_invalidUseOfProtectedMember_function() { 1277 test_invalidUseOfProtectedMember_function() async {
1278 Source source = addNamedSource( 1278 Source source = addNamedSource(
1279 '/lib1.dart', 1279 '/lib1.dart',
1280 r''' 1280 r'''
1281 import 'package:meta/meta.dart'; 1281 import 'package:meta/meta.dart';
1282 class A { 1282 class A {
1283 @protected 1283 @protected
1284 void a(){ } 1284 void a(){ }
1285 } 1285 }
1286 '''); 1286 ''');
1287 Source source2 = addNamedSource( 1287 Source source2 = addNamedSource(
1288 '/lib2.dart', 1288 '/lib2.dart',
1289 r''' 1289 r'''
1290 import 'lib1.dart'; 1290 import 'lib1.dart';
1291 1291
1292 main() { 1292 main() {
1293 new A().a(); 1293 new A().a();
1294 } 1294 }
1295 '''); 1295 ''');
1296 assertErrors(source2, [HintCode.INVALID_USE_OF_PROTECTED_MEMBER]); 1296 await assertErrors(source2, [HintCode.INVALID_USE_OF_PROTECTED_MEMBER]);
1297 assertNoErrors(source); 1297 await assertNoErrors(source);
1298 verify([source, source2]); 1298 verify([source, source2]);
1299 } 1299 }
1300 1300
1301 void test_invalidUseOfProtectedMember_function_OK() { 1301 test_invalidUseOfProtectedMember_function_OK() async {
1302 Source source = addSource(r''' 1302 Source source = addSource(r'''
1303 import 'package:meta/meta.dart'; 1303 import 'package:meta/meta.dart';
1304 class A { 1304 class A {
1305 @protected 1305 @protected
1306 int a() => 0; 1306 int a() => 0;
1307 } 1307 }
1308 1308
1309 abstract class B implements A { 1309 abstract class B implements A {
1310 int b() => a(); 1310 int b() => a();
1311 }'''); 1311 }''');
1312 assertNoErrors(source); 1312 await assertNoErrors(source);
1313 verify([source]); 1313 verify([source]);
1314 } 1314 }
1315 1315
1316 void test_invalidUseOfProtectedMember_function_OK2() { 1316 test_invalidUseOfProtectedMember_function_OK2() async {
1317 Source source = addSource(r''' 1317 Source source = addSource(r'''
1318 import 'package:meta/meta.dart'; 1318 import 'package:meta/meta.dart';
1319 class A { 1319 class A {
1320 @protected 1320 @protected
1321 void a(){ } 1321 void a(){ }
1322 } 1322 }
1323 main() { 1323 main() {
1324 new A().a(); 1324 new A().a();
1325 }'''); 1325 }''');
1326 assertNoErrors(source); 1326 await assertNoErrors(source);
1327 verify([source]); 1327 verify([source]);
1328 } 1328 }
1329 1329
1330 void test_invalidUseOfProtectedMember_getter() { 1330 test_invalidUseOfProtectedMember_getter() async {
1331 Source source = addNamedSource( 1331 Source source = addNamedSource(
1332 '/lib1.dart', 1332 '/lib1.dart',
1333 r''' 1333 r'''
1334 import 'package:meta/meta.dart'; 1334 import 'package:meta/meta.dart';
1335 class A { 1335 class A {
1336 @protected 1336 @protected
1337 int get a => 42; 1337 int get a => 42;
1338 } 1338 }
1339 '''); 1339 ''');
1340 Source source2 = addNamedSource( 1340 Source source2 = addNamedSource(
1341 '/lib2.dart', 1341 '/lib2.dart',
1342 r''' 1342 r'''
1343 import 'lib1.dart'; 1343 import 'lib1.dart';
1344 1344
1345 class B { 1345 class B {
1346 A a; 1346 A a;
1347 int b() => a.a; 1347 int b() => a.a;
1348 } 1348 }
1349 '''); 1349 ''');
1350 assertErrors(source2, [HintCode.INVALID_USE_OF_PROTECTED_MEMBER]); 1350 await assertErrors(source2, [HintCode.INVALID_USE_OF_PROTECTED_MEMBER]);
1351 assertNoErrors(source); 1351 await assertNoErrors(source);
1352 verify([source, source2]); 1352 verify([source, source2]);
1353 } 1353 }
1354 1354
1355 void test_invalidUseOfProtectedMember_getter_OK() { 1355 test_invalidUseOfProtectedMember_getter_OK() async {
1356 Source source = addSource(r''' 1356 Source source = addSource(r'''
1357 import 'package:meta/meta.dart'; 1357 import 'package:meta/meta.dart';
1358 class A { 1358 class A {
1359 @protected 1359 @protected
1360 int get a => 42; 1360 int get a => 42;
1361 } 1361 }
1362 abstract class B implements A { 1362 abstract class B implements A {
1363 int b() => a; 1363 int b() => a;
1364 }'''); 1364 }''');
1365 assertNoErrors(source); 1365 await assertNoErrors(source);
1366 verify([source]); 1366 verify([source]);
1367 } 1367 }
1368 1368
1369 void test_invalidUseOfProtectedMember_in_docs_OK() { 1369 test_invalidUseOfProtectedMember_in_docs_OK() async {
1370 Source source = addSource(r''' 1370 Source source = addSource(r'''
1371 import 'package:meta/meta.dart'; 1371 import 'package:meta/meta.dart';
1372 1372
1373 class A { 1373 class A {
1374 @protected 1374 @protected
1375 int a() => c; 1375 int a() => c;
1376 @protected 1376 @protected
1377 int get b => a(); 1377 int get b => a();
1378 @protected 1378 @protected
1379 int c = 42; 1379 int c = 42;
1380 } 1380 }
1381 1381
1382 /// OK: [A.a], [A.b], [A.c]. 1382 /// OK: [A.a], [A.b], [A.c].
1383 f() {} 1383 f() {}
1384 '''); 1384 ''');
1385 assertNoErrors(source); 1385 await assertNoErrors(source);
1386 verify([source]); 1386 verify([source]);
1387 } 1387 }
1388 1388
1389 void test_invalidUseOfProtectedMember_message() { 1389 test_invalidUseOfProtectedMember_message() async {
1390 Source source = addNamedSource( 1390 Source source = addNamedSource(
1391 '/lib1.dart', 1391 '/lib1.dart',
1392 r''' 1392 r'''
1393 import 'package:meta/meta.dart'; 1393 import 'package:meta/meta.dart';
1394 class A { 1394 class A {
1395 @protected 1395 @protected
1396 void a(){ } 1396 void a(){ }
1397 } 1397 }
1398 '''); 1398 ''');
1399 Source source2 = addNamedSource( 1399 Source source2 = addNamedSource(
1400 '/lib2.dart', 1400 '/lib2.dart',
1401 r''' 1401 r'''
1402 import 'lib1.dart'; 1402 import 'lib1.dart';
1403 1403
1404 class B { 1404 class B {
1405 void b() => new A().a(); 1405 void b() => new A().a();
1406 } 1406 }
1407 '''); 1407 ''');
1408 List<AnalysisError> errors = analysisContext2.computeErrors(source2); 1408 List<AnalysisError> errors = analysisContext2.computeErrors(source2);
1409 expect(errors, hasLength(1)); 1409 expect(errors, hasLength(1));
1410 expect(errors[0].errorCode, HintCode.INVALID_USE_OF_PROTECTED_MEMBER); 1410 expect(errors[0].errorCode, HintCode.INVALID_USE_OF_PROTECTED_MEMBER);
1411 verify([source, source2]); 1411 verify([source, source2]);
1412 } 1412 }
1413 1413
1414 void test_invalidUseOfProtectedMember_method_1() { 1414 test_invalidUseOfProtectedMember_method_1() async {
1415 Source source = addNamedSource( 1415 Source source = addNamedSource(
1416 '/lib1.dart', 1416 '/lib1.dart',
1417 r''' 1417 r'''
1418 import 'package:meta/meta.dart'; 1418 import 'package:meta/meta.dart';
1419 class A { 1419 class A {
1420 @protected 1420 @protected
1421 void a(){ } 1421 void a(){ }
1422 } 1422 }
1423 '''); 1423 ''');
1424 Source source2 = addNamedSource( 1424 Source source2 = addNamedSource(
1425 '/lib2.dart', 1425 '/lib2.dart',
1426 r''' 1426 r'''
1427 import 'lib1.dart'; 1427 import 'lib1.dart';
1428 1428
1429 class B { 1429 class B {
1430 void b() => new A().a(); 1430 void b() => new A().a();
1431 } 1431 }
1432 '''); 1432 ''');
1433 1433
1434 assertErrors(source2, [HintCode.INVALID_USE_OF_PROTECTED_MEMBER]); 1434 await assertErrors(source2, [HintCode.INVALID_USE_OF_PROTECTED_MEMBER]);
1435 assertNoErrors(source); 1435 await assertNoErrors(source);
1436 verify([source, source2]); 1436 verify([source, source2]);
1437 } 1437 }
1438 1438
1439 void test_invalidUseOfProtectedMember_method_OK() { 1439 test_invalidUseOfProtectedMember_method_OK() async {
1440 // https://github.com/dart-lang/linter/issues/257 1440 // https://github.com/dart-lang/linter/issues/257
1441 Source source = addSource(r''' 1441 Source source = addSource(r'''
1442 import 'package:meta/meta.dart'; 1442 import 'package:meta/meta.dart';
1443 1443
1444 typedef void VoidCallback(); 1444 typedef void VoidCallback();
1445 1445
1446 class State<E> { 1446 class State<E> {
1447 @protected 1447 @protected
1448 void setState(VoidCallback fn) {} 1448 void setState(VoidCallback fn) {}
1449 } 1449 }
1450 1450
1451 class Button extends State<Object> { 1451 class Button extends State<Object> {
1452 void handleSomething() { 1452 void handleSomething() {
1453 setState(() {}); 1453 setState(() {});
1454 } 1454 }
1455 } 1455 }
1456 '''); 1456 ''');
1457 assertNoErrors(source); 1457 await assertNoErrors(source);
1458 verify([source]); 1458 verify([source]);
1459 } 1459 }
1460 1460
1461 void test_invalidUseOfProtectedMember_OK_1() { 1461 test_invalidUseOfProtectedMember_OK_1() async {
1462 Source source = addSource(r''' 1462 Source source = addSource(r'''
1463 import 'package:meta/meta.dart'; 1463 import 'package:meta/meta.dart';
1464 class A { 1464 class A {
1465 @protected 1465 @protected
1466 void a(){ } 1466 void a(){ }
1467 } 1467 }
1468 class B extends A { 1468 class B extends A {
1469 void b() => a(); 1469 void b() => a();
1470 }'''); 1470 }''');
1471 assertNoErrors(source); 1471 await assertNoErrors(source);
1472 verify([source]); 1472 verify([source]);
1473 } 1473 }
1474 1474
1475 void test_invalidUseOfProtectedMember_OK_2() { 1475 test_invalidUseOfProtectedMember_OK_2() async {
1476 Source source = addSource(r''' 1476 Source source = addSource(r'''
1477 import 'package:meta/meta.dart'; 1477 import 'package:meta/meta.dart';
1478 class A { 1478 class A {
1479 @protected 1479 @protected
1480 void a(){ } 1480 void a(){ }
1481 } 1481 }
1482 class B extends Object with A { 1482 class B extends Object with A {
1483 void b() => a(); 1483 void b() => a();
1484 }'''); 1484 }''');
1485 assertNoErrors(source); 1485 await assertNoErrors(source);
1486 verify([source]); 1486 verify([source]);
1487 } 1487 }
1488 1488
1489 void test_invalidUseOfProtectedMember_OK_3() { 1489 test_invalidUseOfProtectedMember_OK_3() async {
1490 Source source = addSource(r''' 1490 Source source = addSource(r'''
1491 import 'package:meta/meta.dart'; 1491 import 'package:meta/meta.dart';
1492 class A { 1492 class A {
1493 @protected m1() {} 1493 @protected m1() {}
1494 } 1494 }
1495 class B extends A { 1495 class B extends A {
1496 static m2(A a) => a.m1(); 1496 static m2(A a) => a.m1();
1497 }'''); 1497 }''');
1498 assertNoErrors(source); 1498 await assertNoErrors(source);
1499 verify([source]); 1499 verify([source]);
1500 } 1500 }
1501 1501
1502 void test_invalidUseOfProtectedMember_OK_4() { 1502 test_invalidUseOfProtectedMember_OK_4() async {
1503 Source source = addSource(r''' 1503 Source source = addSource(r'''
1504 import 'package:meta/meta.dart'; 1504 import 'package:meta/meta.dart';
1505 class A { 1505 class A {
1506 @protected 1506 @protected
1507 void a(){ } 1507 void a(){ }
1508 } 1508 }
1509 class B extends A { 1509 class B extends A {
1510 void a() => a(); 1510 void a() => a();
1511 } 1511 }
1512 main() { 1512 main() {
1513 new B().a(); 1513 new B().a();
1514 }'''); 1514 }''');
1515 assertNoErrors(source); 1515 await assertNoErrors(source);
1516 verify([source]); 1516 verify([source]);
1517 } 1517 }
1518 1518
1519 void test_invalidUseOfProtectedMember_OK_field() { 1519 test_invalidUseOfProtectedMember_OK_field() async {
1520 Source source = addSource(r''' 1520 Source source = addSource(r'''
1521 import 'package:meta/meta.dart'; 1521 import 'package:meta/meta.dart';
1522 class A { 1522 class A {
1523 @protected 1523 @protected
1524 int a = 42; 1524 int a = 42;
1525 } 1525 }
1526 class B extends A { 1526 class B extends A {
1527 int b() => a; 1527 int b() => a;
1528 } 1528 }
1529 '''); 1529 ''');
1530 assertNoErrors(source); 1530 await assertNoErrors(source);
1531 verify([source]); 1531 verify([source]);
1532 } 1532 }
1533 1533
1534 void test_invalidUseOfProtectedMember_OK_getter() { 1534 test_invalidUseOfProtectedMember_OK_getter() async {
1535 Source source = addSource(r''' 1535 Source source = addSource(r'''
1536 import 'package:meta/meta.dart'; 1536 import 'package:meta/meta.dart';
1537 class A { 1537 class A {
1538 @protected 1538 @protected
1539 int get a => 42; 1539 int get a => 42;
1540 } 1540 }
1541 class B extends A { 1541 class B extends A {
1542 int b() => a; 1542 int b() => a;
1543 } 1543 }
1544 '''); 1544 ''');
1545 assertNoErrors(source); 1545 await assertNoErrors(source);
1546 verify([source]); 1546 verify([source]);
1547 } 1547 }
1548 1548
1549 void test_invalidUseOfProtectedMember_OK_setter() { 1549 test_invalidUseOfProtectedMember_OK_setter() async {
1550 Source source = addSource(r''' 1550 Source source = addSource(r'''
1551 import 'package:meta/meta.dart'; 1551 import 'package:meta/meta.dart';
1552 class A { 1552 class A {
1553 @protected 1553 @protected
1554 void set a(int i) { } 1554 void set a(int i) { }
1555 } 1555 }
1556 class B extends A { 1556 class B extends A {
1557 void b(int i) { 1557 void b(int i) {
1558 a = i; 1558 a = i;
1559 } 1559 }
1560 } 1560 }
1561 '''); 1561 ''');
1562 assertNoErrors(source); 1562 await assertNoErrors(source);
1563 verify([source]); 1563 verify([source]);
1564 } 1564 }
1565 1565
1566 void test_invalidUseOfProtectedMember_OK_setter_2() { 1566 test_invalidUseOfProtectedMember_OK_setter_2() async {
1567 Source source = addSource(r''' 1567 Source source = addSource(r'''
1568 import 'package:meta/meta.dart'; 1568 import 'package:meta/meta.dart';
1569 class A { 1569 class A {
1570 int _a; 1570 int _a;
1571 @protected 1571 @protected
1572 void set a(int a) { _a = a; } 1572 void set a(int a) { _a = a; }
1573 A(int a) { 1573 A(int a) {
1574 this.a = a; 1574 this.a = a;
1575 } 1575 }
1576 } 1576 }
1577 '''); 1577 ''');
1578 assertNoErrors(source); 1578 await assertNoErrors(source);
1579 verify([source]); 1579 verify([source]);
1580 } 1580 }
1581 1581
1582 void test_invalidUseOfProtectedMember_setter() { 1582 test_invalidUseOfProtectedMember_setter() async {
1583 Source source = addNamedSource( 1583 Source source = addNamedSource(
1584 '/lib1.dart', 1584 '/lib1.dart',
1585 r''' 1585 r'''
1586 import 'package:meta/meta.dart'; 1586 import 'package:meta/meta.dart';
1587 class A { 1587 class A {
1588 @protected 1588 @protected
1589 void set a(int i) { } 1589 void set a(int i) { }
1590 } 1590 }
1591 '''); 1591 ''');
1592 Source source2 = addNamedSource( 1592 Source source2 = addNamedSource(
1593 '/lib2.dart', 1593 '/lib2.dart',
1594 r''' 1594 r'''
1595 import 'lib1.dart'; 1595 import 'lib1.dart';
1596 1596
1597 class B{ 1597 class B{
1598 A a; 1598 A a;
1599 b(int i) { 1599 b(int i) {
1600 a.a = i; 1600 a.a = i;
1601 } 1601 }
1602 } 1602 }
1603 '''); 1603 ''');
1604 assertErrors(source2, [HintCode.INVALID_USE_OF_PROTECTED_MEMBER]); 1604 await assertErrors(source2, [HintCode.INVALID_USE_OF_PROTECTED_MEMBER]);
1605 assertNoErrors(source); 1605 await assertNoErrors(source);
1606 verify([source, source2]); 1606 verify([source, source2]);
1607 } 1607 }
1608 1608
1609 void test_invalidUseOfProtectedMember_setter_OK() { 1609 test_invalidUseOfProtectedMember_setter_OK() async {
1610 Source source = addSource(r''' 1610 Source source = addSource(r'''
1611 import 'package:meta/meta.dart'; 1611 import 'package:meta/meta.dart';
1612 class A { 1612 class A {
1613 @protected 1613 @protected
1614 void set a(int i) { } 1614 void set a(int i) { }
1615 } 1615 }
1616 abstract class B implements A { 1616 abstract class B implements A {
1617 b(int i) { 1617 b(int i) {
1618 a = i; 1618 a = i;
1619 } 1619 }
1620 }'''); 1620 }''');
1621 assertNoErrors(source); 1621 await assertNoErrors(source);
1622 verify([source]); 1622 verify([source]);
1623 } 1623 }
1624 1624
1625 void test_invalidUseOfProtectedMember_topLevelVariable() { 1625 test_invalidUseOfProtectedMember_topLevelVariable() async {
1626 Source source = addSource(r''' 1626 Source source = addSource(r'''
1627 import 'package:meta/meta.dart'; 1627 import 'package:meta/meta.dart';
1628 @protected 1628 @protected
1629 int x = 0; 1629 int x = 0;
1630 main() { 1630 main() {
1631 print(x); 1631 print(x);
1632 }'''); 1632 }''');
1633 // TODO(brianwilkerson) This should produce a hint because the annotation is 1633 // TODO(brianwilkerson) This should produce a hint because the annotation is
1634 // being applied to the wrong kind of declaration. 1634 // being applied to the wrong kind of declaration.
1635 assertNoErrors(source); 1635 await assertNoErrors(source);
1636 verify([source]); 1636 verify([source]);
1637 } 1637 }
1638 1638
1639 void test_isDouble() { 1639 test_isDouble() async {
1640 AnalysisOptionsImpl options = new AnalysisOptionsImpl(); 1640 AnalysisOptionsImpl options = new AnalysisOptionsImpl();
1641 options.dart2jsHint = true; 1641 options.dart2jsHint = true;
1642 resetWithOptions(options); 1642 resetWithOptions(options);
1643 Source source = addSource("var v = 1 is double;"); 1643 Source source = addSource("var v = 1 is double;");
1644 assertErrors(source, [HintCode.IS_DOUBLE]); 1644 await assertErrors(source, [HintCode.IS_DOUBLE]);
1645 verify([source]); 1645 verify([source]);
1646 } 1646 }
1647 1647
1648 @failingTest 1648 @failingTest
1649 void test_isInt() { 1649 test_isInt() async {
1650 Source source = addSource("var v = 1 is int;"); 1650 Source source = addSource("var v = 1 is int;");
1651 assertErrors(source, [HintCode.IS_INT]); 1651 await assertErrors(source, [HintCode.IS_INT]);
1652 verify([source]); 1652 verify([source]);
1653 } 1653 }
1654 1654
1655 void test_isNotDouble() { 1655 test_isNotDouble() async {
1656 AnalysisOptionsImpl options = new AnalysisOptionsImpl(); 1656 AnalysisOptionsImpl options = new AnalysisOptionsImpl();
1657 options.dart2jsHint = true; 1657 options.dart2jsHint = true;
1658 resetWithOptions(options); 1658 resetWithOptions(options);
1659 Source source = addSource("var v = 1 is! double;"); 1659 Source source = addSource("var v = 1 is! double;");
1660 assertErrors(source, [HintCode.IS_NOT_DOUBLE]); 1660 await assertErrors(source, [HintCode.IS_NOT_DOUBLE]);
1661 verify([source]); 1661 verify([source]);
1662 } 1662 }
1663 1663
1664 @failingTest 1664 @failingTest
1665 void test_isNotInt() { 1665 test_isNotInt() async {
1666 Source source = addSource("var v = 1 is! int;"); 1666 Source source = addSource("var v = 1 is! int;");
1667 assertErrors(source, [HintCode.IS_NOT_INT]); 1667 await assertErrors(source, [HintCode.IS_NOT_INT]);
1668 verify([source]); 1668 verify([source]);
1669 } 1669 }
1670 1670
1671 void test_js_lib_OK() { 1671 test_js_lib_OK() async {
1672 Source source = addSource(r''' 1672 Source source = addSource(r'''
1673 @JS() 1673 @JS()
1674 library foo; 1674 library foo;
1675 1675
1676 import 'package:js/js.dart'; 1676 import 'package:js/js.dart';
1677 1677
1678 @JS() 1678 @JS()
1679 class A { } 1679 class A { }
1680 '''); 1680 ''');
1681 assertNoErrors(source); 1681 await assertNoErrors(source);
1682 verify([source]); 1682 verify([source]);
1683 } 1683 }
1684 1684
1685 void test_missingJsLibAnnotation_class() { 1685 test_missingJsLibAnnotation_class() async {
1686 Source source = addSource(r''' 1686 Source source = addSource(r'''
1687 library foo; 1687 library foo;
1688 1688
1689 import 'package:js/js.dart'; 1689 import 'package:js/js.dart';
1690 1690
1691 @JS() 1691 @JS()
1692 class A { } 1692 class A { }
1693 '''); 1693 ''');
1694 assertErrors(source, [HintCode.MISSING_JS_LIB_ANNOTATION]); 1694 await assertErrors(source, [HintCode.MISSING_JS_LIB_ANNOTATION]);
1695 verify([source]); 1695 verify([source]);
1696 } 1696 }
1697 1697
1698 void test_missingJsLibAnnotation_externalField() { 1698 test_missingJsLibAnnotation_externalField() async {
1699 // https://github.com/dart-lang/sdk/issues/26987 1699 // https://github.com/dart-lang/sdk/issues/26987
1700 Source source = addSource(r''' 1700 Source source = addSource(r'''
1701 import 'package:js/js.dart'; 1701 import 'package:js/js.dart';
1702 1702
1703 @JS() 1703 @JS()
1704 external dynamic exports; 1704 external dynamic exports;
1705 '''); 1705 ''');
1706 assertErrors(source, 1706 await assertErrors(source,
1707 [ParserErrorCode.EXTERNAL_FIELD, HintCode.MISSING_JS_LIB_ANNOTATION]); 1707 [ParserErrorCode.EXTERNAL_FIELD, HintCode.MISSING_JS_LIB_ANNOTATION]);
1708 verify([source]); 1708 verify([source]);
1709 } 1709 }
1710 1710
1711 void test_missingJsLibAnnotation_function() { 1711 test_missingJsLibAnnotation_function() async {
1712 Source source = addSource(r''' 1712 Source source = addSource(r'''
1713 library foo; 1713 library foo;
1714 1714
1715 import 'package:js/js.dart'; 1715 import 'package:js/js.dart';
1716 1716
1717 @JS('acxZIndex') 1717 @JS('acxZIndex')
1718 set _currentZIndex(int value) { } 1718 set _currentZIndex(int value) { }
1719 '''); 1719 ''');
1720 assertErrors(source, [HintCode.MISSING_JS_LIB_ANNOTATION]); 1720 await assertErrors(source, [HintCode.MISSING_JS_LIB_ANNOTATION]);
1721 verify([source]); 1721 verify([source]);
1722 } 1722 }
1723 1723
1724 void test_missingJsLibAnnotation_method() { 1724 test_missingJsLibAnnotation_method() async {
1725 Source source = addSource(r''' 1725 Source source = addSource(r'''
1726 library foo; 1726 library foo;
1727 1727
1728 import 'package:js/js.dart'; 1728 import 'package:js/js.dart';
1729 1729
1730 class A { 1730 class A {
1731 @JS() 1731 @JS()
1732 void a() { } 1732 void a() { }
1733 } 1733 }
1734 '''); 1734 ''');
1735 assertErrors(source, [HintCode.MISSING_JS_LIB_ANNOTATION]); 1735 await assertErrors(source, [HintCode.MISSING_JS_LIB_ANNOTATION]);
1736 verify([source]); 1736 verify([source]);
1737 } 1737 }
1738 1738
1739 void test_missingJsLibAnnotation_variable() { 1739 test_missingJsLibAnnotation_variable() async {
1740 Source source = addSource(r''' 1740 Source source = addSource(r'''
1741 import 'package:js/js.dart'; 1741 import 'package:js/js.dart';
1742 1742
1743 @JS() 1743 @JS()
1744 dynamic variable; 1744 dynamic variable;
1745 '''); 1745 ''');
1746 assertErrors(source, [HintCode.MISSING_JS_LIB_ANNOTATION]); 1746 await assertErrors(source, [HintCode.MISSING_JS_LIB_ANNOTATION]);
1747 verify([source]); 1747 verify([source]);
1748 } 1748 }
1749 1749
1750 void test_missingReturn_async() { 1750 test_missingReturn_async() async {
1751 Source source = addSource(''' 1751 Source source = addSource('''
1752 import 'dart:async'; 1752 import 'dart:async';
1753 Future<int> f() async {} 1753 Future<int> f() async {}
1754 '''); 1754 ''');
1755 assertErrors(source, [HintCode.MISSING_RETURN]); 1755 await assertErrors(source, [HintCode.MISSING_RETURN]);
1756 verify([source]); 1756 verify([source]);
1757 } 1757 }
1758 1758
1759 void test_missingReturn_factory() { 1759 test_missingReturn_factory() async {
1760 Source source = addSource(r''' 1760 Source source = addSource(r'''
1761 class A { 1761 class A {
1762 factory A() {} 1762 factory A() {}
1763 } 1763 }
1764 '''); 1764 ''');
1765 assertErrors(source, [HintCode.MISSING_RETURN]); 1765 await assertErrors(source, [HintCode.MISSING_RETURN]);
1766 verify([source]); 1766 verify([source]);
1767 } 1767 }
1768 1768
1769 void test_missingReturn_function() { 1769 test_missingReturn_function() async {
1770 Source source = addSource("int f() {}"); 1770 Source source = addSource("int f() {}");
1771 assertErrors(source, [HintCode.MISSING_RETURN]); 1771 await assertErrors(source, [HintCode.MISSING_RETURN]);
1772 verify([source]); 1772 verify([source]);
1773 } 1773 }
1774 1774
1775 void test_missingReturn_method() { 1775 test_missingReturn_method() async {
1776 Source source = addSource(r''' 1776 Source source = addSource(r'''
1777 class A { 1777 class A {
1778 int m() {} 1778 int m() {}
1779 }'''); 1779 }''');
1780 assertErrors(source, [HintCode.MISSING_RETURN]); 1780 await assertErrors(source, [HintCode.MISSING_RETURN]);
1781 verify([source]); 1781 verify([source]);
1782 } 1782 }
1783 1783
1784 void test_mustCallSuper() { 1784 test_mustCallSuper() async {
1785 Source source = addSource(r''' 1785 Source source = addSource(r'''
1786 import 'package:meta/meta.dart'; 1786 import 'package:meta/meta.dart';
1787 class A { 1787 class A {
1788 @mustCallSuper 1788 @mustCallSuper
1789 void a() {} 1789 void a() {}
1790 } 1790 }
1791 class B extends A { 1791 class B extends A {
1792 @override 1792 @override
1793 void a() 1793 void a()
1794 {} 1794 {}
1795 } 1795 }
1796 '''); 1796 ''');
1797 assertErrors(source, [HintCode.MUST_CALL_SUPER]); 1797 await assertErrors(source, [HintCode.MUST_CALL_SUPER]);
1798 verify([source]); 1798 verify([source]);
1799 } 1799 }
1800 1800
1801 void test_mustCallSuper_fromInterface() { 1801 test_mustCallSuper_fromInterface() async {
1802 Source source = addSource(r''' 1802 Source source = addSource(r'''
1803 import 'package:meta/meta.dart'; 1803 import 'package:meta/meta.dart';
1804 class A { 1804 class A {
1805 @mustCallSuper 1805 @mustCallSuper
1806 void a() {} 1806 void a() {}
1807 } 1807 }
1808 class C implements A { 1808 class C implements A {
1809 @override 1809 @override
1810 void a() {} 1810 void a() {}
1811 } 1811 }
1812 '''); 1812 ''');
1813 assertErrors(source, []); 1813 await assertErrors(source, []);
1814 verify([source]); 1814 verify([source]);
1815 } 1815 }
1816 1816
1817 void test_mustCallSuper_indirect() { 1817 test_mustCallSuper_indirect() async {
1818 Source source = addSource(r''' 1818 Source source = addSource(r'''
1819 import 'package:meta/meta.dart'; 1819 import 'package:meta/meta.dart';
1820 class A { 1820 class A {
1821 @mustCallSuper 1821 @mustCallSuper
1822 void a() {} 1822 void a() {}
1823 } 1823 }
1824 class C extends A { 1824 class C extends A {
1825 @override 1825 @override
1826 void a() { 1826 void a() {
1827 super.a(); 1827 super.a();
1828 } 1828 }
1829 } 1829 }
1830 class D extends C { 1830 class D extends C {
1831 @override 1831 @override
1832 void a() {} 1832 void a() {}
1833 } 1833 }
1834 '''); 1834 ''');
1835 assertErrors(source, [HintCode.MUST_CALL_SUPER]); 1835 await assertErrors(source, [HintCode.MUST_CALL_SUPER]);
1836 verify([source]); 1836 verify([source]);
1837 } 1837 }
1838 1838
1839 void test_mustCallSuper_overridden() { 1839 test_mustCallSuper_overridden() async {
1840 Source source = addSource(r''' 1840 Source source = addSource(r'''
1841 import 'package:meta/meta.dart'; 1841 import 'package:meta/meta.dart';
1842 class A { 1842 class A {
1843 @mustCallSuper 1843 @mustCallSuper
1844 void a() {} 1844 void a() {}
1845 } 1845 }
1846 class C extends A { 1846 class C extends A {
1847 @override 1847 @override
1848 void a() { 1848 void a() {
1849 super.a(); //OK 1849 super.a(); //OK
1850 } 1850 }
1851 } 1851 }
1852 '''); 1852 ''');
1853 assertErrors(source, []); 1853 await assertErrors(source, []);
1854 verify([source]); 1854 verify([source]);
1855 } 1855 }
1856 1856
1857 void test_nullAwareInCondition_assert() { 1857 test_nullAwareInCondition_assert() async {
1858 Source source = addSource(r''' 1858 Source source = addSource(r'''
1859 m(x) { 1859 m(x) {
1860 assert (x?.a); 1860 assert (x?.a);
1861 } 1861 }
1862 '''); 1862 ''');
1863 assertErrors(source, [HintCode.NULL_AWARE_IN_CONDITION]); 1863 await assertErrors(source, [HintCode.NULL_AWARE_IN_CONDITION]);
1864 verify([source]); 1864 verify([source]);
1865 } 1865 }
1866 1866
1867 void test_nullAwareInCondition_conditionalExpression() { 1867 test_nullAwareInCondition_conditionalExpression() async {
1868 Source source = addSource(r''' 1868 Source source = addSource(r'''
1869 m(x) { 1869 m(x) {
1870 return x?.a ? 0 : 1; 1870 return x?.a ? 0 : 1;
1871 } 1871 }
1872 '''); 1872 ''');
1873 assertErrors(source, [HintCode.NULL_AWARE_IN_CONDITION]); 1873 await assertErrors(source, [HintCode.NULL_AWARE_IN_CONDITION]);
1874 verify([source]); 1874 verify([source]);
1875 } 1875 }
1876 1876
1877 void test_nullAwareInCondition_do() { 1877 test_nullAwareInCondition_do() async {
1878 Source source = addSource(r''' 1878 Source source = addSource(r'''
1879 m(x) { 1879 m(x) {
1880 do {} while (x?.a); 1880 do {} while (x?.a);
1881 } 1881 }
1882 '''); 1882 ''');
1883 assertErrors(source, [HintCode.NULL_AWARE_IN_CONDITION]); 1883 await assertErrors(source, [HintCode.NULL_AWARE_IN_CONDITION]);
1884 verify([source]); 1884 verify([source]);
1885 } 1885 }
1886 1886
1887 void test_nullAwareInCondition_for() { 1887 test_nullAwareInCondition_for() async {
1888 Source source = addSource(r''' 1888 Source source = addSource(r'''
1889 m(x) { 1889 m(x) {
1890 for (var v = x; v?.a; v = v.next) {} 1890 for (var v = x; v?.a; v = v.next) {}
1891 } 1891 }
1892 '''); 1892 ''');
1893 assertErrors(source, [HintCode.NULL_AWARE_IN_CONDITION]); 1893 await assertErrors(source, [HintCode.NULL_AWARE_IN_CONDITION]);
1894 verify([source]); 1894 verify([source]);
1895 } 1895 }
1896 1896
1897 void test_nullAwareInCondition_if() { 1897 test_nullAwareInCondition_if() async {
1898 Source source = addSource(r''' 1898 Source source = addSource(r'''
1899 m(x) { 1899 m(x) {
1900 if (x?.a) {} 1900 if (x?.a) {}
1901 } 1901 }
1902 '''); 1902 ''');
1903 assertErrors(source, [HintCode.NULL_AWARE_IN_CONDITION]); 1903 await assertErrors(source, [HintCode.NULL_AWARE_IN_CONDITION]);
1904 verify([source]); 1904 verify([source]);
1905 } 1905 }
1906 1906
1907 void test_nullAwareInCondition_if_conditionalAnd_first() { 1907 test_nullAwareInCondition_if_conditionalAnd_first() async {
1908 Source source = addSource(r''' 1908 Source source = addSource(r'''
1909 m(x) { 1909 m(x) {
1910 if (x?.a && x.b) {} 1910 if (x?.a && x.b) {}
1911 } 1911 }
1912 '''); 1912 ''');
1913 assertErrors(source, [HintCode.NULL_AWARE_IN_CONDITION]); 1913 await assertErrors(source, [HintCode.NULL_AWARE_IN_CONDITION]);
1914 verify([source]); 1914 verify([source]);
1915 } 1915 }
1916 1916
1917 void test_nullAwareInCondition_if_conditionalAnd_second() { 1917 test_nullAwareInCondition_if_conditionalAnd_second() async {
1918 Source source = addSource(r''' 1918 Source source = addSource(r'''
1919 m(x) { 1919 m(x) {
1920 if (x.a && x?.b) {} 1920 if (x.a && x?.b) {}
1921 } 1921 }
1922 '''); 1922 ''');
1923 assertErrors(source, [HintCode.NULL_AWARE_IN_CONDITION]); 1923 await assertErrors(source, [HintCode.NULL_AWARE_IN_CONDITION]);
1924 verify([source]); 1924 verify([source]);
1925 } 1925 }
1926 1926
1927 void test_nullAwareInCondition_if_conditionalAnd_third() { 1927 test_nullAwareInCondition_if_conditionalAnd_third() async {
1928 Source source = addSource(r''' 1928 Source source = addSource(r'''
1929 m(x) { 1929 m(x) {
1930 if (x.a && x.b && x?.c) {} 1930 if (x.a && x.b && x?.c) {}
1931 } 1931 }
1932 '''); 1932 ''');
1933 assertErrors(source, [HintCode.NULL_AWARE_IN_CONDITION]); 1933 await assertErrors(source, [HintCode.NULL_AWARE_IN_CONDITION]);
1934 verify([source]); 1934 verify([source]);
1935 } 1935 }
1936 1936
1937 void test_nullAwareInCondition_if_conditionalOr_first() { 1937 test_nullAwareInCondition_if_conditionalOr_first() async {
1938 Source source = addSource(r''' 1938 Source source = addSource(r'''
1939 m(x) { 1939 m(x) {
1940 if (x?.a || x.b) {} 1940 if (x?.a || x.b) {}
1941 } 1941 }
1942 '''); 1942 ''');
1943 assertErrors(source, [HintCode.NULL_AWARE_IN_CONDITION]); 1943 await assertErrors(source, [HintCode.NULL_AWARE_IN_CONDITION]);
1944 verify([source]); 1944 verify([source]);
1945 } 1945 }
1946 1946
1947 void test_nullAwareInCondition_if_conditionalOr_second() { 1947 test_nullAwareInCondition_if_conditionalOr_second() async {
1948 Source source = addSource(r''' 1948 Source source = addSource(r'''
1949 m(x) { 1949 m(x) {
1950 if (x.a || x?.b) {} 1950 if (x.a || x?.b) {}
1951 } 1951 }
1952 '''); 1952 ''');
1953 assertErrors(source, [HintCode.NULL_AWARE_IN_CONDITION]); 1953 await assertErrors(source, [HintCode.NULL_AWARE_IN_CONDITION]);
1954 verify([source]); 1954 verify([source]);
1955 } 1955 }
1956 1956
1957 void test_nullAwareInCondition_if_conditionalOr_third() { 1957 test_nullAwareInCondition_if_conditionalOr_third() async {
1958 Source source = addSource(r''' 1958 Source source = addSource(r'''
1959 m(x) { 1959 m(x) {
1960 if (x.a || x.b || x?.c) {} 1960 if (x.a || x.b || x?.c) {}
1961 } 1961 }
1962 '''); 1962 ''');
1963 assertErrors(source, [HintCode.NULL_AWARE_IN_CONDITION]); 1963 await assertErrors(source, [HintCode.NULL_AWARE_IN_CONDITION]);
1964 verify([source]); 1964 verify([source]);
1965 } 1965 }
1966 1966
1967 void test_nullAwareInCondition_if_not() { 1967 test_nullAwareInCondition_if_not() async {
1968 Source source = addSource(r''' 1968 Source source = addSource(r'''
1969 m(x) { 1969 m(x) {
1970 if (!x?.a) {} 1970 if (!x?.a) {}
1971 } 1971 }
1972 '''); 1972 ''');
1973 assertErrors(source, [HintCode.NULL_AWARE_IN_CONDITION]); 1973 await assertErrors(source, [HintCode.NULL_AWARE_IN_CONDITION]);
1974 verify([source]); 1974 verify([source]);
1975 } 1975 }
1976 1976
1977 void test_nullAwareInCondition_if_parenthesized() { 1977 test_nullAwareInCondition_if_parenthesized() async {
1978 Source source = addSource(r''' 1978 Source source = addSource(r'''
1979 m(x) { 1979 m(x) {
1980 if ((x?.a)) {} 1980 if ((x?.a)) {}
1981 } 1981 }
1982 '''); 1982 ''');
1983 assertErrors(source, [HintCode.NULL_AWARE_IN_CONDITION]); 1983 await assertErrors(source, [HintCode.NULL_AWARE_IN_CONDITION]);
1984 verify([source]); 1984 verify([source]);
1985 } 1985 }
1986 1986
1987 void test_nullAwareInCondition_while() { 1987 test_nullAwareInCondition_while() async {
1988 Source source = addSource(r''' 1988 Source source = addSource(r'''
1989 m(x) { 1989 m(x) {
1990 while (x?.a) {} 1990 while (x?.a) {}
1991 } 1991 }
1992 '''); 1992 ''');
1993 assertErrors(source, [HintCode.NULL_AWARE_IN_CONDITION]); 1993 await assertErrors(source, [HintCode.NULL_AWARE_IN_CONDITION]);
1994 verify([source]); 1994 verify([source]);
1995 } 1995 }
1996 1996
1997 @failingTest 1997 @failingTest
1998 void test_overrideEqualsButNotHashCode() { 1998 test_overrideEqualsButNotHashCode() async {
1999 Source source = addSource(r''' 1999 Source source = addSource(r'''
2000 class A { 2000 class A {
2001 bool operator ==(x) {} 2001 bool operator ==(x) {}
2002 }'''); 2002 }''');
2003 assertErrors(source, [HintCode.OVERRIDE_EQUALS_BUT_NOT_HASH_CODE]); 2003 await assertErrors(source, [HintCode.OVERRIDE_EQUALS_BUT_NOT_HASH_CODE]);
2004 verify([source]); 2004 verify([source]);
2005 } 2005 }
2006 2006
2007 void test_overrideOnNonOverridingField_invalid() { 2007 test_overrideOnNonOverridingField_invalid() async {
2008 Source source = addSource(r''' 2008 Source source = addSource(r'''
2009 class A { 2009 class A {
2010 } 2010 }
2011 class B extends A { 2011 class B extends A {
2012 @override 2012 @override
2013 final int m = 1; 2013 final int m = 1;
2014 }'''); 2014 }''');
2015 assertErrors(source, [HintCode.OVERRIDE_ON_NON_OVERRIDING_FIELD]); 2015 await assertErrors(source, [HintCode.OVERRIDE_ON_NON_OVERRIDING_FIELD]);
2016 verify([source]); 2016 verify([source]);
2017 } 2017 }
2018 2018
2019 void test_overrideOnNonOverridingGetter_invalid() { 2019 test_overrideOnNonOverridingGetter_invalid() async {
2020 Source source = addSource(r''' 2020 Source source = addSource(r'''
2021 class A { 2021 class A {
2022 } 2022 }
2023 class B extends A { 2023 class B extends A {
2024 @override 2024 @override
2025 int get m => 1; 2025 int get m => 1;
2026 }'''); 2026 }''');
2027 assertErrors(source, [HintCode.OVERRIDE_ON_NON_OVERRIDING_GETTER]); 2027 await assertErrors(source, [HintCode.OVERRIDE_ON_NON_OVERRIDING_GETTER]);
2028 verify([source]); 2028 verify([source]);
2029 } 2029 }
2030 2030
2031 void test_overrideOnNonOverridingMethod_invalid() { 2031 test_overrideOnNonOverridingMethod_invalid() async {
2032 Source source = addSource(r''' 2032 Source source = addSource(r'''
2033 class A { 2033 class A {
2034 } 2034 }
2035 class B extends A { 2035 class B extends A {
2036 @override 2036 @override
2037 int m() => 1; 2037 int m() => 1;
2038 }'''); 2038 }''');
2039 assertErrors(source, [HintCode.OVERRIDE_ON_NON_OVERRIDING_METHOD]); 2039 await assertErrors(source, [HintCode.OVERRIDE_ON_NON_OVERRIDING_METHOD]);
2040 verify([source]); 2040 verify([source]);
2041 } 2041 }
2042 2042
2043 void test_overrideOnNonOverridingSetter_invalid() { 2043 test_overrideOnNonOverridingSetter_invalid() async {
2044 Source source = addSource(r''' 2044 Source source = addSource(r'''
2045 class A { 2045 class A {
2046 } 2046 }
2047 class B extends A { 2047 class B extends A {
2048 @override 2048 @override
2049 set m(int x) {} 2049 set m(int x) {}
2050 }'''); 2050 }''');
2051 assertErrors(source, [HintCode.OVERRIDE_ON_NON_OVERRIDING_SETTER]); 2051 await assertErrors(source, [HintCode.OVERRIDE_ON_NON_OVERRIDING_SETTER]);
2052 verify([source]); 2052 verify([source]);
2053 } 2053 }
2054 2054
2055 void test_required_constructor_param() { 2055 test_required_constructor_param() async {
2056 Source source = addSource(r''' 2056 Source source = addSource(r'''
2057 import 'package:meta/meta.dart'; 2057 import 'package:meta/meta.dart';
2058 2058
2059 class C { 2059 class C {
2060 C({@Required('must specify an `a`') int a}) {} 2060 C({@Required('must specify an `a`') int a}) {}
2061 } 2061 }
2062 2062
2063 main() { 2063 main() {
2064 new C(); 2064 new C();
2065 } 2065 }
2066 '''); 2066 ''');
2067 assertErrors(source, [HintCode.MISSING_REQUIRED_PARAM_WITH_DETAILS]); 2067 await assertErrors(source, [HintCode.MISSING_REQUIRED_PARAM_WITH_DETAILS]);
2068 verify([source]); 2068 verify([source]);
2069 } 2069 }
2070 2070
2071 void test_required_constructor_param_no_reason() { 2071 test_required_constructor_param_no_reason() async {
2072 Source source = addSource(r''' 2072 Source source = addSource(r'''
2073 import 'package:meta/meta.dart'; 2073 import 'package:meta/meta.dart';
2074 2074
2075 class C { 2075 class C {
2076 C({@required int a}) {} 2076 C({@required int a}) {}
2077 } 2077 }
2078 2078
2079 main() { 2079 main() {
2080 new C(); 2080 new C();
2081 } 2081 }
2082 '''); 2082 ''');
2083 assertErrors(source, [HintCode.MISSING_REQUIRED_PARAM]); 2083 await assertErrors(source, [HintCode.MISSING_REQUIRED_PARAM]);
2084 verify([source]); 2084 verify([source]);
2085 } 2085 }
2086 2086
2087 void test_required_constructor_param_null_reason() { 2087 test_required_constructor_param_null_reason() async {
2088 Source source = addSource(r''' 2088 Source source = addSource(r'''
2089 import 'package:meta/meta.dart'; 2089 import 'package:meta/meta.dart';
2090 2090
2091 class C { 2091 class C {
2092 C({@Required(null) int a}) {} 2092 C({@Required(null) int a}) {}
2093 } 2093 }
2094 2094
2095 main() { 2095 main() {
2096 new C(); 2096 new C();
2097 } 2097 }
2098 '''); 2098 ''');
2099 assertErrors(source, [HintCode.MISSING_REQUIRED_PARAM]); 2099 await assertErrors(source, [HintCode.MISSING_REQUIRED_PARAM]);
2100 verify([source]); 2100 verify([source]);
2101 } 2101 }
2102 2102
2103 void test_required_constructor_param_OK() { 2103 test_required_constructor_param_OK() async {
2104 Source source = addSource(r''' 2104 Source source = addSource(r'''
2105 import 'package:meta/meta.dart'; 2105 import 'package:meta/meta.dart';
2106 2106
2107 class C { 2107 class C {
2108 C({@required int a}) {} 2108 C({@required int a}) {}
2109 } 2109 }
2110 2110
2111 main() { 2111 main() {
2112 new C(a: 2); 2112 new C(a: 2);
2113 } 2113 }
2114 '''); 2114 ''');
2115 assertNoErrors(source); 2115 await assertNoErrors(source);
2116 verify([source]); 2116 verify([source]);
2117 } 2117 }
2118 2118
2119 void test_required_constructor_param_redirecting_cons_call() { 2119 test_required_constructor_param_redirecting_cons_call() async {
2120 Source source = addSource(r''' 2120 Source source = addSource(r'''
2121 import 'package:meta/meta.dart'; 2121 import 'package:meta/meta.dart';
2122 2122
2123 class C { 2123 class C {
2124 C({@required int x}); 2124 C({@required int x});
2125 C.named() : this(); 2125 C.named() : this();
2126 } 2126 }
2127 '''); 2127 ''');
2128 assertErrors(source, [HintCode.MISSING_REQUIRED_PARAM]); 2128 await assertErrors(source, [HintCode.MISSING_REQUIRED_PARAM]);
2129 verify([source]); 2129 verify([source]);
2130 } 2130 }
2131 2131
2132 void test_required_constructor_param_super_call() { 2132 test_required_constructor_param_super_call() async {
2133 Source source = addSource(r''' 2133 Source source = addSource(r'''
2134 import 'package:meta/meta.dart'; 2134 import 'package:meta/meta.dart';
2135 2135
2136 class C { 2136 class C {
2137 C({@Required('must specify an `a`') int a}) {} 2137 C({@Required('must specify an `a`') int a}) {}
2138 } 2138 }
2139 2139
2140 class D extends C { 2140 class D extends C {
2141 D() : super(); 2141 D() : super();
2142 } 2142 }
2143 '''); 2143 ''');
2144 assertErrors(source, [HintCode.MISSING_REQUIRED_PARAM_WITH_DETAILS]); 2144 await assertErrors(source, [HintCode.MISSING_REQUIRED_PARAM_WITH_DETAILS]);
2145 verify([source]); 2145 verify([source]);
2146 } 2146 }
2147 2147
2148 void test_required_function_param() { 2148 test_required_function_param() async {
2149 Source source = addSource(r''' 2149 Source source = addSource(r'''
2150 import 'package:meta/meta.dart'; 2150 import 'package:meta/meta.dart';
2151 2151
2152 void f({@Required('must specify an `a`') int a}) {} 2152 void f({@Required('must specify an `a`') int a}) {}
2153 2153
2154 main() { 2154 main() {
2155 f(); 2155 f();
2156 } 2156 }
2157 '''); 2157 ''');
2158 assertErrors(source, [HintCode.MISSING_REQUIRED_PARAM_WITH_DETAILS]); 2158 await assertErrors(source, [HintCode.MISSING_REQUIRED_PARAM_WITH_DETAILS]);
2159 verify([source]); 2159 verify([source]);
2160 } 2160 }
2161 2161
2162 void test_required_method_param() { 2162 test_required_method_param() async {
2163 Source source = addSource(r''' 2163 Source source = addSource(r'''
2164 import 'package:meta/meta.dart'; 2164 import 'package:meta/meta.dart';
2165 class A { 2165 class A {
2166 void m({@Required('must specify an `a`') int a}) {} 2166 void m({@Required('must specify an `a`') int a}) {}
2167 } 2167 }
2168 f() { 2168 f() {
2169 new A().m(); 2169 new A().m();
2170 } 2170 }
2171 '''); 2171 ''');
2172 assertErrors(source, [HintCode.MISSING_REQUIRED_PARAM_WITH_DETAILS]); 2172 await assertErrors(source, [HintCode.MISSING_REQUIRED_PARAM_WITH_DETAILS]);
2173 verify([source]); 2173 verify([source]);
2174 } 2174 }
2175 2175
2176 void test_required_method_param_in_other_lib() { 2176 test_required_method_param_in_other_lib() async {
2177 addNamedSource( 2177 addNamedSource(
2178 '/a_lib.dart', 2178 '/a_lib.dart',
2179 r''' 2179 r'''
2180 library a_lib; 2180 library a_lib;
2181 import 'package:meta/meta.dart'; 2181 import 'package:meta/meta.dart';
2182 class A { 2182 class A {
2183 void m({@Required('must specify an `a`') int a}) {} 2183 void m({@Required('must specify an `a`') int a}) {}
2184 } 2184 }
2185 '''); 2185 ''');
2186 2186
2187 Source source = addSource(r''' 2187 Source source = addSource(r'''
2188 import "a_lib.dart"; 2188 import "a_lib.dart";
2189 f() { 2189 f() {
2190 new A().m(); 2190 new A().m();
2191 } 2191 }
2192 '''); 2192 ''');
2193 2193
2194 assertErrors(source, [HintCode.MISSING_REQUIRED_PARAM_WITH_DETAILS]); 2194 await assertErrors(source, [HintCode.MISSING_REQUIRED_PARAM_WITH_DETAILS]);
2195 verify([source]); 2195 verify([source]);
2196 } 2196 }
2197 2197
2198 void test_required_typedef_function_param() { 2198 test_required_typedef_function_param() async {
2199 Source source = addSource(r''' 2199 Source source = addSource(r'''
2200 import 'package:meta/meta.dart'; 2200 import 'package:meta/meta.dart';
2201 2201
2202 String test(C c) => c.m()(); 2202 String test(C c) => c.m()();
2203 2203
2204 typedef String F({@required String x}); 2204 typedef String F({@required String x});
2205 2205
2206 class C { 2206 class C {
2207 F m() => ({@required String x}) => null; 2207 F m() => ({@required String x}) => null;
2208 } 2208 }
2209 '''); 2209 ''');
2210 assertErrors(source, [HintCode.MISSING_REQUIRED_PARAM]); 2210 await assertErrors(source, [HintCode.MISSING_REQUIRED_PARAM]);
2211 verify([source]); 2211 verify([source]);
2212 } 2212 }
2213 2213
2214 void test_typeCheck_type_is_Null() { 2214 test_typeCheck_type_is_Null() async {
2215 Source source = addSource(r''' 2215 Source source = addSource(r'''
2216 m(i) { 2216 m(i) {
2217 bool b = i is Null; 2217 bool b = i is Null;
2218 }'''); 2218 }''');
2219 assertErrors(source, [HintCode.TYPE_CHECK_IS_NULL]); 2219 await assertErrors(source, [HintCode.TYPE_CHECK_IS_NULL]);
2220 verify([source]); 2220 verify([source]);
2221 } 2221 }
2222 2222
2223 void test_typeCheck_type_not_Null() { 2223 test_typeCheck_type_not_Null() async {
2224 Source source = addSource(r''' 2224 Source source = addSource(r'''
2225 m(i) { 2225 m(i) {
2226 bool b = i is! Null; 2226 bool b = i is! Null;
2227 }'''); 2227 }''');
2228 assertErrors(source, [HintCode.TYPE_CHECK_IS_NOT_NULL]); 2228 await assertErrors(source, [HintCode.TYPE_CHECK_IS_NOT_NULL]);
2229 verify([source]); 2229 verify([source]);
2230 } 2230 }
2231 2231
2232 void test_undefinedGetter() { 2232 test_undefinedGetter() async {
2233 Source source = addSource(r''' 2233 Source source = addSource(r'''
2234 class A {} 2234 class A {}
2235 f(var a) { 2235 f(var a) {
2236 if(a is A) { 2236 if(a is A) {
2237 return a.m; 2237 return a.m;
2238 } 2238 }
2239 }'''); 2239 }''');
2240 assertErrors(source, [HintCode.UNDEFINED_GETTER]); 2240 await assertErrors(source, [HintCode.UNDEFINED_GETTER]);
2241 } 2241 }
2242 2242
2243 void test_undefinedGetter_message() { 2243 test_undefinedGetter_message() async {
2244 // The implementation of HintCode.UNDEFINED_SETTER assumes that 2244 // The implementation of HintCode.UNDEFINED_SETTER assumes that
2245 // UNDEFINED_SETTER in StaticTypeWarningCode and StaticWarningCode are the 2245 // UNDEFINED_SETTER in StaticTypeWarningCode and StaticWarningCode are the
2246 // same, this verifies that assumption. 2246 // same, this verifies that assumption.
2247 expect(StaticWarningCode.UNDEFINED_GETTER.message, 2247 expect(StaticWarningCode.UNDEFINED_GETTER.message,
2248 StaticTypeWarningCode.UNDEFINED_GETTER.message); 2248 StaticTypeWarningCode.UNDEFINED_GETTER.message);
2249 } 2249 }
2250 2250
2251 void test_undefinedIdentifier_exportHide() { 2251 test_undefinedIdentifier_exportHide() async {
2252 Source source = addSource(r''' 2252 Source source = addSource(r'''
2253 library L; 2253 library L;
2254 export 'lib1.dart' hide a;'''); 2254 export 'lib1.dart' hide a;''');
2255 addNamedSource("/lib1.dart", "library lib1;"); 2255 addNamedSource("/lib1.dart", "library lib1;");
2256 assertErrors(source, [HintCode.UNDEFINED_HIDDEN_NAME]); 2256 await assertErrors(source, [HintCode.UNDEFINED_HIDDEN_NAME]);
2257 verify([source]); 2257 verify([source]);
2258 } 2258 }
2259 2259
2260 void test_undefinedIdentifier_exportShow() { 2260 test_undefinedIdentifier_exportShow() async {
2261 Source source = addSource(r''' 2261 Source source = addSource(r'''
2262 library L; 2262 library L;
2263 export 'lib1.dart' show a;'''); 2263 export 'lib1.dart' show a;''');
2264 addNamedSource("/lib1.dart", "library lib1;"); 2264 addNamedSource("/lib1.dart", "library lib1;");
2265 assertErrors(source, [HintCode.UNDEFINED_SHOWN_NAME]); 2265 await assertErrors(source, [HintCode.UNDEFINED_SHOWN_NAME]);
2266 verify([source]); 2266 verify([source]);
2267 } 2267 }
2268 2268
2269 void test_undefinedIdentifier_importHide() { 2269 test_undefinedIdentifier_importHide() async {
2270 Source source = addSource(r''' 2270 Source source = addSource(r'''
2271 library L; 2271 library L;
2272 import 'lib1.dart' hide a;'''); 2272 import 'lib1.dart' hide a;''');
2273 addNamedSource("/lib1.dart", "library lib1;"); 2273 addNamedSource("/lib1.dart", "library lib1;");
2274 assertErrors( 2274 await assertErrors(
2275 source, [HintCode.UNUSED_IMPORT, HintCode.UNDEFINED_HIDDEN_NAME]); 2275 source, [HintCode.UNUSED_IMPORT, HintCode.UNDEFINED_HIDDEN_NAME]);
2276 verify([source]); 2276 verify([source]);
2277 } 2277 }
2278 2278
2279 void test_undefinedIdentifier_importShow() { 2279 test_undefinedIdentifier_importShow() async {
2280 Source source = addSource(r''' 2280 Source source = addSource(r'''
2281 library L; 2281 library L;
2282 import 'lib1.dart' show a;'''); 2282 import 'lib1.dart' show a;''');
2283 addNamedSource("/lib1.dart", "library lib1;"); 2283 addNamedSource("/lib1.dart", "library lib1;");
2284 assertErrors( 2284 await assertErrors(
2285 source, [HintCode.UNUSED_IMPORT, HintCode.UNDEFINED_SHOWN_NAME]); 2285 source, [HintCode.UNUSED_IMPORT, HintCode.UNDEFINED_SHOWN_NAME]);
2286 verify([source]); 2286 verify([source]);
2287 } 2287 }
2288 2288
2289 void test_undefinedMethod() { 2289 test_undefinedMethod() async {
2290 Source source = addSource(r''' 2290 Source source = addSource(r'''
2291 f() { 2291 f() {
2292 var a = 'str'; 2292 var a = 'str';
2293 a.notAMethodOnString(); 2293 a.notAMethodOnString();
2294 }'''); 2294 }''');
2295 assertErrors(source, [HintCode.UNDEFINED_METHOD]); 2295 await assertErrors(source, [HintCode.UNDEFINED_METHOD]);
2296 } 2296 }
2297 2297
2298 void test_undefinedMethod_assignmentExpression() { 2298 test_undefinedMethod_assignmentExpression() async {
2299 Source source = addSource(r''' 2299 Source source = addSource(r'''
2300 class A {} 2300 class A {}
2301 class B { 2301 class B {
2302 f(var a, var a2) { 2302 f(var a, var a2) {
2303 a = new A(); 2303 a = new A();
2304 a2 = new A(); 2304 a2 = new A();
2305 a += a2; 2305 a += a2;
2306 } 2306 }
2307 }'''); 2307 }''');
2308 assertErrors(source, [HintCode.UNDEFINED_METHOD]); 2308 await assertErrors(source, [HintCode.UNDEFINED_METHOD]);
2309 } 2309 }
2310 2310
2311 void test_undefinedOperator_binaryExpression() { 2311 test_undefinedOperator_binaryExpression() async {
2312 Source source = addSource(r''' 2312 Source source = addSource(r'''
2313 class A {} 2313 class A {}
2314 f(var a) { 2314 f(var a) {
2315 if(a is A) { 2315 if(a is A) {
2316 a + 1; 2316 a + 1;
2317 } 2317 }
2318 }'''); 2318 }''');
2319 assertErrors(source, [HintCode.UNDEFINED_OPERATOR]); 2319 await assertErrors(source, [HintCode.UNDEFINED_OPERATOR]);
2320 } 2320 }
2321 2321
2322 void test_undefinedOperator_indexBoth() { 2322 test_undefinedOperator_indexBoth() async {
2323 Source source = addSource(r''' 2323 Source source = addSource(r'''
2324 class A {} 2324 class A {}
2325 f(var a) { 2325 f(var a) {
2326 if(a is A) { 2326 if(a is A) {
2327 a[0]++; 2327 a[0]++;
2328 } 2328 }
2329 }'''); 2329 }''');
2330 assertErrors(source, [HintCode.UNDEFINED_OPERATOR]); 2330 await assertErrors(source, [HintCode.UNDEFINED_OPERATOR]);
2331 } 2331 }
2332 2332
2333 void test_undefinedOperator_indexGetter() { 2333 test_undefinedOperator_indexGetter() async {
2334 Source source = addSource(r''' 2334 Source source = addSource(r'''
2335 class A {} 2335 class A {}
2336 f(var a) { 2336 f(var a) {
2337 if(a is A) { 2337 if(a is A) {
2338 a[0]; 2338 a[0];
2339 } 2339 }
2340 }'''); 2340 }''');
2341 assertErrors(source, [HintCode.UNDEFINED_OPERATOR]); 2341 await assertErrors(source, [HintCode.UNDEFINED_OPERATOR]);
2342 } 2342 }
2343 2343
2344 void test_undefinedOperator_indexSetter() { 2344 test_undefinedOperator_indexSetter() async {
2345 Source source = addSource(r''' 2345 Source source = addSource(r'''
2346 class A {} 2346 class A {}
2347 f(var a) { 2347 f(var a) {
2348 if(a is A) { 2348 if(a is A) {
2349 a[0] = 1; 2349 a[0] = 1;
2350 } 2350 }
2351 }'''); 2351 }''');
2352 assertErrors(source, [HintCode.UNDEFINED_OPERATOR]); 2352 await assertErrors(source, [HintCode.UNDEFINED_OPERATOR]);
2353 } 2353 }
2354 2354
2355 void test_undefinedOperator_postfixExpression() { 2355 test_undefinedOperator_postfixExpression() async {
2356 Source source = addSource(r''' 2356 Source source = addSource(r'''
2357 class A {} 2357 class A {}
2358 f(var a) { 2358 f(var a) {
2359 if(a is A) { 2359 if(a is A) {
2360 a++; 2360 a++;
2361 } 2361 }
2362 }'''); 2362 }''');
2363 assertErrors(source, [HintCode.UNDEFINED_OPERATOR]); 2363 await assertErrors(source, [HintCode.UNDEFINED_OPERATOR]);
2364 } 2364 }
2365 2365
2366 void test_undefinedOperator_prefixExpression() { 2366 test_undefinedOperator_prefixExpression() async {
2367 Source source = addSource(r''' 2367 Source source = addSource(r'''
2368 class A {} 2368 class A {}
2369 f(var a) { 2369 f(var a) {
2370 if(a is A) { 2370 if(a is A) {
2371 ++a; 2371 ++a;
2372 } 2372 }
2373 }'''); 2373 }''');
2374 assertErrors(source, [HintCode.UNDEFINED_OPERATOR]); 2374 await assertErrors(source, [HintCode.UNDEFINED_OPERATOR]);
2375 } 2375 }
2376 2376
2377 void test_undefinedSetter() { 2377 test_undefinedSetter() async {
2378 Source source = addSource(r''' 2378 Source source = addSource(r'''
2379 class A {} 2379 class A {}
2380 f(var a) { 2380 f(var a) {
2381 if(a is A) { 2381 if(a is A) {
2382 a.m = 0; 2382 a.m = 0;
2383 } 2383 }
2384 }'''); 2384 }''');
2385 assertErrors(source, [HintCode.UNDEFINED_SETTER]); 2385 await assertErrors(source, [HintCode.UNDEFINED_SETTER]);
2386 } 2386 }
2387 2387
2388 void test_undefinedSetter_message() { 2388 test_undefinedSetter_message() async {
2389 // The implementation of HintCode.UNDEFINED_SETTER assumes that 2389 // The implementation of HintCode.UNDEFINED_SETTER assumes that
2390 // UNDEFINED_SETTER in StaticTypeWarningCode and StaticWarningCode are the 2390 // UNDEFINED_SETTER in StaticTypeWarningCode and StaticWarningCode are the
2391 // same, this verifies that assumption. 2391 // same, this verifies that assumption.
2392 expect(StaticWarningCode.UNDEFINED_SETTER.message, 2392 expect(StaticWarningCode.UNDEFINED_SETTER.message,
2393 StaticTypeWarningCode.UNDEFINED_SETTER.message); 2393 StaticTypeWarningCode.UNDEFINED_SETTER.message);
2394 } 2394 }
2395 2395
2396 void test_unnecessaryCast_type_supertype() { 2396 test_unnecessaryCast_type_supertype() async {
2397 Source source = addSource(r''' 2397 Source source = addSource(r'''
2398 m(int i) { 2398 m(int i) {
2399 var b = i as Object; 2399 var b = i as Object;
2400 }'''); 2400 }''');
2401 assertErrors(source, [HintCode.UNNECESSARY_CAST]); 2401 await assertErrors(source, [HintCode.UNNECESSARY_CAST]);
2402 verify([source]); 2402 verify([source]);
2403 } 2403 }
2404 2404
2405 void test_unnecessaryCast_type_type() { 2405 test_unnecessaryCast_type_type() async {
2406 Source source = addSource(r''' 2406 Source source = addSource(r'''
2407 m(num i) { 2407 m(num i) {
2408 var b = i as num; 2408 var b = i as num;
2409 }'''); 2409 }''');
2410 assertErrors(source, [HintCode.UNNECESSARY_CAST]); 2410 await assertErrors(source, [HintCode.UNNECESSARY_CAST]);
2411 verify([source]); 2411 verify([source]);
2412 } 2412 }
2413 2413
2414 void test_unnecessaryNoSuchMethod_blockBody() { 2414 test_unnecessaryNoSuchMethod_blockBody() async {
2415 Source source = addSource(r''' 2415 Source source = addSource(r'''
2416 class A { 2416 class A {
2417 noSuchMethod(x) => super.noSuchMethod(x); 2417 noSuchMethod(x) => super.noSuchMethod(x);
2418 } 2418 }
2419 class B extends A { 2419 class B extends A {
2420 mmm(); 2420 mmm();
2421 noSuchMethod(y) { 2421 noSuchMethod(y) {
2422 return super.noSuchMethod(y); 2422 return super.noSuchMethod(y);
2423 } 2423 }
2424 }'''); 2424 }''');
2425 assertErrors(source, [HintCode.UNNECESSARY_NO_SUCH_METHOD]); 2425 await assertErrors(source, [HintCode.UNNECESSARY_NO_SUCH_METHOD]);
2426 verify([source]); 2426 verify([source]);
2427 } 2427 }
2428 2428
2429 void test_unnecessaryNoSuchMethod_expressionBody() { 2429 test_unnecessaryNoSuchMethod_expressionBody() async {
2430 Source source = addSource(r''' 2430 Source source = addSource(r'''
2431 class A { 2431 class A {
2432 noSuchMethod(x) => super.noSuchMethod(x); 2432 noSuchMethod(x) => super.noSuchMethod(x);
2433 } 2433 }
2434 class B extends A { 2434 class B extends A {
2435 mmm(); 2435 mmm();
2436 noSuchMethod(y) => super.noSuchMethod(y); 2436 noSuchMethod(y) => super.noSuchMethod(y);
2437 }'''); 2437 }''');
2438 assertErrors(source, [HintCode.UNNECESSARY_NO_SUCH_METHOD]); 2438 await assertErrors(source, [HintCode.UNNECESSARY_NO_SUCH_METHOD]);
2439 verify([source]); 2439 verify([source]);
2440 } 2440 }
2441 2441
2442 void test_unnecessaryTypeCheck_null_is_Null() { 2442 test_unnecessaryTypeCheck_null_is_Null() async {
2443 Source source = addSource("bool b = null is Null;"); 2443 Source source = addSource("bool b = null is Null;");
2444 assertErrors(source, [HintCode.UNNECESSARY_TYPE_CHECK_TRUE]); 2444 await assertErrors(source, [HintCode.UNNECESSARY_TYPE_CHECK_TRUE]);
2445 verify([source]); 2445 verify([source]);
2446 } 2446 }
2447 2447
2448 void test_unnecessaryTypeCheck_null_not_Null() { 2448 test_unnecessaryTypeCheck_null_not_Null() async {
2449 Source source = addSource("bool b = null is! Null;"); 2449 Source source = addSource("bool b = null is! Null;");
2450 assertErrors(source, [HintCode.UNNECESSARY_TYPE_CHECK_FALSE]); 2450 await assertErrors(source, [HintCode.UNNECESSARY_TYPE_CHECK_FALSE]);
2451 verify([source]); 2451 verify([source]);
2452 } 2452 }
2453 2453
2454 void test_unnecessaryTypeCheck_type_is_dynamic() { 2454 test_unnecessaryTypeCheck_type_is_dynamic() async {
2455 Source source = addSource(r''' 2455 Source source = addSource(r'''
2456 m(i) { 2456 m(i) {
2457 bool b = i is dynamic; 2457 bool b = i is dynamic;
2458 }'''); 2458 }''');
2459 assertErrors(source, [HintCode.UNNECESSARY_TYPE_CHECK_TRUE]); 2459 await assertErrors(source, [HintCode.UNNECESSARY_TYPE_CHECK_TRUE]);
2460 verify([source]); 2460 verify([source]);
2461 } 2461 }
2462 2462
2463 void test_unnecessaryTypeCheck_type_is_object() { 2463 test_unnecessaryTypeCheck_type_is_object() async {
2464 Source source = addSource(r''' 2464 Source source = addSource(r'''
2465 m(i) { 2465 m(i) {
2466 bool b = i is Object; 2466 bool b = i is Object;
2467 }'''); 2467 }''');
2468 assertErrors(source, [HintCode.UNNECESSARY_TYPE_CHECK_TRUE]); 2468 await assertErrors(source, [HintCode.UNNECESSARY_TYPE_CHECK_TRUE]);
2469 verify([source]); 2469 verify([source]);
2470 } 2470 }
2471 2471
2472 void test_unnecessaryTypeCheck_type_not_dynamic() { 2472 test_unnecessaryTypeCheck_type_not_dynamic() async {
2473 Source source = addSource(r''' 2473 Source source = addSource(r'''
2474 m(i) { 2474 m(i) {
2475 bool b = i is! dynamic; 2475 bool b = i is! dynamic;
2476 }'''); 2476 }''');
2477 assertErrors(source, [HintCode.UNNECESSARY_TYPE_CHECK_FALSE]); 2477 await assertErrors(source, [HintCode.UNNECESSARY_TYPE_CHECK_FALSE]);
2478 verify([source]); 2478 verify([source]);
2479 } 2479 }
2480 2480
2481 void test_unnecessaryTypeCheck_type_not_object() { 2481 test_unnecessaryTypeCheck_type_not_object() async {
2482 Source source = addSource(r''' 2482 Source source = addSource(r'''
2483 m(i) { 2483 m(i) {
2484 bool b = i is! Object; 2484 bool b = i is! Object;
2485 }'''); 2485 }''');
2486 assertErrors(source, [HintCode.UNNECESSARY_TYPE_CHECK_FALSE]); 2486 await assertErrors(source, [HintCode.UNNECESSARY_TYPE_CHECK_FALSE]);
2487 verify([source]); 2487 verify([source]);
2488 } 2488 }
2489 2489
2490 void test_unusedElement_class_isUsed_extends() { 2490 test_unusedElement_class_isUsed_extends() async {
2491 enableUnusedElement = true; 2491 enableUnusedElement = true;
2492 Source source = addSource(r''' 2492 Source source = addSource(r'''
2493 class _A {} 2493 class _A {}
2494 class B extends _A {} 2494 class B extends _A {}
2495 '''); 2495 ''');
2496 assertNoErrors(source); 2496 await assertNoErrors(source);
2497 verify([source]); 2497 verify([source]);
2498 } 2498 }
2499 2499
2500 void test_unusedElement_class_isUsed_fieldDeclaration() { 2500 test_unusedElement_class_isUsed_fieldDeclaration() async {
2501 enableUnusedElement = true; 2501 enableUnusedElement = true;
2502 var src = r''' 2502 var src = r'''
2503 class Foo { 2503 class Foo {
2504 _Bar x; 2504 _Bar x;
2505 } 2505 }
2506 2506
2507 class _Bar { 2507 class _Bar {
2508 } 2508 }
2509 '''; 2509 ''';
2510 Source source = addSource(src); 2510 Source source = addSource(src);
2511 assertNoErrors(source); 2511 await assertNoErrors(source);
2512 verify([source]); 2512 verify([source]);
2513 } 2513 }
2514 2514
2515 void test_unusedElement_class_isUsed_implements() { 2515 test_unusedElement_class_isUsed_implements() async {
2516 enableUnusedElement = true; 2516 enableUnusedElement = true;
2517 Source source = addSource(r''' 2517 Source source = addSource(r'''
2518 class _A {} 2518 class _A {}
2519 class B implements _A {} 2519 class B implements _A {}
2520 '''); 2520 ''');
2521 assertNoErrors(source); 2521 await assertNoErrors(source);
2522 verify([source]); 2522 verify([source]);
2523 } 2523 }
2524 2524
2525 void test_unusedElement_class_isUsed_instanceCreation() { 2525 test_unusedElement_class_isUsed_instanceCreation() async {
2526 enableUnusedElement = true; 2526 enableUnusedElement = true;
2527 Source source = addSource(r''' 2527 Source source = addSource(r'''
2528 class _A {} 2528 class _A {}
2529 main() { 2529 main() {
2530 new _A(); 2530 new _A();
2531 }'''); 2531 }''');
2532 assertNoErrors(source); 2532 await assertNoErrors(source);
2533 verify([source]); 2533 verify([source]);
2534 } 2534 }
2535 2535
2536 void test_unusedElement_class_isUsed_staticFieldAccess() { 2536 test_unusedElement_class_isUsed_staticFieldAccess() async {
2537 enableUnusedElement = true; 2537 enableUnusedElement = true;
2538 Source source = addSource(r''' 2538 Source source = addSource(r'''
2539 class _A { 2539 class _A {
2540 static const F = 42; 2540 static const F = 42;
2541 } 2541 }
2542 main() { 2542 main() {
2543 _A.F; 2543 _A.F;
2544 }'''); 2544 }''');
2545 assertNoErrors(source); 2545 await assertNoErrors(source);
2546 verify([source]); 2546 verify([source]);
2547 } 2547 }
2548 2548
2549 void test_unusedElement_class_isUsed_staticMethodInvocation() { 2549 test_unusedElement_class_isUsed_staticMethodInvocation() async {
2550 enableUnusedElement = true; 2550 enableUnusedElement = true;
2551 Source source = addSource(r''' 2551 Source source = addSource(r'''
2552 class _A { 2552 class _A {
2553 static m() {} 2553 static m() {}
2554 } 2554 }
2555 main() { 2555 main() {
2556 _A.m(); 2556 _A.m();
2557 }'''); 2557 }''');
2558 assertNoErrors(source); 2558 await assertNoErrors(source);
2559 verify([source]); 2559 verify([source]);
2560 } 2560 }
2561 2561
2562 void test_unusedElement_class_isUsed_typeArgument() { 2562 test_unusedElement_class_isUsed_typeArgument() async {
2563 enableUnusedElement = true; 2563 enableUnusedElement = true;
2564 Source source = addSource(r''' 2564 Source source = addSource(r'''
2565 class _A {} 2565 class _A {}
2566 main() { 2566 main() {
2567 var v = new List<_A>(); 2567 var v = new List<_A>();
2568 print(v); 2568 print(v);
2569 }'''); 2569 }''');
2570 assertNoErrors(source); 2570 await assertNoErrors(source);
2571 verify([source]); 2571 verify([source]);
2572 } 2572 }
2573 2573
2574 void test_unusedElement_class_notUsed_inClassMember() { 2574 test_unusedElement_class_notUsed_inClassMember() async {
2575 enableUnusedElement = true; 2575 enableUnusedElement = true;
2576 Source source = addSource(r''' 2576 Source source = addSource(r'''
2577 class _A { 2577 class _A {
2578 static staticMethod() { 2578 static staticMethod() {
2579 new _A(); 2579 new _A();
2580 } 2580 }
2581 instanceMethod() { 2581 instanceMethod() {
2582 new _A(); 2582 new _A();
2583 } 2583 }
2584 } 2584 }
2585 '''); 2585 ''');
2586 assertErrors(source, [HintCode.UNUSED_ELEMENT]); 2586 await assertErrors(source, [HintCode.UNUSED_ELEMENT]);
2587 verify([source]); 2587 verify([source]);
2588 } 2588 }
2589 2589
2590 void test_unusedElement_class_notUsed_inConstructorName() { 2590 test_unusedElement_class_notUsed_inConstructorName() async {
2591 enableUnusedElement = true; 2591 enableUnusedElement = true;
2592 Source source = addSource(r''' 2592 Source source = addSource(r'''
2593 class _A { 2593 class _A {
2594 _A() {} 2594 _A() {}
2595 _A.named() {} 2595 _A.named() {}
2596 } 2596 }
2597 '''); 2597 ''');
2598 assertErrors(source, [HintCode.UNUSED_ELEMENT]); 2598 await assertErrors(source, [HintCode.UNUSED_ELEMENT]);
2599 verify([source]); 2599 verify([source]);
2600 } 2600 }
2601 2601
2602 void test_unusedElement_class_notUsed_isExpression() { 2602 test_unusedElement_class_notUsed_isExpression() async {
2603 enableUnusedElement = true; 2603 enableUnusedElement = true;
2604 Source source = addSource(r''' 2604 Source source = addSource(r'''
2605 class _A {} 2605 class _A {}
2606 main(p) { 2606 main(p) {
2607 if (p is _A) { 2607 if (p is _A) {
2608 } 2608 }
2609 } 2609 }
2610 '''); 2610 ''');
2611 assertErrors(source, [HintCode.UNUSED_ELEMENT]); 2611 await assertErrors(source, [HintCode.UNUSED_ELEMENT]);
2612 verify([source]); 2612 verify([source]);
2613 } 2613 }
2614 2614
2615 void test_unusedElement_class_notUsed_noReference() { 2615 test_unusedElement_class_notUsed_noReference() async {
2616 enableUnusedElement = true; 2616 enableUnusedElement = true;
2617 Source source = addSource(r''' 2617 Source source = addSource(r'''
2618 class _A {} 2618 class _A {}
2619 main() { 2619 main() {
2620 }'''); 2620 }''');
2621 assertErrors(source, [HintCode.UNUSED_ELEMENT]); 2621 await assertErrors(source, [HintCode.UNUSED_ELEMENT]);
2622 verify([source]); 2622 verify([source]);
2623 } 2623 }
2624 2624
2625 void test_unusedElement_class_notUsed_variableDeclaration() { 2625 test_unusedElement_class_notUsed_variableDeclaration() async {
2626 enableUnusedElement = true; 2626 enableUnusedElement = true;
2627 Source source = addSource(r''' 2627 Source source = addSource(r'''
2628 class _A {} 2628 class _A {}
2629 main() { 2629 main() {
2630 _A v; 2630 _A v;
2631 print(v); 2631 print(v);
2632 } 2632 }
2633 print(x) {} 2633 print(x) {}
2634 '''); 2634 ''');
2635 assertErrors(source, [HintCode.UNUSED_ELEMENT]); 2635 await assertErrors(source, [HintCode.UNUSED_ELEMENT]);
2636 verify([source]); 2636 verify([source]);
2637 } 2637 }
2638 2638
2639 void test_unusedElement_enum_isUsed_fieldReference() { 2639 test_unusedElement_enum_isUsed_fieldReference() async {
2640 enableUnusedElement = true; 2640 enableUnusedElement = true;
2641 Source source = addSource(r''' 2641 Source source = addSource(r'''
2642 enum _MyEnum {A, B, C} 2642 enum _MyEnum {A, B, C}
2643 main() { 2643 main() {
2644 print(_MyEnum.B); 2644 print(_MyEnum.B);
2645 }'''); 2645 }''');
2646 assertNoErrors(source); 2646 await assertNoErrors(source);
2647 verify([source]); 2647 verify([source]);
2648 } 2648 }
2649 2649
2650 void test_unusedElement_enum_notUsed_noReference() { 2650 test_unusedElement_enum_notUsed_noReference() async {
2651 enableUnusedElement = true; 2651 enableUnusedElement = true;
2652 Source source = addSource(r''' 2652 Source source = addSource(r'''
2653 enum _MyEnum {A, B, C} 2653 enum _MyEnum {A, B, C}
2654 main() { 2654 main() {
2655 }'''); 2655 }''');
2656 assertErrors(source, [HintCode.UNUSED_ELEMENT]); 2656 await assertErrors(source, [HintCode.UNUSED_ELEMENT]);
2657 verify([source]); 2657 verify([source]);
2658 } 2658 }
2659 2659
2660 void test_unusedElement_functionLocal_isUsed_closure() { 2660 test_unusedElement_functionLocal_isUsed_closure() async {
2661 enableUnusedElement = true; 2661 enableUnusedElement = true;
2662 Source source = addSource(r''' 2662 Source source = addSource(r'''
2663 main() { 2663 main() {
2664 print(() {}); 2664 print(() {});
2665 } 2665 }
2666 print(x) {} 2666 print(x) {}
2667 '''); 2667 ''');
2668 assertNoErrors(source); 2668 await assertNoErrors(source);
2669 verify([source]); 2669 verify([source]);
2670 } 2670 }
2671 2671
2672 void test_unusedElement_functionLocal_isUsed_invocation() { 2672 test_unusedElement_functionLocal_isUsed_invocation() async {
2673 enableUnusedElement = true; 2673 enableUnusedElement = true;
2674 Source source = addSource(r''' 2674 Source source = addSource(r'''
2675 main() { 2675 main() {
2676 f() {} 2676 f() {}
2677 f(); 2677 f();
2678 }'''); 2678 }''');
2679 assertNoErrors(source); 2679 await assertNoErrors(source);
2680 verify([source]); 2680 verify([source]);
2681 } 2681 }
2682 2682
2683 void test_unusedElement_functionLocal_isUsed_reference() { 2683 test_unusedElement_functionLocal_isUsed_reference() async {
2684 enableUnusedElement = true; 2684 enableUnusedElement = true;
2685 Source source = addSource(r''' 2685 Source source = addSource(r'''
2686 main() { 2686 main() {
2687 f() {} 2687 f() {}
2688 print(f); 2688 print(f);
2689 } 2689 }
2690 print(x) {} 2690 print(x) {}
2691 '''); 2691 ''');
2692 assertNoErrors(source); 2692 await assertNoErrors(source);
2693 verify([source]); 2693 verify([source]);
2694 } 2694 }
2695 2695
2696 void test_unusedElement_functionLocal_notUsed_noReference() { 2696 test_unusedElement_functionLocal_notUsed_noReference() async {
2697 enableUnusedElement = true; 2697 enableUnusedElement = true;
2698 Source source = addSource(r''' 2698 Source source = addSource(r'''
2699 main() { 2699 main() {
2700 f() {} 2700 f() {}
2701 }'''); 2701 }''');
2702 assertErrors(source, [HintCode.UNUSED_ELEMENT]); 2702 await assertErrors(source, [HintCode.UNUSED_ELEMENT]);
2703 verify([source]); 2703 verify([source]);
2704 } 2704 }
2705 2705
2706 void test_unusedElement_functionLocal_notUsed_referenceFromItself() { 2706 test_unusedElement_functionLocal_notUsed_referenceFromItself() async {
2707 enableUnusedElement = true; 2707 enableUnusedElement = true;
2708 Source source = addSource(r''' 2708 Source source = addSource(r'''
2709 main() { 2709 main() {
2710 _f(int p) { 2710 _f(int p) {
2711 _f(p - 1); 2711 _f(p - 1);
2712 } 2712 }
2713 }'''); 2713 }''');
2714 assertErrors(source, [HintCode.UNUSED_ELEMENT]); 2714 await assertErrors(source, [HintCode.UNUSED_ELEMENT]);
2715 verify([source]); 2715 verify([source]);
2716 } 2716 }
2717 2717
2718 void test_unusedElement_functionTop_isUsed_invocation() { 2718 test_unusedElement_functionTop_isUsed_invocation() async {
2719 enableUnusedElement = true; 2719 enableUnusedElement = true;
2720 Source source = addSource(r''' 2720 Source source = addSource(r'''
2721 _f() {} 2721 _f() {}
2722 main() { 2722 main() {
2723 _f(); 2723 _f();
2724 }'''); 2724 }''');
2725 assertNoErrors(source); 2725 await assertNoErrors(source);
2726 verify([source]); 2726 verify([source]);
2727 } 2727 }
2728 2728
2729 void test_unusedElement_functionTop_isUsed_reference() { 2729 test_unusedElement_functionTop_isUsed_reference() async {
2730 enableUnusedElement = true; 2730 enableUnusedElement = true;
2731 Source source = addSource(r''' 2731 Source source = addSource(r'''
2732 _f() {} 2732 _f() {}
2733 main() { 2733 main() {
2734 print(_f); 2734 print(_f);
2735 } 2735 }
2736 print(x) {} 2736 print(x) {}
2737 '''); 2737 ''');
2738 assertNoErrors(source); 2738 await assertNoErrors(source);
2739 verify([source]); 2739 verify([source]);
2740 } 2740 }
2741 2741
2742 void test_unusedElement_functionTop_notUsed_noReference() { 2742 test_unusedElement_functionTop_notUsed_noReference() async {
2743 enableUnusedElement = true; 2743 enableUnusedElement = true;
2744 Source source = addSource(r''' 2744 Source source = addSource(r'''
2745 _f() {} 2745 _f() {}
2746 main() { 2746 main() {
2747 }'''); 2747 }''');
2748 assertErrors(source, [HintCode.UNUSED_ELEMENT]); 2748 await assertErrors(source, [HintCode.UNUSED_ELEMENT]);
2749 verify([source]); 2749 verify([source]);
2750 } 2750 }
2751 2751
2752 void test_unusedElement_functionTop_notUsed_referenceFromItself() { 2752 test_unusedElement_functionTop_notUsed_referenceFromItself() async {
2753 enableUnusedElement = true; 2753 enableUnusedElement = true;
2754 Source source = addSource(r''' 2754 Source source = addSource(r'''
2755 _f(int p) { 2755 _f(int p) {
2756 _f(p - 1); 2756 _f(p - 1);
2757 } 2757 }
2758 main() { 2758 main() {
2759 }'''); 2759 }''');
2760 assertErrors(source, [HintCode.UNUSED_ELEMENT]); 2760 await assertErrors(source, [HintCode.UNUSED_ELEMENT]);
2761 verify([source]); 2761 verify([source]);
2762 } 2762 }
2763 2763
2764 void test_unusedElement_functionTypeAlias_isUsed_isExpression() { 2764 test_unusedElement_functionTypeAlias_isUsed_isExpression() async {
2765 enableUnusedElement = true; 2765 enableUnusedElement = true;
2766 Source source = addSource(r''' 2766 Source source = addSource(r'''
2767 typedef _F(a, b); 2767 typedef _F(a, b);
2768 main(f) { 2768 main(f) {
2769 if (f is _F) { 2769 if (f is _F) {
2770 print('F'); 2770 print('F');
2771 } 2771 }
2772 }'''); 2772 }''');
2773 assertNoErrors(source); 2773 await assertNoErrors(source);
2774 verify([source]); 2774 verify([source]);
2775 } 2775 }
2776 2776
2777 void test_unusedElement_functionTypeAlias_isUsed_reference() { 2777 test_unusedElement_functionTypeAlias_isUsed_reference() async {
2778 enableUnusedElement = true; 2778 enableUnusedElement = true;
2779 Source source = addSource(r''' 2779 Source source = addSource(r'''
2780 typedef _F(a, b); 2780 typedef _F(a, b);
2781 main(_F f) { 2781 main(_F f) {
2782 }'''); 2782 }''');
2783 assertNoErrors(source); 2783 await assertNoErrors(source);
2784 verify([source]); 2784 verify([source]);
2785 } 2785 }
2786 2786
2787 void test_unusedElement_functionTypeAlias_isUsed_typeArgument() { 2787 test_unusedElement_functionTypeAlias_isUsed_typeArgument() async {
2788 enableUnusedElement = true; 2788 enableUnusedElement = true;
2789 Source source = addSource(r''' 2789 Source source = addSource(r'''
2790 typedef _F(a, b); 2790 typedef _F(a, b);
2791 main() { 2791 main() {
2792 var v = new List<_F>(); 2792 var v = new List<_F>();
2793 print(v); 2793 print(v);
2794 }'''); 2794 }''');
2795 assertNoErrors(source); 2795 await assertNoErrors(source);
2796 verify([source]); 2796 verify([source]);
2797 } 2797 }
2798 2798
2799 void test_unusedElement_functionTypeAlias_isUsed_variableDeclaration() { 2799 test_unusedElement_functionTypeAlias_isUsed_variableDeclaration() async {
2800 enableUnusedElement = true; 2800 enableUnusedElement = true;
2801 Source source = addSource(r''' 2801 Source source = addSource(r'''
2802 typedef _F(a, b); 2802 typedef _F(a, b);
2803 class A { 2803 class A {
2804 _F f; 2804 _F f;
2805 }'''); 2805 }''');
2806 assertNoErrors(source); 2806 await assertNoErrors(source);
2807 verify([source]); 2807 verify([source]);
2808 } 2808 }
2809 2809
2810 void test_unusedElement_functionTypeAlias_notUsed_noReference() { 2810 test_unusedElement_functionTypeAlias_notUsed_noReference() async {
2811 enableUnusedElement = true; 2811 enableUnusedElement = true;
2812 Source source = addSource(r''' 2812 Source source = addSource(r'''
2813 typedef _F(a, b); 2813 typedef _F(a, b);
2814 main() { 2814 main() {
2815 }'''); 2815 }''');
2816 assertErrors(source, [HintCode.UNUSED_ELEMENT]); 2816 await assertErrors(source, [HintCode.UNUSED_ELEMENT]);
2817 verify([source]); 2817 verify([source]);
2818 } 2818 }
2819 2819
2820 void test_unusedElement_getter_isUsed_invocation_implicitThis() { 2820 test_unusedElement_getter_isUsed_invocation_implicitThis() async {
2821 enableUnusedElement = true; 2821 enableUnusedElement = true;
2822 Source source = addSource(r''' 2822 Source source = addSource(r'''
2823 class A { 2823 class A {
2824 get _g => null; 2824 get _g => null;
2825 useGetter() { 2825 useGetter() {
2826 var v = _g; 2826 var v = _g;
2827 } 2827 }
2828 }'''); 2828 }''');
2829 assertNoErrors(source); 2829 await assertNoErrors(source);
2830 verify([source]); 2830 verify([source]);
2831 } 2831 }
2832 2832
2833 void test_unusedElement_getter_isUsed_invocation_PrefixedIdentifier() { 2833 test_unusedElement_getter_isUsed_invocation_PrefixedIdentifier() async {
2834 enableUnusedElement = true; 2834 enableUnusedElement = true;
2835 Source source = addSource(r''' 2835 Source source = addSource(r'''
2836 class A { 2836 class A {
2837 get _g => null; 2837 get _g => null;
2838 } 2838 }
2839 main(A a) { 2839 main(A a) {
2840 var v = a._g; 2840 var v = a._g;
2841 } 2841 }
2842 '''); 2842 ''');
2843 assertNoErrors(source); 2843 await assertNoErrors(source);
2844 verify([source]); 2844 verify([source]);
2845 } 2845 }
2846 2846
2847 void test_unusedElement_getter_isUsed_invocation_PropertyAccess() { 2847 test_unusedElement_getter_isUsed_invocation_PropertyAccess() async {
2848 enableUnusedElement = true; 2848 enableUnusedElement = true;
2849 Source source = addSource(r''' 2849 Source source = addSource(r'''
2850 class A { 2850 class A {
2851 get _g => null; 2851 get _g => null;
2852 } 2852 }
2853 main() { 2853 main() {
2854 var v = new A()._g; 2854 var v = new A()._g;
2855 } 2855 }
2856 '''); 2856 ''');
2857 assertNoErrors(source); 2857 await assertNoErrors(source);
2858 verify([source]); 2858 verify([source]);
2859 } 2859 }
2860 2860
2861 void test_unusedElement_getter_notUsed_noReference() { 2861 test_unusedElement_getter_notUsed_noReference() async {
2862 enableUnusedElement = true; 2862 enableUnusedElement = true;
2863 Source source = addSource(r''' 2863 Source source = addSource(r'''
2864 class A { 2864 class A {
2865 get _g => null; 2865 get _g => null;
2866 }'''); 2866 }''');
2867 assertErrors(source, [HintCode.UNUSED_ELEMENT]); 2867 await assertErrors(source, [HintCode.UNUSED_ELEMENT]);
2868 verify([source]); 2868 verify([source]);
2869 } 2869 }
2870 2870
2871 void test_unusedElement_getter_notUsed_referenceFromItself() { 2871 test_unusedElement_getter_notUsed_referenceFromItself() async {
2872 enableUnusedElement = true; 2872 enableUnusedElement = true;
2873 Source source = addSource(r''' 2873 Source source = addSource(r'''
2874 class A { 2874 class A {
2875 get _g { 2875 get _g {
2876 return _g; 2876 return _g;
2877 } 2877 }
2878 }'''); 2878 }''');
2879 assertErrors(source, [HintCode.UNUSED_ELEMENT]); 2879 await assertErrors(source, [HintCode.UNUSED_ELEMENT]);
2880 verify([source]); 2880 verify([source]);
2881 } 2881 }
2882 2882
2883 void test_unusedElement_method_isUsed_hasReference_implicitThis() { 2883 test_unusedElement_method_isUsed_hasReference_implicitThis() async {
2884 enableUnusedElement = true; 2884 enableUnusedElement = true;
2885 Source source = addSource(r''' 2885 Source source = addSource(r'''
2886 class A { 2886 class A {
2887 _m() {} 2887 _m() {}
2888 useMethod() { 2888 useMethod() {
2889 print(_m); 2889 print(_m);
2890 } 2890 }
2891 } 2891 }
2892 print(x) {} 2892 print(x) {}
2893 '''); 2893 ''');
2894 assertNoErrors(source); 2894 await assertNoErrors(source);
2895 verify([source]); 2895 verify([source]);
2896 } 2896 }
2897 2897
2898 void test_unusedElement_method_isUsed_hasReference_implicitThis_subclass() { 2898 test_unusedElement_method_isUsed_hasReference_implicitThis_subclass() async {
2899 enableUnusedElement = true; 2899 enableUnusedElement = true;
2900 Source source = addSource(r''' 2900 Source source = addSource(r'''
2901 class A { 2901 class A {
2902 _m() {} 2902 _m() {}
2903 useMethod() { 2903 useMethod() {
2904 print(_m); 2904 print(_m);
2905 } 2905 }
2906 } 2906 }
2907 class B extends A { 2907 class B extends A {
2908 _m() {} 2908 _m() {}
2909 } 2909 }
2910 print(x) {} 2910 print(x) {}
2911 '''); 2911 ''');
2912 assertNoErrors(source); 2912 await assertNoErrors(source);
2913 verify([source]); 2913 verify([source]);
2914 } 2914 }
2915 2915
2916 void test_unusedElement_method_isUsed_hasReference_PrefixedIdentifier() { 2916 test_unusedElement_method_isUsed_hasReference_PrefixedIdentifier() async {
2917 enableUnusedElement = true; 2917 enableUnusedElement = true;
2918 Source source = addSource(r''' 2918 Source source = addSource(r'''
2919 class A { 2919 class A {
2920 _m() {} 2920 _m() {}
2921 } 2921 }
2922 main(A a) { 2922 main(A a) {
2923 a._m; 2923 a._m;
2924 }'''); 2924 }''');
2925 assertNoErrors(source); 2925 await assertNoErrors(source);
2926 verify([source]); 2926 verify([source]);
2927 } 2927 }
2928 2928
2929 void test_unusedElement_method_isUsed_hasReference_PropertyAccess() { 2929 test_unusedElement_method_isUsed_hasReference_PropertyAccess() async {
2930 enableUnusedElement = true; 2930 enableUnusedElement = true;
2931 Source source = addSource(r''' 2931 Source source = addSource(r'''
2932 class A { 2932 class A {
2933 _m() {} 2933 _m() {}
2934 } 2934 }
2935 main() { 2935 main() {
2936 new A()._m; 2936 new A()._m;
2937 }'''); 2937 }''');
2938 assertNoErrors(source); 2938 await assertNoErrors(source);
2939 verify([source]); 2939 verify([source]);
2940 } 2940 }
2941 2941
2942 void test_unusedElement_method_isUsed_invocation_implicitThis() { 2942 test_unusedElement_method_isUsed_invocation_implicitThis() async {
2943 enableUnusedElement = true; 2943 enableUnusedElement = true;
2944 Source source = addSource(r''' 2944 Source source = addSource(r'''
2945 class A { 2945 class A {
2946 _m() {} 2946 _m() {}
2947 useMethod() { 2947 useMethod() {
2948 _m(); 2948 _m();
2949 } 2949 }
2950 }'''); 2950 }''');
2951 assertNoErrors(source); 2951 await assertNoErrors(source);
2952 verify([source]); 2952 verify([source]);
2953 } 2953 }
2954 2954
2955 void test_unusedElement_method_isUsed_invocation_implicitThis_subclass() { 2955 test_unusedElement_method_isUsed_invocation_implicitThis_subclass() async {
2956 enableUnusedElement = true; 2956 enableUnusedElement = true;
2957 Source source = addSource(r''' 2957 Source source = addSource(r'''
2958 class A { 2958 class A {
2959 _m() {} 2959 _m() {}
2960 useMethod() { 2960 useMethod() {
2961 _m(); 2961 _m();
2962 } 2962 }
2963 } 2963 }
2964 class B extends A { 2964 class B extends A {
2965 _m() {} 2965 _m() {}
2966 }'''); 2966 }''');
2967 assertNoErrors(source); 2967 await assertNoErrors(source);
2968 verify([source]); 2968 verify([source]);
2969 } 2969 }
2970 2970
2971 void test_unusedElement_method_isUsed_invocation_MemberElement() { 2971 test_unusedElement_method_isUsed_invocation_MemberElement() async {
2972 enableUnusedElement = true; 2972 enableUnusedElement = true;
2973 Source source = addSource(r''' 2973 Source source = addSource(r'''
2974 class A<T> { 2974 class A<T> {
2975 _m(T t) {} 2975 _m(T t) {}
2976 } 2976 }
2977 main(A<int> a) { 2977 main(A<int> a) {
2978 a._m(0); 2978 a._m(0);
2979 }'''); 2979 }''');
2980 assertNoErrors(source); 2980 await assertNoErrors(source);
2981 verify([source]); 2981 verify([source]);
2982 } 2982 }
2983 2983
2984 void test_unusedElement_method_isUsed_invocation_propagated() { 2984 test_unusedElement_method_isUsed_invocation_propagated() async {
2985 enableUnusedElement = true; 2985 enableUnusedElement = true;
2986 Source source = addSource(r''' 2986 Source source = addSource(r'''
2987 class A { 2987 class A {
2988 _m() {} 2988 _m() {}
2989 } 2989 }
2990 main() { 2990 main() {
2991 var a = new A(); 2991 var a = new A();
2992 a._m(); 2992 a._m();
2993 }'''); 2993 }''');
2994 assertNoErrors(source); 2994 await assertNoErrors(source);
2995 verify([source]); 2995 verify([source]);
2996 } 2996 }
2997 2997
2998 void test_unusedElement_method_isUsed_invocation_static() { 2998 test_unusedElement_method_isUsed_invocation_static() async {
2999 enableUnusedElement = true; 2999 enableUnusedElement = true;
3000 Source source = addSource(r''' 3000 Source source = addSource(r'''
3001 class A { 3001 class A {
3002 _m() {} 3002 _m() {}
3003 } 3003 }
3004 main() { 3004 main() {
3005 A a = new A(); 3005 A a = new A();
3006 a._m(); 3006 a._m();
3007 }'''); 3007 }''');
3008 assertNoErrors(source); 3008 await assertNoErrors(source);
3009 verify([source]); 3009 verify([source]);
3010 } 3010 }
3011 3011
3012 void test_unusedElement_method_isUsed_invocation_subclass() { 3012 test_unusedElement_method_isUsed_invocation_subclass() async {
3013 enableUnusedElement = true; 3013 enableUnusedElement = true;
3014 Source source = addSource(r''' 3014 Source source = addSource(r'''
3015 class A { 3015 class A {
3016 _m() {} 3016 _m() {}
3017 } 3017 }
3018 class B extends A { 3018 class B extends A {
3019 _m() {} 3019 _m() {}
3020 } 3020 }
3021 main(A a) { 3021 main(A a) {
3022 a._m(); 3022 a._m();
3023 }'''); 3023 }''');
3024 assertNoErrors(source); 3024 await assertNoErrors(source);
3025 verify([source]); 3025 verify([source]);
3026 } 3026 }
3027 3027
3028 void test_unusedElement_method_isUsed_notPrivate() { 3028 test_unusedElement_method_isUsed_notPrivate() async {
3029 enableUnusedElement = true; 3029 enableUnusedElement = true;
3030 Source source = addSource(r''' 3030 Source source = addSource(r'''
3031 class A { 3031 class A {
3032 m() {} 3032 m() {}
3033 } 3033 }
3034 main() { 3034 main() {
3035 }'''); 3035 }''');
3036 assertNoErrors(source); 3036 await assertNoErrors(source);
3037 verify([source]); 3037 verify([source]);
3038 } 3038 }
3039 3039
3040 void test_unusedElement_method_isUsed_staticInvocation() { 3040 test_unusedElement_method_isUsed_staticInvocation() async {
3041 enableUnusedElement = true; 3041 enableUnusedElement = true;
3042 Source source = addSource(r''' 3042 Source source = addSource(r'''
3043 class A { 3043 class A {
3044 static _m() {} 3044 static _m() {}
3045 } 3045 }
3046 main() { 3046 main() {
3047 A._m(); 3047 A._m();
3048 }'''); 3048 }''');
3049 assertNoErrors(source); 3049 await assertNoErrors(source);
3050 verify([source]); 3050 verify([source]);
3051 } 3051 }
3052 3052
3053 void test_unusedElement_method_notUsed_noReference() { 3053 test_unusedElement_method_notUsed_noReference() async {
3054 enableUnusedElement = true; 3054 enableUnusedElement = true;
3055 Source source = addSource(r''' 3055 Source source = addSource(r'''
3056 class A { 3056 class A {
3057 static _m() {} 3057 static _m() {}
3058 }'''); 3058 }''');
3059 assertErrors(source, [HintCode.UNUSED_ELEMENT]); 3059 await assertErrors(source, [HintCode.UNUSED_ELEMENT]);
3060 verify([source]); 3060 verify([source]);
3061 } 3061 }
3062 3062
3063 void test_unusedElement_method_notUsed_referenceFromItself() { 3063 test_unusedElement_method_notUsed_referenceFromItself() async {
3064 enableUnusedElement = true; 3064 enableUnusedElement = true;
3065 Source source = addSource(r''' 3065 Source source = addSource(r'''
3066 class A { 3066 class A {
3067 static _m(int p) { 3067 static _m(int p) {
3068 _m(p - 1); 3068 _m(p - 1);
3069 } 3069 }
3070 }'''); 3070 }''');
3071 assertErrors(source, [HintCode.UNUSED_ELEMENT]); 3071 await assertErrors(source, [HintCode.UNUSED_ELEMENT]);
3072 verify([source]); 3072 verify([source]);
3073 } 3073 }
3074 3074
3075 void test_unusedElement_setter_isUsed_invocation_implicitThis() { 3075 test_unusedElement_setter_isUsed_invocation_implicitThis() async {
3076 enableUnusedElement = true; 3076 enableUnusedElement = true;
3077 Source source = addSource(r''' 3077 Source source = addSource(r'''
3078 class A { 3078 class A {
3079 set _s(x) {} 3079 set _s(x) {}
3080 useSetter() { 3080 useSetter() {
3081 _s = 42; 3081 _s = 42;
3082 } 3082 }
3083 }'''); 3083 }''');
3084 assertNoErrors(source); 3084 await assertNoErrors(source);
3085 verify([source]); 3085 verify([source]);
3086 } 3086 }
3087 3087
3088 void test_unusedElement_setter_isUsed_invocation_PrefixedIdentifier() { 3088 test_unusedElement_setter_isUsed_invocation_PrefixedIdentifier() async {
3089 enableUnusedElement = true; 3089 enableUnusedElement = true;
3090 Source source = addSource(r''' 3090 Source source = addSource(r'''
3091 class A { 3091 class A {
3092 set _s(x) {} 3092 set _s(x) {}
3093 } 3093 }
3094 main(A a) { 3094 main(A a) {
3095 a._s = 42; 3095 a._s = 42;
3096 } 3096 }
3097 '''); 3097 ''');
3098 assertNoErrors(source); 3098 await assertNoErrors(source);
3099 verify([source]); 3099 verify([source]);
3100 } 3100 }
3101 3101
3102 void test_unusedElement_setter_isUsed_invocation_PropertyAccess() { 3102 test_unusedElement_setter_isUsed_invocation_PropertyAccess() async {
3103 enableUnusedElement = true; 3103 enableUnusedElement = true;
3104 Source source = addSource(r''' 3104 Source source = addSource(r'''
3105 class A { 3105 class A {
3106 set _s(x) {} 3106 set _s(x) {}
3107 } 3107 }
3108 main() { 3108 main() {
3109 new A()._s = 42; 3109 new A()._s = 42;
3110 } 3110 }
3111 '''); 3111 ''');
3112 assertNoErrors(source); 3112 await assertNoErrors(source);
3113 verify([source]); 3113 verify([source]);
3114 } 3114 }
3115 3115
3116 void test_unusedElement_setter_notUsed_noReference() { 3116 test_unusedElement_setter_notUsed_noReference() async {
3117 enableUnusedElement = true; 3117 enableUnusedElement = true;
3118 Source source = addSource(r''' 3118 Source source = addSource(r'''
3119 class A { 3119 class A {
3120 set _s(x) {} 3120 set _s(x) {}
3121 }'''); 3121 }''');
3122 assertErrors(source, [HintCode.UNUSED_ELEMENT]); 3122 await assertErrors(source, [HintCode.UNUSED_ELEMENT]);
3123 verify([source]); 3123 verify([source]);
3124 } 3124 }
3125 3125
3126 void test_unusedElement_setter_notUsed_referenceFromItself() { 3126 test_unusedElement_setter_notUsed_referenceFromItself() async {
3127 enableUnusedElement = true; 3127 enableUnusedElement = true;
3128 Source source = addSource(r''' 3128 Source source = addSource(r'''
3129 class A { 3129 class A {
3130 set _s(int x) { 3130 set _s(int x) {
3131 if (x > 5) { 3131 if (x > 5) {
3132 _s = x - 1; 3132 _s = x - 1;
3133 } 3133 }
3134 } 3134 }
3135 }'''); 3135 }''');
3136 assertErrors(source, [HintCode.UNUSED_ELEMENT]); 3136 await assertErrors(source, [HintCode.UNUSED_ELEMENT]);
3137 verify([source]); 3137 verify([source]);
3138 } 3138 }
3139 3139
3140 void test_unusedField_isUsed_argument() { 3140 test_unusedField_isUsed_argument() async {
3141 enableUnusedElement = true; 3141 enableUnusedElement = true;
3142 Source source = addSource(r''' 3142 Source source = addSource(r'''
3143 class A { 3143 class A {
3144 int _f = 0; 3144 int _f = 0;
3145 main() { 3145 main() {
3146 print(++_f); 3146 print(++_f);
3147 } 3147 }
3148 } 3148 }
3149 print(x) {}'''); 3149 print(x) {}''');
3150 assertErrors(source); 3150 await assertErrors(source);
3151 verify([source]); 3151 verify([source]);
3152 } 3152 }
3153 3153
3154 void test_unusedField_isUsed_reference_implicitThis() { 3154 test_unusedField_isUsed_reference_implicitThis() async {
3155 enableUnusedElement = true; 3155 enableUnusedElement = true;
3156 Source source = addSource(r''' 3156 Source source = addSource(r'''
3157 class A { 3157 class A {
3158 int _f; 3158 int _f;
3159 main() { 3159 main() {
3160 print(_f); 3160 print(_f);
3161 } 3161 }
3162 } 3162 }
3163 print(x) {}'''); 3163 print(x) {}''');
3164 assertErrors(source); 3164 await assertErrors(source);
3165 verify([source]); 3165 verify([source]);
3166 } 3166 }
3167 3167
3168 void test_unusedField_isUsed_reference_implicitThis_expressionFunctionBody() { 3168 test_unusedField_isUsed_reference_implicitThis_expressionFunctionBody() async {
3169 enableUnusedElement = true; 3169 enableUnusedElement = true;
3170 Source source = addSource(r''' 3170 Source source = addSource(r'''
3171 class A { 3171 class A {
3172 int _f; 3172 int _f;
3173 m() => _f; 3173 m() => _f;
3174 }'''); 3174 }''');
3175 assertErrors(source); 3175 await assertErrors(source);
3176 verify([source]); 3176 verify([source]);
3177 } 3177 }
3178 3178
3179 void test_unusedField_isUsed_reference_implicitThis_subclass() { 3179 test_unusedField_isUsed_reference_implicitThis_subclass() async {
3180 enableUnusedElement = true; 3180 enableUnusedElement = true;
3181 Source source = addSource(r''' 3181 Source source = addSource(r'''
3182 class A { 3182 class A {
3183 int _f; 3183 int _f;
3184 main() { 3184 main() {
3185 print(_f); 3185 print(_f);
3186 } 3186 }
3187 } 3187 }
3188 class B extends A { 3188 class B extends A {
3189 int _f; 3189 int _f;
3190 } 3190 }
3191 print(x) {}'''); 3191 print(x) {}''');
3192 assertErrors(source); 3192 await assertErrors(source);
3193 verify([source]); 3193 verify([source]);
3194 } 3194 }
3195 3195
3196 void test_unusedField_isUsed_reference_qualified_propagatedElement() { 3196 test_unusedField_isUsed_reference_qualified_propagatedElement() async {
3197 enableUnusedElement = true; 3197 enableUnusedElement = true;
3198 Source source = addSource(r''' 3198 Source source = addSource(r'''
3199 class A { 3199 class A {
3200 int _f; 3200 int _f;
3201 } 3201 }
3202 main() { 3202 main() {
3203 var a = new A(); 3203 var a = new A();
3204 print(a._f); 3204 print(a._f);
3205 } 3205 }
3206 print(x) {}'''); 3206 print(x) {}''');
3207 assertErrors(source); 3207 await assertErrors(source);
3208 verify([source]); 3208 verify([source]);
3209 } 3209 }
3210 3210
3211 void test_unusedField_isUsed_reference_qualified_staticElement() { 3211 test_unusedField_isUsed_reference_qualified_staticElement() async {
3212 enableUnusedElement = true; 3212 enableUnusedElement = true;
3213 Source source = addSource(r''' 3213 Source source = addSource(r'''
3214 class A { 3214 class A {
3215 int _f; 3215 int _f;
3216 } 3216 }
3217 main() { 3217 main() {
3218 A a = new A(); 3218 A a = new A();
3219 print(a._f); 3219 print(a._f);
3220 } 3220 }
3221 print(x) {}'''); 3221 print(x) {}''');
3222 assertErrors(source); 3222 await assertErrors(source);
3223 verify([source]); 3223 verify([source]);
3224 } 3224 }
3225 3225
3226 void test_unusedField_isUsed_reference_qualified_unresolved() { 3226 test_unusedField_isUsed_reference_qualified_unresolved() async {
3227 enableUnusedElement = true; 3227 enableUnusedElement = true;
3228 Source source = addSource(r''' 3228 Source source = addSource(r'''
3229 class A { 3229 class A {
3230 int _f; 3230 int _f;
3231 } 3231 }
3232 main(a) { 3232 main(a) {
3233 print(a._f); 3233 print(a._f);
3234 } 3234 }
3235 print(x) {}'''); 3235 print(x) {}''');
3236 assertErrors(source); 3236 await assertErrors(source);
3237 verify([source]); 3237 verify([source]);
3238 } 3238 }
3239 3239
3240 void test_unusedField_notUsed_compoundAssign() { 3240 test_unusedField_notUsed_compoundAssign() async {
3241 enableUnusedElement = true; 3241 enableUnusedElement = true;
3242 Source source = addSource(r''' 3242 Source source = addSource(r'''
3243 class A { 3243 class A {
3244 int _f; 3244 int _f;
3245 main() { 3245 main() {
3246 _f += 2; 3246 _f += 2;
3247 } 3247 }
3248 }'''); 3248 }''');
3249 assertErrors(source, [HintCode.UNUSED_FIELD]); 3249 await assertErrors(source, [HintCode.UNUSED_FIELD]);
3250 verify([source]); 3250 verify([source]);
3251 } 3251 }
3252 3252
3253 void test_unusedField_notUsed_constructorFieldInitializers() { 3253 test_unusedField_notUsed_constructorFieldInitializers() async {
3254 enableUnusedElement = true; 3254 enableUnusedElement = true;
3255 Source source = addSource(r''' 3255 Source source = addSource(r'''
3256 class A { 3256 class A {
3257 int _f; 3257 int _f;
3258 A() : _f = 0; 3258 A() : _f = 0;
3259 }'''); 3259 }''');
3260 assertErrors(source, [HintCode.UNUSED_FIELD]); 3260 await assertErrors(source, [HintCode.UNUSED_FIELD]);
3261 verify([source]); 3261 verify([source]);
3262 } 3262 }
3263 3263
3264 void test_unusedField_notUsed_fieldFormalParameter() { 3264 test_unusedField_notUsed_fieldFormalParameter() async {
3265 enableUnusedElement = true; 3265 enableUnusedElement = true;
3266 Source source = addSource(r''' 3266 Source source = addSource(r'''
3267 class A { 3267 class A {
3268 int _f; 3268 int _f;
3269 A(this._f); 3269 A(this._f);
3270 }'''); 3270 }''');
3271 assertErrors(source, [HintCode.UNUSED_FIELD]); 3271 await assertErrors(source, [HintCode.UNUSED_FIELD]);
3272 verify([source]); 3272 verify([source]);
3273 } 3273 }
3274 3274
3275 void test_unusedField_notUsed_noReference() { 3275 test_unusedField_notUsed_noReference() async {
3276 enableUnusedElement = true; 3276 enableUnusedElement = true;
3277 Source source = addSource(r''' 3277 Source source = addSource(r'''
3278 class A { 3278 class A {
3279 int _f; 3279 int _f;
3280 } 3280 }
3281 '''); 3281 ''');
3282 assertErrors(source, [HintCode.UNUSED_FIELD]); 3282 await assertErrors(source, [HintCode.UNUSED_FIELD]);
3283 verify([source]); 3283 verify([source]);
3284 } 3284 }
3285 3285
3286 void test_unusedField_notUsed_postfixExpr() { 3286 test_unusedField_notUsed_postfixExpr() async {
3287 enableUnusedElement = true; 3287 enableUnusedElement = true;
3288 Source source = addSource(r''' 3288 Source source = addSource(r'''
3289 class A { 3289 class A {
3290 int _f = 0; 3290 int _f = 0;
3291 main() { 3291 main() {
3292 _f++; 3292 _f++;
3293 } 3293 }
3294 }'''); 3294 }''');
3295 assertErrors(source, [HintCode.UNUSED_FIELD]); 3295 await assertErrors(source, [HintCode.UNUSED_FIELD]);
3296 verify([source]); 3296 verify([source]);
3297 } 3297 }
3298 3298
3299 void test_unusedField_notUsed_prefixExpr() { 3299 test_unusedField_notUsed_prefixExpr() async {
3300 enableUnusedElement = true; 3300 enableUnusedElement = true;
3301 Source source = addSource(r''' 3301 Source source = addSource(r'''
3302 class A { 3302 class A {
3303 int _f = 0; 3303 int _f = 0;
3304 main() { 3304 main() {
3305 ++_f; 3305 ++_f;
3306 } 3306 }
3307 }'''); 3307 }''');
3308 assertErrors(source, [HintCode.UNUSED_FIELD]); 3308 await assertErrors(source, [HintCode.UNUSED_FIELD]);
3309 verify([source]); 3309 verify([source]);
3310 } 3310 }
3311 3311
3312 void test_unusedField_notUsed_simpleAssignment() { 3312 test_unusedField_notUsed_simpleAssignment() async {
3313 enableUnusedElement = true; 3313 enableUnusedElement = true;
3314 Source source = addSource(r''' 3314 Source source = addSource(r'''
3315 class A { 3315 class A {
3316 int _f; 3316 int _f;
3317 m() { 3317 m() {
3318 _f = 1; 3318 _f = 1;
3319 } 3319 }
3320 } 3320 }
3321 main(A a) { 3321 main(A a) {
3322 a._f = 2; 3322 a._f = 2;
3323 } 3323 }
3324 '''); 3324 ''');
3325 assertErrors(source, [HintCode.UNUSED_FIELD]); 3325 await assertErrors(source, [HintCode.UNUSED_FIELD]);
3326 verify([source]); 3326 verify([source]);
3327 } 3327 }
3328 3328
3329 void test_unusedImport() { 3329 test_unusedImport() async {
3330 Source source = addSource(r''' 3330 Source source = addSource(r'''
3331 library L; 3331 library L;
3332 import 'lib1.dart';'''); 3332 import 'lib1.dart';''');
3333 Source source2 = addNamedSource("/lib1.dart", "library lib1;"); 3333 Source source2 = addNamedSource("/lib1.dart", "library lib1;");
3334 assertErrors(source, [HintCode.UNUSED_IMPORT]); 3334 await assertErrors(source, [HintCode.UNUSED_IMPORT]);
3335 assertNoErrors(source2); 3335 await assertNoErrors(source2);
3336 verify([source, source2]); 3336 verify([source, source2]);
3337 } 3337 }
3338 3338
3339 void test_unusedImport_as() { 3339 test_unusedImport_as() async {
3340 Source source = addSource(r''' 3340 Source source = addSource(r'''
3341 library L; 3341 library L;
3342 import 'lib1.dart'; 3342 import 'lib1.dart';
3343 import 'lib1.dart' as one; 3343 import 'lib1.dart' as one;
3344 one.A a;'''); 3344 one.A a;''');
3345 Source source2 = addNamedSource( 3345 Source source2 = addNamedSource(
3346 "/lib1.dart", 3346 "/lib1.dart",
3347 r''' 3347 r'''
3348 library lib1; 3348 library lib1;
3349 class A {}'''); 3349 class A {}''');
3350 assertErrors(source, [HintCode.UNUSED_IMPORT]); 3350 await assertErrors(source, [HintCode.UNUSED_IMPORT]);
3351 assertNoErrors(source2); 3351 await assertNoErrors(source2);
3352 verify([source, source2]); 3352 verify([source, source2]);
3353 } 3353 }
3354 3354
3355 @failingTest 3355 @failingTest
3356 void test_unusedImport_as_equalPrefixes() { 3356 test_unusedImport_as_equalPrefixes() async {
3357 // See todo at ImportsVerifier.prefixElementMap. 3357 // See todo at ImportsVerifier.prefixElementMap.
3358 Source source = addSource(r''' 3358 Source source = addSource(r'''
3359 library L; 3359 library L;
3360 import 'lib1.dart' as one; 3360 import 'lib1.dart' as one;
3361 import 'lib2.dart' as one; 3361 import 'lib2.dart' as one;
3362 one.A a;'''); 3362 one.A a;''');
3363 Source source2 = addNamedSource( 3363 Source source2 = addNamedSource(
3364 "/lib1.dart", 3364 "/lib1.dart",
3365 r''' 3365 r'''
3366 library lib1; 3366 library lib1;
3367 class A {}'''); 3367 class A {}''');
3368 Source source3 = addNamedSource( 3368 Source source3 = addNamedSource(
3369 "/lib2.dart", 3369 "/lib2.dart",
3370 r''' 3370 r'''
3371 library lib2; 3371 library lib2;
3372 class B {}'''); 3372 class B {}''');
3373 assertErrors(source, [HintCode.UNUSED_IMPORT]); 3373 await assertErrors(source, [HintCode.UNUSED_IMPORT]);
3374 assertNoErrors(source2); 3374 await assertNoErrors(source2);
3375 assertNoErrors(source3); 3375 await assertNoErrors(source3);
3376 verify([source, source2, source3]); 3376 verify([source, source2, source3]);
3377 } 3377 }
3378 3378
3379 void test_unusedImport_hide() { 3379 test_unusedImport_hide() async {
3380 Source source = addSource(r''' 3380 Source source = addSource(r'''
3381 library L; 3381 library L;
3382 import 'lib1.dart'; 3382 import 'lib1.dart';
3383 import 'lib1.dart' hide A; 3383 import 'lib1.dart' hide A;
3384 A a;'''); 3384 A a;''');
3385 Source source2 = addNamedSource( 3385 Source source2 = addNamedSource(
3386 "/lib1.dart", 3386 "/lib1.dart",
3387 r''' 3387 r'''
3388 library lib1; 3388 library lib1;
3389 class A {}'''); 3389 class A {}''');
3390 assertErrors(source, [HintCode.UNUSED_IMPORT]); 3390 await assertErrors(source, [HintCode.UNUSED_IMPORT]);
3391 assertNoErrors(source2); 3391 await assertNoErrors(source2);
3392 verify([source, source2]); 3392 verify([source, source2]);
3393 } 3393 }
3394 3394
3395 void test_unusedImport_inComment_libraryDirective() { 3395 test_unusedImport_inComment_libraryDirective() async {
3396 Source source = addSource(r''' 3396 Source source = addSource(r'''
3397 /// Use [Future] class. 3397 /// Use [Future] class.
3398 library L; 3398 library L;
3399 import 'dart:async'; 3399 import 'dart:async';
3400 '''); 3400 ''');
3401 assertNoErrors(source); 3401 await assertNoErrors(source);
3402 } 3402 }
3403 3403
3404 void test_unusedImport_show() { 3404 test_unusedImport_show() async {
3405 Source source = addSource(r''' 3405 Source source = addSource(r'''
3406 library L; 3406 library L;
3407 import 'lib1.dart' show A; 3407 import 'lib1.dart' show A;
3408 import 'lib1.dart' show B; 3408 import 'lib1.dart' show B;
3409 A a;'''); 3409 A a;''');
3410 Source source2 = addNamedSource( 3410 Source source2 = addNamedSource(
3411 "/lib1.dart", 3411 "/lib1.dart",
3412 r''' 3412 r'''
3413 library lib1; 3413 library lib1;
3414 class A {} 3414 class A {}
3415 class B {}'''); 3415 class B {}''');
3416 assertErrors(source, [HintCode.UNUSED_IMPORT]); 3416 await assertErrors(source, [HintCode.UNUSED_IMPORT]);
3417 assertNoErrors(source2); 3417 await assertNoErrors(source2);
3418 verify([source, source2]); 3418 verify([source, source2]);
3419 } 3419 }
3420 3420
3421 void test_unusedLocalVariable_inCatch_exception() { 3421 test_unusedLocalVariable_inCatch_exception() async {
3422 enableUnusedLocalVariable = true; 3422 enableUnusedLocalVariable = true;
3423 Source source = addSource(r''' 3423 Source source = addSource(r'''
3424 main() { 3424 main() {
3425 try { 3425 try {
3426 } on String catch (exception) { 3426 } on String catch (exception) {
3427 } 3427 }
3428 }'''); 3428 }''');
3429 assertErrors(source, [HintCode.UNUSED_CATCH_CLAUSE]); 3429 await assertErrors(source, [HintCode.UNUSED_CATCH_CLAUSE]);
3430 verify([source]); 3430 verify([source]);
3431 } 3431 }
3432 3432
3433 void test_unusedLocalVariable_inCatch_exception_hasStack() { 3433 test_unusedLocalVariable_inCatch_exception_hasStack() async {
3434 enableUnusedLocalVariable = true; 3434 enableUnusedLocalVariable = true;
3435 Source source = addSource(r''' 3435 Source source = addSource(r'''
3436 main() { 3436 main() {
3437 try { 3437 try {
3438 } catch (exception, stack) { 3438 } catch (exception, stack) {
3439 print(stack); 3439 print(stack);
3440 } 3440 }
3441 }'''); 3441 }''');
3442 assertNoErrors(source); 3442 await assertNoErrors(source);
3443 verify([source]); 3443 verify([source]);
3444 } 3444 }
3445 3445
3446 void test_unusedLocalVariable_inCatch_exception_noOnClause() { 3446 test_unusedLocalVariable_inCatch_exception_noOnClause() async {
3447 enableUnusedLocalVariable = true; 3447 enableUnusedLocalVariable = true;
3448 Source source = addSource(r''' 3448 Source source = addSource(r'''
3449 main() { 3449 main() {
3450 try { 3450 try {
3451 } catch (exception) { 3451 } catch (exception) {
3452 } 3452 }
3453 }'''); 3453 }''');
3454 assertNoErrors(source); 3454 await assertNoErrors(source);
3455 verify([source]); 3455 verify([source]);
3456 } 3456 }
3457 3457
3458 void test_unusedLocalVariable_inCatch_stackTrace() { 3458 test_unusedLocalVariable_inCatch_stackTrace() async {
3459 enableUnusedLocalVariable = true; 3459 enableUnusedLocalVariable = true;
3460 Source source = addSource(r''' 3460 Source source = addSource(r'''
3461 main() { 3461 main() {
3462 try { 3462 try {
3463 } catch (exception, stackTrace) { 3463 } catch (exception, stackTrace) {
3464 } 3464 }
3465 }'''); 3465 }''');
3466 assertErrors(source, [HintCode.UNUSED_CATCH_STACK]); 3466 await assertErrors(source, [HintCode.UNUSED_CATCH_STACK]);
3467 verify([source]); 3467 verify([source]);
3468 } 3468 }
3469 3469
3470 void test_unusedLocalVariable_inCatch_stackTrace_used() { 3470 test_unusedLocalVariable_inCatch_stackTrace_used() async {
3471 enableUnusedLocalVariable = true; 3471 enableUnusedLocalVariable = true;
3472 Source source = addSource(r''' 3472 Source source = addSource(r'''
3473 main() { 3473 main() {
3474 try { 3474 try {
3475 } catch (exception, stackTrace) { 3475 } catch (exception, stackTrace) {
3476 print('exception at $stackTrace'); 3476 print('exception at $stackTrace');
3477 } 3477 }
3478 } 3478 }
3479 print(x) {}'''); 3479 print(x) {}''');
3480 assertErrors(source); 3480 await assertErrors(source);
3481 verify([source]); 3481 verify([source]);
3482 } 3482 }
3483 3483
3484 void test_unusedLocalVariable_inFor_underscore_ignored() { 3484 test_unusedLocalVariable_inFor_underscore_ignored() async {
3485 enableUnusedLocalVariable = true; 3485 enableUnusedLocalVariable = true;
3486 Source source = addSource(r''' 3486 Source source = addSource(r'''
3487 main() { 3487 main() {
3488 for (var _ in [1,2,3]) { 3488 for (var _ in [1,2,3]) {
3489 for (var __ in [4,5,6]) { 3489 for (var __ in [4,5,6]) {
3490 // do something 3490 // do something
3491 } 3491 }
3492 } 3492 }
3493 }'''); 3493 }''');
3494 assertErrors(source); 3494 await assertErrors(source);
3495 verify([source]); 3495 verify([source]);
3496 } 3496 }
3497 3497
3498 void test_unusedLocalVariable_inFunction() { 3498 test_unusedLocalVariable_inFunction() async {
3499 enableUnusedLocalVariable = true; 3499 enableUnusedLocalVariable = true;
3500 Source source = addSource(r''' 3500 Source source = addSource(r'''
3501 main() { 3501 main() {
3502 var v = 1; 3502 var v = 1;
3503 v = 2; 3503 v = 2;
3504 }'''); 3504 }''');
3505 assertErrors(source, [HintCode.UNUSED_LOCAL_VARIABLE]); 3505 await assertErrors(source, [HintCode.UNUSED_LOCAL_VARIABLE]);
3506 verify([source]); 3506 verify([source]);
3507 } 3507 }
3508 3508
3509 void test_unusedLocalVariable_inMethod() { 3509 test_unusedLocalVariable_inMethod() async {
3510 enableUnusedLocalVariable = true; 3510 enableUnusedLocalVariable = true;
3511 Source source = addSource(r''' 3511 Source source = addSource(r'''
3512 class A { 3512 class A {
3513 foo() { 3513 foo() {
3514 var v = 1; 3514 var v = 1;
3515 v = 2; 3515 v = 2;
3516 } 3516 }
3517 }'''); 3517 }''');
3518 assertErrors(source, [HintCode.UNUSED_LOCAL_VARIABLE]); 3518 await assertErrors(source, [HintCode.UNUSED_LOCAL_VARIABLE]);
3519 verify([source]); 3519 verify([source]);
3520 } 3520 }
3521 3521
3522 void test_unusedLocalVariable_isInvoked() { 3522 test_unusedLocalVariable_isInvoked() async {
3523 enableUnusedLocalVariable = true; 3523 enableUnusedLocalVariable = true;
3524 Source source = addSource(r''' 3524 Source source = addSource(r'''
3525 typedef Foo(); 3525 typedef Foo();
3526 main() { 3526 main() {
3527 Foo foo; 3527 Foo foo;
3528 foo(); 3528 foo();
3529 }'''); 3529 }''');
3530 assertErrors(source); 3530 await assertErrors(source);
3531 verify([source]); 3531 verify([source]);
3532 } 3532 }
3533 3533
3534 void test_unusedLocalVariable_isRead_notUsed_compoundAssign() { 3534 test_unusedLocalVariable_isRead_notUsed_compoundAssign() async {
3535 enableUnusedLocalVariable = true; 3535 enableUnusedLocalVariable = true;
3536 Source source = addSource(r''' 3536 Source source = addSource(r'''
3537 main() { 3537 main() {
3538 var v = 1; 3538 var v = 1;
3539 v += 2; 3539 v += 2;
3540 }'''); 3540 }''');
3541 assertErrors(source, [HintCode.UNUSED_LOCAL_VARIABLE]); 3541 await assertErrors(source, [HintCode.UNUSED_LOCAL_VARIABLE]);
3542 verify([source]); 3542 verify([source]);
3543 } 3543 }
3544 3544
3545 void test_unusedLocalVariable_isRead_notUsed_postfixExpr() { 3545 test_unusedLocalVariable_isRead_notUsed_postfixExpr() async {
3546 enableUnusedLocalVariable = true; 3546 enableUnusedLocalVariable = true;
3547 Source source = addSource(r''' 3547 Source source = addSource(r'''
3548 main() { 3548 main() {
3549 var v = 1; 3549 var v = 1;
3550 v++; 3550 v++;
3551 }'''); 3551 }''');
3552 assertErrors(source, [HintCode.UNUSED_LOCAL_VARIABLE]); 3552 await assertErrors(source, [HintCode.UNUSED_LOCAL_VARIABLE]);
3553 verify([source]); 3553 verify([source]);
3554 } 3554 }
3555 3555
3556 void test_unusedLocalVariable_isRead_notUsed_prefixExpr() { 3556 test_unusedLocalVariable_isRead_notUsed_prefixExpr() async {
3557 enableUnusedLocalVariable = true; 3557 enableUnusedLocalVariable = true;
3558 Source source = addSource(r''' 3558 Source source = addSource(r'''
3559 main() { 3559 main() {
3560 var v = 1; 3560 var v = 1;
3561 ++v; 3561 ++v;
3562 }'''); 3562 }''');
3563 assertErrors(source, [HintCode.UNUSED_LOCAL_VARIABLE]); 3563 await assertErrors(source, [HintCode.UNUSED_LOCAL_VARIABLE]);
3564 verify([source]); 3564 verify([source]);
3565 } 3565 }
3566 3566
3567 void test_unusedLocalVariable_isRead_usedArgument() { 3567 test_unusedLocalVariable_isRead_usedArgument() async {
3568 enableUnusedLocalVariable = true; 3568 enableUnusedLocalVariable = true;
3569 Source source = addSource(r''' 3569 Source source = addSource(r'''
3570 main() { 3570 main() {
3571 var v = 1; 3571 var v = 1;
3572 print(++v); 3572 print(++v);
3573 } 3573 }
3574 print(x) {}'''); 3574 print(x) {}''');
3575 assertErrors(source); 3575 await assertErrors(source);
3576 verify([source]); 3576 verify([source]);
3577 } 3577 }
3578 3578
3579 void test_unusedLocalVariable_isRead_usedInvocationTarget() { 3579 test_unusedLocalVariable_isRead_usedInvocationTarget() async {
3580 enableUnusedLocalVariable = true; 3580 enableUnusedLocalVariable = true;
3581 Source source = addSource(r''' 3581 Source source = addSource(r'''
3582 class A { 3582 class A {
3583 foo() {} 3583 foo() {}
3584 } 3584 }
3585 main() { 3585 main() {
3586 var a = new A(); 3586 var a = new A();
3587 a.foo(); 3587 a.foo();
3588 } 3588 }
3589 '''); 3589 ''');
3590 assertErrors(source); 3590 await assertErrors(source);
3591 verify([source]); 3591 verify([source]);
3592 } 3592 }
3593 3593
3594 void test_unusedShownName() { 3594 test_unusedShownName() async {
3595 Source source = addSource(r''' 3595 Source source = addSource(r'''
3596 library L; 3596 library L;
3597 import 'lib1.dart' show A, B; 3597 import 'lib1.dart' show A, B;
3598 A a;'''); 3598 A a;''');
3599 Source source2 = addNamedSource( 3599 Source source2 = addNamedSource(
3600 "/lib1.dart", 3600 "/lib1.dart",
3601 r''' 3601 r'''
3602 library lib1; 3602 library lib1;
3603 class A {} 3603 class A {}
3604 class B {}'''); 3604 class B {}''');
3605 assertErrors(source, [HintCode.UNUSED_SHOWN_NAME]); 3605 await assertErrors(source, [HintCode.UNUSED_SHOWN_NAME]);
3606 assertNoErrors(source2); 3606 await assertNoErrors(source2);
3607 verify([source, source2]); 3607 verify([source, source2]);
3608 } 3608 }
3609 3609
3610 void test_unusedShownName_as() { 3610 test_unusedShownName_as() async {
3611 Source source = addSource(r''' 3611 Source source = addSource(r'''
3612 library L; 3612 library L;
3613 import 'lib1.dart' as p show A, B; 3613 import 'lib1.dart' as p show A, B;
3614 p.A a;'''); 3614 p.A a;''');
3615 Source source2 = addNamedSource( 3615 Source source2 = addNamedSource(
3616 "/lib1.dart", 3616 "/lib1.dart",
3617 r''' 3617 r'''
3618 library lib1; 3618 library lib1;
3619 class A {} 3619 class A {}
3620 class B {}'''); 3620 class B {}''');
3621 assertErrors(source, [HintCode.UNUSED_SHOWN_NAME]); 3621 await assertErrors(source, [HintCode.UNUSED_SHOWN_NAME]);
3622 assertNoErrors(source2); 3622 await assertNoErrors(source2);
3623 verify([source, source2]); 3623 verify([source, source2]);
3624 } 3624 }
3625 3625
3626 void test_unusedShownName_duplicates() { 3626 test_unusedShownName_duplicates() async {
3627 Source source = addSource(r''' 3627 Source source = addSource(r'''
3628 library L; 3628 library L;
3629 import 'lib1.dart' show A, B; 3629 import 'lib1.dart' show A, B;
3630 import 'lib1.dart' show C, D; 3630 import 'lib1.dart' show C, D;
3631 A a; 3631 A a;
3632 C c;'''); 3632 C c;''');
3633 Source source2 = addNamedSource( 3633 Source source2 = addNamedSource(
3634 "/lib1.dart", 3634 "/lib1.dart",
3635 r''' 3635 r'''
3636 library lib1; 3636 library lib1;
3637 class A {} 3637 class A {}
3638 class B {} 3638 class B {}
3639 class C {} 3639 class C {}
3640 class D {}'''); 3640 class D {}''');
3641 assertErrors( 3641 await assertErrors(
3642 source, [HintCode.UNUSED_SHOWN_NAME, HintCode.UNUSED_SHOWN_NAME]); 3642 source, [HintCode.UNUSED_SHOWN_NAME, HintCode.UNUSED_SHOWN_NAME]);
3643 assertNoErrors(source2); 3643 await assertNoErrors(source2);
3644 verify([source, source2]); 3644 verify([source, source2]);
3645 } 3645 }
3646 3646
3647 void test_unusedShownName_topLevelVariable() { 3647 test_unusedShownName_topLevelVariable() async {
3648 Source source = addSource(r''' 3648 Source source = addSource(r'''
3649 library L; 3649 library L;
3650 import 'lib1.dart' show var1, var2; 3650 import 'lib1.dart' show var1, var2;
3651 import 'lib1.dart' show var3, var4; 3651 import 'lib1.dart' show var3, var4;
3652 int a = var1; 3652 int a = var1;
3653 int b = var2; 3653 int b = var2;
3654 int c = var3;'''); 3654 int c = var3;''');
3655 Source source2 = addNamedSource( 3655 Source source2 = addNamedSource(
3656 "/lib1.dart", 3656 "/lib1.dart",
3657 r''' 3657 r'''
3658 library lib1; 3658 library lib1;
3659 const int var1 = 1; 3659 const int var1 = 1;
3660 const int var2 = 2; 3660 const int var2 = 2;
3661 const int var3 = 3; 3661 const int var3 = 3;
3662 const int var4 = 4;'''); 3662 const int var4 = 4;''');
3663 assertErrors(source, [HintCode.UNUSED_SHOWN_NAME]); 3663 await assertErrors(source, [HintCode.UNUSED_SHOWN_NAME]);
3664 assertNoErrors(source2); 3664 await assertNoErrors(source2);
3665 verify([source, source2]); 3665 verify([source, source2]);
3666 } 3666 }
3667 3667
3668 void test_useOfVoidResult_assignmentExpression_function() { 3668 test_useOfVoidResult_assignmentExpression_function() async {
3669 Source source = addSource(r''' 3669 Source source = addSource(r'''
3670 void f() {} 3670 void f() {}
3671 class A { 3671 class A {
3672 n() { 3672 n() {
3673 var a; 3673 var a;
3674 a = f(); 3674 a = f();
3675 } 3675 }
3676 }'''); 3676 }''');
3677 assertErrors(source, [HintCode.USE_OF_VOID_RESULT]); 3677 await assertErrors(source, [HintCode.USE_OF_VOID_RESULT]);
3678 verify([source]); 3678 verify([source]);
3679 } 3679 }
3680 3680
3681 void test_useOfVoidResult_assignmentExpression_method() { 3681 test_useOfVoidResult_assignmentExpression_method() async {
3682 Source source = addSource(r''' 3682 Source source = addSource(r'''
3683 class A { 3683 class A {
3684 void m() {} 3684 void m() {}
3685 n() { 3685 n() {
3686 var a; 3686 var a;
3687 a = m(); 3687 a = m();
3688 } 3688 }
3689 }'''); 3689 }''');
3690 assertErrors(source, [HintCode.USE_OF_VOID_RESULT]); 3690 await assertErrors(source, [HintCode.USE_OF_VOID_RESULT]);
3691 verify([source]); 3691 verify([source]);
3692 } 3692 }
3693 3693
3694 void test_useOfVoidResult_inForLoop() { 3694 test_useOfVoidResult_inForLoop() async {
3695 Source source = addSource(r''' 3695 Source source = addSource(r'''
3696 class A { 3696 class A {
3697 void m() {} 3697 void m() {}
3698 n() { 3698 n() {
3699 for(var a = m();;) {} 3699 for(var a = m();;) {}
3700 } 3700 }
3701 }'''); 3701 }''');
3702 assertErrors(source, [HintCode.USE_OF_VOID_RESULT]); 3702 await assertErrors(source, [HintCode.USE_OF_VOID_RESULT]);
3703 verify([source]); 3703 verify([source]);
3704 } 3704 }
3705 3705
3706 void test_useOfVoidResult_variableDeclaration_function() { 3706 test_useOfVoidResult_variableDeclaration_function() async {
3707 Source source = addSource(r''' 3707 Source source = addSource(r'''
3708 void f() {} 3708 void f() {}
3709 class A { 3709 class A {
3710 n() { 3710 n() {
3711 var a = f(); 3711 var a = f();
3712 } 3712 }
3713 }'''); 3713 }''');
3714 assertErrors(source, [HintCode.USE_OF_VOID_RESULT]); 3714 await assertErrors(source, [HintCode.USE_OF_VOID_RESULT]);
3715 verify([source]); 3715 verify([source]);
3716 } 3716 }
3717 3717
3718 void test_useOfVoidResult_variableDeclaration_method() { 3718 test_useOfVoidResult_variableDeclaration_method() async {
3719 Source source = addSource(r''' 3719 Source source = addSource(r'''
3720 class A { 3720 class A {
3721 void m() {} 3721 void m() {}
3722 n() { 3722 n() {
3723 var a = m(); 3723 var a = m();
3724 } 3724 }
3725 }'''); 3725 }''');
3726 assertErrors(source, [HintCode.USE_OF_VOID_RESULT]); 3726 await assertErrors(source, [HintCode.USE_OF_VOID_RESULT]);
3727 verify([source]); 3727 verify([source]);
3728 } 3728 }
3729 3729
3730 void test_useOfVoidResult_variableDeclaration_method2() { 3730 test_useOfVoidResult_variableDeclaration_method2() async {
3731 Source source = addSource(r''' 3731 Source source = addSource(r'''
3732 class A { 3732 class A {
3733 void m() {} 3733 void m() {}
3734 n() { 3734 n() {
3735 var a = m(), b = m(); 3735 var a = m(), b = m();
3736 } 3736 }
3737 }'''); 3737 }''');
3738 assertErrors( 3738 await assertErrors(
3739 source, [HintCode.USE_OF_VOID_RESULT, HintCode.USE_OF_VOID_RESULT]); 3739 source, [HintCode.USE_OF_VOID_RESULT, HintCode.USE_OF_VOID_RESULT]);
3740 verify([source]); 3740 verify([source]);
3741 } 3741 }
3742 } 3742 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698