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

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

Issue 2626653002: Remove computeLibrarySourceErrors(). (Closed)
Patch Set: Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library analyzer.test.generated.non_error_resolver_test; 5 library analyzer.test.generated.non_error_resolver_test;
6 6
7 import 'package:analyzer/dart/ast/ast.dart'; 7 import 'package:analyzer/dart/ast/ast.dart';
8 import 'package:analyzer/dart/ast/standard_resolution_map.dart'; 8 import 'package:analyzer/dart/ast/standard_resolution_map.dart';
9 import 'package:analyzer/dart/element/element.dart'; 9 import 'package:analyzer/dart/element/element.dart';
10 import 'package:analyzer/error/error.dart'; 10 import 'package:analyzer/error/error.dart';
(...skipping 14 matching lines...) Expand all
25 } 25 }
26 26
27 @reflectiveTest 27 @reflectiveTest
28 class NonErrorResolverTest extends ResolverTestCase { 28 class NonErrorResolverTest extends ResolverTestCase {
29 void fail_undefinedEnumConstant() { 29 void fail_undefinedEnumConstant() {
30 Source source = addSource(r''' 30 Source source = addSource(r'''
31 enum E { ONE } 31 enum E { ONE }
32 E e() { 32 E e() {
33 return E.TWO; 33 return E.TWO;
34 }'''); 34 }''');
35 computeLibrarySourceErrors(source);
36 assertNoErrors(source); 35 assertNoErrors(source);
37 verify([source]); 36 verify([source]);
38 } 37 }
39 38
40 void 39 void
41 test_abstractSuperMemberReference_superHasConcrete_mixinHasAbstract_method () { 40 test_abstractSuperMemberReference_superHasConcrete_mixinHasAbstract_method () {
42 Source source = addSource(''' 41 Source source = addSource('''
43 class A { 42 class A {
44 void method() {} 43 void method() {}
45 } 44 }
46 45
47 abstract class B { 46 abstract class B {
48 void method(); 47 void method();
49 } 48 }
50 49
51 class C extends A with B { 50 class C extends A with B {
52 void method() { 51 void method() {
53 super.method(); 52 super.method();
54 } 53 }
55 } 54 }
56 '''); 55 ''');
57 computeLibrarySourceErrors(source);
58 assertNoErrors(source); 56 assertNoErrors(source);
59 verify([source]); 57 verify([source]);
60 } 58 }
61 59
62 void test_abstractSuperMemberReference_superHasNoSuchMethod() { 60 void test_abstractSuperMemberReference_superHasNoSuchMethod() {
63 Source source = addSource(''' 61 Source source = addSource('''
64 abstract class A { 62 abstract class A {
65 int m(); 63 int m();
66 noSuchMethod(_) => 42; 64 noSuchMethod(_) => 42;
67 } 65 }
68 66
69 class B extends A { 67 class B extends A {
70 int m() => super.m(); 68 int m() => super.m();
71 } 69 }
72 '''); 70 ''');
73 computeLibrarySourceErrors(source);
74 assertNoErrors(source); 71 assertNoErrors(source);
75 verify([source]); 72 verify([source]);
76 } 73 }
77 74
78 void test_abstractSuperMemberReference_superSuperHasConcrete_getter() { 75 void test_abstractSuperMemberReference_superSuperHasConcrete_getter() {
79 Source source = addSource(''' 76 Source source = addSource('''
80 abstract class A { 77 abstract class A {
81 int get m => 0; 78 int get m => 0;
82 } 79 }
83 80
84 abstract class B extends A { 81 abstract class B extends A {
85 int get m; 82 int get m;
86 } 83 }
87 84
88 class C extends B { 85 class C extends B {
89 int get m => super.m; 86 int get m => super.m;
90 } 87 }
91 '''); 88 ''');
92 computeLibrarySourceErrors(source);
93 assertNoErrors(source); 89 assertNoErrors(source);
94 verify([source]); 90 verify([source]);
95 } 91 }
96 92
97 void test_abstractSuperMemberReference_superSuperHasConcrete_method() { 93 void test_abstractSuperMemberReference_superSuperHasConcrete_method() {
98 Source source = addSource(''' 94 Source source = addSource('''
99 void main() { 95 void main() {
100 print(new C().m()); 96 print(new C().m());
101 } 97 }
102 98
103 abstract class A { 99 abstract class A {
104 int m() => 0; 100 int m() => 0;
105 } 101 }
106 102
107 abstract class B extends A { 103 abstract class B extends A {
108 int m(); 104 int m();
109 } 105 }
110 106
111 class C extends B { 107 class C extends B {
112 int m() => super.m(); 108 int m() => super.m();
113 } 109 }
114 '''); 110 ''');
115 computeLibrarySourceErrors(source);
116 assertNoErrors(source); 111 assertNoErrors(source);
117 verify([source]); 112 verify([source]);
118 } 113 }
119 114
120 void test_abstractSuperMemberReference_superSuperHasConcrete_setter() { 115 void test_abstractSuperMemberReference_superSuperHasConcrete_setter() {
121 Source source = addSource(''' 116 Source source = addSource('''
122 abstract class A { 117 abstract class A {
123 void set m(int v) {} 118 void set m(int v) {}
124 } 119 }
125 120
126 abstract class B extends A { 121 abstract class B extends A {
127 void set m(int v); 122 void set m(int v);
128 } 123 }
129 124
130 class C extends B { 125 class C extends B {
131 void set m(int v) { 126 void set m(int v) {
132 super.m = 0; 127 super.m = 0;
133 } 128 }
134 } 129 }
135 '''); 130 ''');
136 computeLibrarySourceErrors(source);
137 assertNoErrors(source); 131 assertNoErrors(source);
138 verify([source]); 132 verify([source]);
139 } 133 }
140 134
141 void test_ambiguousExport() { 135 void test_ambiguousExport() {
142 Source source = addSource(r''' 136 Source source = addSource(r'''
143 library L; 137 library L;
144 export 'lib1.dart'; 138 export 'lib1.dart';
145 export 'lib2.dart';'''); 139 export 'lib2.dart';''');
146 addNamedSource( 140 addNamedSource(
147 "/lib1.dart", 141 "/lib1.dart",
148 r''' 142 r'''
149 library lib1; 143 library lib1;
150 class M {}'''); 144 class M {}''');
151 addNamedSource( 145 addNamedSource(
152 "/lib2.dart", 146 "/lib2.dart",
153 r''' 147 r'''
154 library lib2; 148 library lib2;
155 class N {}'''); 149 class N {}''');
156 computeLibrarySourceErrors(source);
157 assertNoErrors(source); 150 assertNoErrors(source);
158 verify([source]); 151 verify([source]);
159 } 152 }
160 153
161 void test_ambiguousExport_combinators_hide() { 154 void test_ambiguousExport_combinators_hide() {
162 Source source = addSource(r''' 155 Source source = addSource(r'''
163 library L; 156 library L;
164 export 'lib1.dart'; 157 export 'lib1.dart';
165 export 'lib2.dart' hide B;'''); 158 export 'lib2.dart' hide B;''');
166 addNamedSource( 159 addNamedSource(
167 "/lib1.dart", 160 "/lib1.dart",
168 r''' 161 r'''
169 library L1; 162 library L1;
170 class A {} 163 class A {}
171 class B {}'''); 164 class B {}''');
172 addNamedSource( 165 addNamedSource(
173 "/lib2.dart", 166 "/lib2.dart",
174 r''' 167 r'''
175 library L2; 168 library L2;
176 class B {} 169 class B {}
177 class C {}'''); 170 class C {}''');
178 computeLibrarySourceErrors(source);
179 assertNoErrors(source); 171 assertNoErrors(source);
180 verify([source]); 172 verify([source]);
181 } 173 }
182 174
183 void test_ambiguousExport_combinators_show() { 175 void test_ambiguousExport_combinators_show() {
184 Source source = addSource(r''' 176 Source source = addSource(r'''
185 library L; 177 library L;
186 export 'lib1.dart'; 178 export 'lib1.dart';
187 export 'lib2.dart' show C;'''); 179 export 'lib2.dart' show C;''');
188 addNamedSource( 180 addNamedSource(
189 "/lib1.dart", 181 "/lib1.dart",
190 r''' 182 r'''
191 library L1; 183 library L1;
192 class A {} 184 class A {}
193 class B {}'''); 185 class B {}''');
194 addNamedSource( 186 addNamedSource(
195 "/lib2.dart", 187 "/lib2.dart",
196 r''' 188 r'''
197 library L2; 189 library L2;
198 class B {} 190 class B {}
199 class C {}'''); 191 class C {}''');
200 computeLibrarySourceErrors(source);
201 assertNoErrors(source); 192 assertNoErrors(source);
202 verify([source]); 193 verify([source]);
203 } 194 }
204 195
205 void test_ambiguousExport_sameDeclaration() { 196 void test_ambiguousExport_sameDeclaration() {
206 Source source = addSource(r''' 197 Source source = addSource(r'''
207 library L; 198 library L;
208 export 'lib.dart'; 199 export 'lib.dart';
209 export 'lib.dart';'''); 200 export 'lib.dart';''');
210 addNamedSource( 201 addNamedSource(
211 "/lib.dart", 202 "/lib.dart",
212 r''' 203 r'''
213 library lib; 204 library lib;
214 class N {}'''); 205 class N {}''');
215 computeLibrarySourceErrors(source);
216 assertNoErrors(source); 206 assertNoErrors(source);
217 verify([source]); 207 verify([source]);
218 } 208 }
219 209
220 void test_ambiguousImport_hideCombinator() { 210 void test_ambiguousImport_hideCombinator() {
221 Source source = addSource(r''' 211 Source source = addSource(r'''
222 import 'lib1.dart'; 212 import 'lib1.dart';
223 import 'lib2.dart'; 213 import 'lib2.dart';
224 import 'lib3.dart' hide N; 214 import 'lib3.dart' hide N;
225 main() { 215 main() {
(...skipping 12 matching lines...) Expand all
238 r''' 228 r'''
239 library lib2; 229 library lib2;
240 class N {} 230 class N {}
241 class N2 {}'''); 231 class N2 {}''');
242 addNamedSource( 232 addNamedSource(
243 "/lib3.dart", 233 "/lib3.dart",
244 r''' 234 r'''
245 library lib3; 235 library lib3;
246 class N {} 236 class N {}
247 class N3 {}'''); 237 class N3 {}''');
248 computeLibrarySourceErrors(source);
249 assertNoErrors(source); 238 assertNoErrors(source);
250 } 239 }
251 240
252 void test_ambiguousImport_showCombinator() { 241 void test_ambiguousImport_showCombinator() {
253 Source source = addSource(r''' 242 Source source = addSource(r'''
254 import 'lib1.dart'; 243 import 'lib1.dart';
255 import 'lib2.dart' show N, N2; 244 import 'lib2.dart' show N, N2;
256 main() { 245 main() {
257 new N1(); 246 new N1();
258 new N2(); 247 new N2();
259 }'''); 248 }''');
260 addNamedSource( 249 addNamedSource(
261 "/lib1.dart", 250 "/lib1.dart",
262 r''' 251 r'''
263 library lib1; 252 library lib1;
264 class N {} 253 class N {}
265 class N1 {}'''); 254 class N1 {}''');
266 addNamedSource( 255 addNamedSource(
267 "/lib2.dart", 256 "/lib2.dart",
268 r''' 257 r'''
269 library lib2; 258 library lib2;
270 class N {} 259 class N {}
271 class N2 {}'''); 260 class N2 {}''');
272 computeLibrarySourceErrors(source);
273 assertErrors(source, [HintCode.UNUSED_SHOWN_NAME]); 261 assertErrors(source, [HintCode.UNUSED_SHOWN_NAME]);
274 } 262 }
275 263
276 void test_annotated_partOfDeclaration() { 264 void test_annotated_partOfDeclaration() {
277 Source source = addSource('library L; part "part.dart";'); 265 Source source = addSource('library L; part "part.dart";');
278 addNamedSource('/part.dart', '@deprecated part of L;'); 266 addNamedSource('/part.dart', '@deprecated part of L;');
279 computeLibrarySourceErrors(source);
280 assertNoErrors(source); 267 assertNoErrors(source);
281 verify([source]); 268 verify([source]);
282 } 269 }
283 270
284 void test_argumentTypeNotAssignable_classWithCall_Function() { 271 void test_argumentTypeNotAssignable_classWithCall_Function() {
285 Source source = addSource(r''' 272 Source source = addSource(r'''
286 caller(Function callee) { 273 caller(Function callee) {
287 callee(); 274 callee();
288 } 275 }
289 276
290 class CallMeBack { 277 class CallMeBack {
291 call() => 0; 278 call() => 0;
292 } 279 }
293 280
294 main() { 281 main() {
295 caller(new CallMeBack()); 282 caller(new CallMeBack());
296 }'''); 283 }''');
297 computeLibrarySourceErrors(source);
298 assertNoErrors(source); 284 assertNoErrors(source);
299 verify([source]); 285 verify([source]);
300 } 286 }
301 287
302 void test_argumentTypeNotAssignable_fieldFormalParameterElement_member() { 288 void test_argumentTypeNotAssignable_fieldFormalParameterElement_member() {
303 Source source = addSource(r''' 289 Source source = addSource(r'''
304 class ObjectSink<T> { 290 class ObjectSink<T> {
305 void sink(T object) { 291 void sink(T object) {
306 new TimestampedObject<T>(object); 292 new TimestampedObject<T>(object);
307 } 293 }
308 } 294 }
309 class TimestampedObject<E> { 295 class TimestampedObject<E> {
310 E object2; 296 E object2;
311 TimestampedObject(this.object2); 297 TimestampedObject(this.object2);
312 }'''); 298 }''');
313 computeLibrarySourceErrors(source);
314 assertNoErrors(source); 299 assertNoErrors(source);
315 verify([source]); 300 verify([source]);
316 } 301 }
317 302
318 void test_argumentTypeNotAssignable_invocation_functionParameter_generic() { 303 void test_argumentTypeNotAssignable_invocation_functionParameter_generic() {
319 Source source = addSource(r''' 304 Source source = addSource(r'''
320 class A<K> { 305 class A<K> {
321 m(f(K k), K v) { 306 m(f(K k), K v) {
322 f(v); 307 f(v);
323 } 308 }
324 }'''); 309 }''');
325 computeLibrarySourceErrors(source);
326 assertNoErrors(source); 310 assertNoErrors(source);
327 verify([source]); 311 verify([source]);
328 } 312 }
329 313
330 void test_argumentTypeNotAssignable_invocation_typedef_generic() { 314 void test_argumentTypeNotAssignable_invocation_typedef_generic() {
331 Source source = addSource(r''' 315 Source source = addSource(r'''
332 typedef A<T>(T p); 316 typedef A<T>(T p);
333 f(A<int> a) { 317 f(A<int> a) {
334 a(1); 318 a(1);
335 }'''); 319 }''');
336 computeLibrarySourceErrors(source);
337 assertNoErrors(source); 320 assertNoErrors(source);
338 verify([source]); 321 verify([source]);
339 } 322 }
340 323
341 void test_argumentTypeNotAssignable_Object_Function() { 324 void test_argumentTypeNotAssignable_Object_Function() {
342 Source source = addSource(r''' 325 Source source = addSource(r'''
343 main() { 326 main() {
344 process(() {}); 327 process(() {});
345 } 328 }
346 process(Object x) {}'''); 329 process(Object x) {}''');
347 computeLibrarySourceErrors(source);
348 assertNoErrors(source); 330 assertNoErrors(source);
349 verify([source]); 331 verify([source]);
350 } 332 }
351 333
352 void test_argumentTypeNotAssignable_typedef_local() { 334 void test_argumentTypeNotAssignable_typedef_local() {
353 Source source = addSource(r''' 335 Source source = addSource(r'''
354 typedef A(int p1, String p2); 336 typedef A(int p1, String p2);
355 A getA() => null; 337 A getA() => null;
356 f() { 338 f() {
357 A a = getA(); 339 A a = getA();
358 a(1, '2'); 340 a(1, '2');
359 }'''); 341 }''');
360 computeLibrarySourceErrors(source);
361 assertNoErrors(source); 342 assertNoErrors(source);
362 verify([source]); 343 verify([source]);
363 } 344 }
364 345
365 void test_argumentTypeNotAssignable_typedef_parameter() { 346 void test_argumentTypeNotAssignable_typedef_parameter() {
366 Source source = addSource(r''' 347 Source source = addSource(r'''
367 typedef A(int p1, String p2); 348 typedef A(int p1, String p2);
368 f(A a) { 349 f(A a) {
369 a(1, '2'); 350 a(1, '2');
370 }'''); 351 }''');
371 computeLibrarySourceErrors(source);
372 assertNoErrors(source); 352 assertNoErrors(source);
373 verify([source]); 353 verify([source]);
374 } 354 }
375 355
376 void test_assert_with_message_await() { 356 void test_assert_with_message_await() {
377 Source source = addSource(''' 357 Source source = addSource('''
378 import 'dart:async'; 358 import 'dart:async';
379 f() async { 359 f() async {
380 assert(false, await g()); 360 assert(false, await g());
381 } 361 }
382 Future<String> g() => null; 362 Future<String> g() => null;
383 '''); 363 ''');
384 computeLibrarySourceErrors(source);
385 assertNoErrors(source); 364 assertNoErrors(source);
386 verify([source]); 365 verify([source]);
387 } 366 }
388 367
389 void test_assert_with_message_dynamic() { 368 void test_assert_with_message_dynamic() {
390 Source source = addSource(''' 369 Source source = addSource('''
391 f() { 370 f() {
392 assert(false, g()); 371 assert(false, g());
393 } 372 }
394 g() => null; 373 g() => null;
395 '''); 374 ''');
396 computeLibrarySourceErrors(source);
397 assertNoErrors(source); 375 assertNoErrors(source);
398 verify([source]); 376 verify([source]);
399 } 377 }
400 378
401 void test_assert_with_message_non_string() { 379 void test_assert_with_message_non_string() {
402 Source source = addSource(''' 380 Source source = addSource('''
403 f() { 381 f() {
404 assert(false, 3); 382 assert(false, 3);
405 } 383 }
406 '''); 384 ''');
407 computeLibrarySourceErrors(source);
408 assertNoErrors(source); 385 assertNoErrors(source);
409 verify([source]); 386 verify([source]);
410 } 387 }
411 388
412 void test_assert_with_message_null() { 389 void test_assert_with_message_null() {
413 Source source = addSource(''' 390 Source source = addSource('''
414 f() { 391 f() {
415 assert(false, null); 392 assert(false, null);
416 } 393 }
417 '''); 394 ''');
418 computeLibrarySourceErrors(source);
419 assertNoErrors(source); 395 assertNoErrors(source);
420 verify([source]); 396 verify([source]);
421 } 397 }
422 398
423 void test_assert_with_message_string() { 399 void test_assert_with_message_string() {
424 Source source = addSource(''' 400 Source source = addSource('''
425 f() { 401 f() {
426 assert(false, 'message'); 402 assert(false, 'message');
427 } 403 }
428 '''); 404 ''');
429 computeLibrarySourceErrors(source);
430 assertNoErrors(source); 405 assertNoErrors(source);
431 verify([source]); 406 verify([source]);
432 } 407 }
433 408
434 void test_assert_with_message_suppresses_unused_var_hint() { 409 void test_assert_with_message_suppresses_unused_var_hint() {
435 Source source = addSource(''' 410 Source source = addSource('''
436 f() { 411 f() {
437 String message = 'msg'; 412 String message = 'msg';
438 assert(true, message); 413 assert(true, message);
439 } 414 }
440 '''); 415 ''');
441 computeLibrarySourceErrors(source);
442 assertNoErrors(source); 416 assertNoErrors(source);
443 verify([source]); 417 verify([source]);
444 } 418 }
445 419
446 void test_assignability_function_expr_rettype_from_typedef_cls() { 420 void test_assignability_function_expr_rettype_from_typedef_cls() {
447 // In the code below, the type of (() => f()) has a return type which is 421 // In the code below, the type of (() => f()) has a return type which is
448 // a class, and that class is inferred from the return type of the typedef 422 // a class, and that class is inferred from the return type of the typedef
449 // F. 423 // F.
450 Source source = addSource(''' 424 Source source = addSource('''
451 class C {} 425 class C {}
452 typedef C F(); 426 typedef C F();
453 F f; 427 F f;
454 main() { 428 main() {
455 F f2 = (() => f()); 429 F f2 = (() => f());
456 } 430 }
457 '''); 431 ''');
458 computeLibrarySourceErrors(source);
459 assertNoErrors(source); 432 assertNoErrors(source);
460 verify([source]); 433 verify([source]);
461 } 434 }
462 435
463 void test_assignability_function_expr_rettype_from_typedef_typedef() { 436 void test_assignability_function_expr_rettype_from_typedef_typedef() {
464 // In the code below, the type of (() => f()) has a return type which is 437 // In the code below, the type of (() => f()) has a return type which is
465 // a typedef, and that typedef is inferred from the return type of the 438 // a typedef, and that typedef is inferred from the return type of the
466 // typedef F. 439 // typedef F.
467 Source source = addSource(''' 440 Source source = addSource('''
468 typedef G F(); 441 typedef G F();
469 typedef G(); 442 typedef G();
470 F f; 443 F f;
471 main() { 444 main() {
472 F f2 = (() => f()); 445 F f2 = (() => f());
473 } 446 }
474 '''); 447 ''');
475 computeLibrarySourceErrors(source);
476 assertNoErrors(source); 448 assertNoErrors(source);
477 verify([source]); 449 verify([source]);
478 } 450 }
479 451
480 void test_assignmentToFinal_prefixNegate() { 452 void test_assignmentToFinal_prefixNegate() {
481 Source source = addSource(r''' 453 Source source = addSource(r'''
482 f() { 454 f() {
483 final x = 0; 455 final x = 0;
484 -x; 456 -x;
485 }'''); 457 }''');
486 computeLibrarySourceErrors(source);
487 assertNoErrors(source); 458 assertNoErrors(source);
488 verify([source]); 459 verify([source]);
489 } 460 }
490 461
491 void test_assignmentToFinalNoSetter_prefixedIdentifier() { 462 void test_assignmentToFinalNoSetter_prefixedIdentifier() {
492 Source source = addSource(r''' 463 Source source = addSource(r'''
493 class A { 464 class A {
494 int get x => 0; 465 int get x => 0;
495 set x(v) {} 466 set x(v) {}
496 } 467 }
497 main() { 468 main() {
498 A a = new A(); 469 A a = new A();
499 a.x = 0; 470 a.x = 0;
500 }'''); 471 }''');
501 computeLibrarySourceErrors(source);
502 assertNoErrors(source); 472 assertNoErrors(source);
503 verify([source]); 473 verify([source]);
504 } 474 }
505 475
506 void test_assignmentToFinalNoSetter_propertyAccess() { 476 void test_assignmentToFinalNoSetter_propertyAccess() {
507 Source source = addSource(r''' 477 Source source = addSource(r'''
508 class A { 478 class A {
509 int get x => 0; 479 int get x => 0;
510 set x(v) {} 480 set x(v) {}
511 } 481 }
512 class B { 482 class B {
513 static A a; 483 static A a;
514 } 484 }
515 main() { 485 main() {
516 B.a.x = 0; 486 B.a.x = 0;
517 }'''); 487 }''');
518 computeLibrarySourceErrors(source);
519 assertNoErrors(source); 488 assertNoErrors(source);
520 verify([source]); 489 verify([source]);
521 } 490 }
522 491
523 void test_assignmentToFinals_importWithPrefix() { 492 void test_assignmentToFinals_importWithPrefix() {
524 Source source = addSource(r''' 493 Source source = addSource(r'''
525 library lib; 494 library lib;
526 import 'lib1.dart' as foo; 495 import 'lib1.dart' as foo;
527 main() { 496 main() {
528 foo.x = true; 497 foo.x = true;
529 }'''); 498 }''');
530 addNamedSource( 499 addNamedSource(
531 "/lib1.dart", 500 "/lib1.dart",
532 r''' 501 r'''
533 library lib1; 502 library lib1;
534 bool x = false;'''); 503 bool x = false;''');
535 computeLibrarySourceErrors(source);
536 assertNoErrors(source); 504 assertNoErrors(source);
537 verify([source]); 505 verify([source]);
538 } 506 }
539 507
540 void test_async_dynamic_with_return() { 508 void test_async_dynamic_with_return() {
541 Source source = addSource(''' 509 Source source = addSource('''
542 dynamic f() async { 510 dynamic f() async {
543 return; 511 return;
544 } 512 }
545 '''); 513 ''');
546 computeLibrarySourceErrors(source);
547 assertNoErrors(source); 514 assertNoErrors(source);
548 verify([source]); 515 verify([source]);
549 } 516 }
550 517
551 void test_async_dynamic_with_return_value() { 518 void test_async_dynamic_with_return_value() {
552 Source source = addSource(''' 519 Source source = addSource('''
553 dynamic f() async { 520 dynamic f() async {
554 return 5; 521 return 5;
555 } 522 }
556 '''); 523 ''');
557 computeLibrarySourceErrors(source);
558 assertNoErrors(source); 524 assertNoErrors(source);
559 verify([source]); 525 verify([source]);
560 } 526 }
561 527
562 void test_async_dynamic_without_return() { 528 void test_async_dynamic_without_return() {
563 Source source = addSource(''' 529 Source source = addSource('''
564 dynamic f() async {} 530 dynamic f() async {}
565 '''); 531 ''');
566 computeLibrarySourceErrors(source);
567 assertNoErrors(source); 532 assertNoErrors(source);
568 verify([source]); 533 verify([source]);
569 } 534 }
570 535
571 void test_async_expression_function_type() { 536 void test_async_expression_function_type() {
572 Source source = addSource(''' 537 Source source = addSource('''
573 import 'dart:async'; 538 import 'dart:async';
574 typedef Future<int> F(int i); 539 typedef Future<int> F(int i);
575 main() { 540 main() {
576 F f = (int i) async => i; 541 F f = (int i) async => i;
577 } 542 }
578 '''); 543 ''');
579 computeLibrarySourceErrors(source);
580 assertNoErrors(source); 544 assertNoErrors(source);
581 verify([source]); 545 verify([source]);
582 } 546 }
583 547
584 void test_async_flattened() { 548 void test_async_flattened() {
585 Source source = addSource(''' 549 Source source = addSource('''
586 import 'dart:async'; 550 import 'dart:async';
587 typedef Future<int> CreatesFutureInt(); 551 typedef Future<int> CreatesFutureInt();
588 main() { 552 main() {
589 CreatesFutureInt createFutureInt = () async => f(); 553 CreatesFutureInt createFutureInt = () async => f();
590 Future<int> futureInt = createFutureInt(); 554 Future<int> futureInt = createFutureInt();
591 futureInt.then((int i) => print(i)); 555 futureInt.then((int i) => print(i));
592 } 556 }
593 Future<int> f() => null; 557 Future<int> f() => null;
594 '''); 558 ''');
595 computeLibrarySourceErrors(source);
596 assertNoErrors(source); 559 assertNoErrors(source);
597 verify([source]); 560 verify([source]);
598 } 561 }
599 562
600 void test_async_future_dynamic_with_return() { 563 void test_async_future_dynamic_with_return() {
601 Source source = addSource(''' 564 Source source = addSource('''
602 import 'dart:async'; 565 import 'dart:async';
603 Future<dynamic> f() async { 566 Future<dynamic> f() async {
604 return; 567 return;
605 } 568 }
606 '''); 569 ''');
607 computeLibrarySourceErrors(source);
608 assertNoErrors(source); 570 assertNoErrors(source);
609 verify([source]); 571 verify([source]);
610 } 572 }
611 573
612 void test_async_future_dynamic_with_return_value() { 574 void test_async_future_dynamic_with_return_value() {
613 Source source = addSource(''' 575 Source source = addSource('''
614 import 'dart:async'; 576 import 'dart:async';
615 Future<dynamic> f() async { 577 Future<dynamic> f() async {
616 return 5; 578 return 5;
617 } 579 }
618 '''); 580 ''');
619 computeLibrarySourceErrors(source);
620 assertNoErrors(source); 581 assertNoErrors(source);
621 verify([source]); 582 verify([source]);
622 } 583 }
623 584
624 void test_async_future_dynamic_without_return() { 585 void test_async_future_dynamic_without_return() {
625 Source source = addSource(''' 586 Source source = addSource('''
626 import 'dart:async'; 587 import 'dart:async';
627 Future<dynamic> f() async {} 588 Future<dynamic> f() async {}
628 '''); 589 ''');
629 computeLibrarySourceErrors(source);
630 assertNoErrors(source); 590 assertNoErrors(source);
631 verify([source]); 591 verify([source]);
632 } 592 }
633 593
634 void test_async_future_int_with_return_future_int() { 594 void test_async_future_int_with_return_future_int() {
635 Source source = addSource(''' 595 Source source = addSource('''
636 import 'dart:async'; 596 import 'dart:async';
637 Future<int> f() async { 597 Future<int> f() async {
638 return new Future<int>.value(5); 598 return new Future<int>.value(5);
639 } 599 }
640 '''); 600 ''');
641 computeLibrarySourceErrors(source);
642 assertNoErrors(source); 601 assertNoErrors(source);
643 verify([source]); 602 verify([source]);
644 } 603 }
645 604
646 void test_async_future_int_with_return_value() { 605 void test_async_future_int_with_return_value() {
647 Source source = addSource(''' 606 Source source = addSource('''
648 import 'dart:async'; 607 import 'dart:async';
649 Future<int> f() async { 608 Future<int> f() async {
650 return 5; 609 return 5;
651 } 610 }
652 '''); 611 ''');
653 computeLibrarySourceErrors(source);
654 assertNoErrors(source); 612 assertNoErrors(source);
655 verify([source]); 613 verify([source]);
656 } 614 }
657 615
658 void test_async_future_null_with_return() { 616 void test_async_future_null_with_return() {
659 Source source = addSource(''' 617 Source source = addSource('''
660 import 'dart:async'; 618 import 'dart:async';
661 Future<Null> f() async { 619 Future<Null> f() async {
662 return; 620 return;
663 } 621 }
664 '''); 622 ''');
665 computeLibrarySourceErrors(source);
666 assertNoErrors(source); 623 assertNoErrors(source);
667 verify([source]); 624 verify([source]);
668 } 625 }
669 626
670 void test_async_future_null_without_return() { 627 void test_async_future_null_without_return() {
671 Source source = addSource(''' 628 Source source = addSource('''
672 import 'dart:async'; 629 import 'dart:async';
673 Future<Null> f() async {} 630 Future<Null> f() async {}
674 '''); 631 ''');
675 computeLibrarySourceErrors(source);
676 assertNoErrors(source); 632 assertNoErrors(source);
677 verify([source]); 633 verify([source]);
678 } 634 }
679 635
680 void test_async_future_object_with_return() { 636 void test_async_future_object_with_return() {
681 Source source = addSource(''' 637 Source source = addSource('''
682 import 'dart:async'; 638 import 'dart:async';
683 Future<Object> f() async { 639 Future<Object> f() async {
684 return; 640 return;
685 } 641 }
686 '''); 642 ''');
687 computeLibrarySourceErrors(source);
688 assertNoErrors(source); 643 assertNoErrors(source);
689 verify([source]); 644 verify([source]);
690 } 645 }
691 646
692 void test_async_future_object_with_return_value() { 647 void test_async_future_object_with_return_value() {
693 Source source = addSource(''' 648 Source source = addSource('''
694 import 'dart:async'; 649 import 'dart:async';
695 Future<Object> f() async { 650 Future<Object> f() async {
696 return 5; 651 return 5;
697 } 652 }
698 '''); 653 ''');
699 computeLibrarySourceErrors(source);
700 assertNoErrors(source); 654 assertNoErrors(source);
701 verify([source]); 655 verify([source]);
702 } 656 }
703 657
704 void test_async_future_object_without_return() { 658 void test_async_future_object_without_return() {
705 Source source = addSource(''' 659 Source source = addSource('''
706 import 'dart:async'; 660 import 'dart:async';
707 Future<Object> f() async {} 661 Future<Object> f() async {}
708 '''); 662 ''');
709 computeLibrarySourceErrors(source);
710 assertNoErrors(source); 663 assertNoErrors(source);
711 verify([source]); 664 verify([source]);
712 } 665 }
713 666
714 void test_async_future_with_return() { 667 void test_async_future_with_return() {
715 Source source = addSource(''' 668 Source source = addSource('''
716 import 'dart:async'; 669 import 'dart:async';
717 Future f() async { 670 Future f() async {
718 return; 671 return;
719 } 672 }
720 '''); 673 ''');
721 computeLibrarySourceErrors(source);
722 assertNoErrors(source); 674 assertNoErrors(source);
723 verify([source]); 675 verify([source]);
724 } 676 }
725 677
726 void test_async_future_with_return_value() { 678 void test_async_future_with_return_value() {
727 Source source = addSource(''' 679 Source source = addSource('''
728 import 'dart:async'; 680 import 'dart:async';
729 Future f() async { 681 Future f() async {
730 return 5; 682 return 5;
731 } 683 }
732 '''); 684 ''');
733 computeLibrarySourceErrors(source);
734 assertNoErrors(source); 685 assertNoErrors(source);
735 verify([source]); 686 verify([source]);
736 } 687 }
737 688
738 void test_async_future_without_return() { 689 void test_async_future_without_return() {
739 Source source = addSource(''' 690 Source source = addSource('''
740 import 'dart:async'; 691 import 'dart:async';
741 Future f() async {} 692 Future f() async {}
742 '''); 693 ''');
743 computeLibrarySourceErrors(source);
744 assertNoErrors(source); 694 assertNoErrors(source);
745 verify([source]); 695 verify([source]);
746 } 696 }
747 697
748 void test_async_return_flattens_futures() { 698 void test_async_return_flattens_futures() {
749 Source source = addSource(''' 699 Source source = addSource('''
750 import 'dart:async'; 700 import 'dart:async';
751 Future<int> f() async { 701 Future<int> f() async {
752 return g(); 702 return g();
753 } 703 }
754 Future<Future<int>> g() => null; 704 Future<Future<int>> g() => null;
755 '''); 705 ''');
756 computeLibrarySourceErrors(source);
757 assertNoErrors(source); 706 assertNoErrors(source);
758 verify([source]); 707 verify([source]);
759 } 708 }
760 709
761 void test_async_with_return() { 710 void test_async_with_return() {
762 Source source = addSource(''' 711 Source source = addSource('''
763 f() async { 712 f() async {
764 return; 713 return;
765 } 714 }
766 '''); 715 ''');
767 computeLibrarySourceErrors(source);
768 assertNoErrors(source); 716 assertNoErrors(source);
769 verify([source]); 717 verify([source]);
770 } 718 }
771 719
772 void test_async_with_return_value() { 720 void test_async_with_return_value() {
773 Source source = addSource(''' 721 Source source = addSource('''
774 f() async { 722 f() async {
775 return 5; 723 return 5;
776 } 724 }
777 '''); 725 ''');
778 computeLibrarySourceErrors(source);
779 assertNoErrors(source); 726 assertNoErrors(source);
780 verify([source]); 727 verify([source]);
781 } 728 }
782 729
783 void test_async_without_return() { 730 void test_async_without_return() {
784 Source source = addSource(''' 731 Source source = addSource('''
785 f() async {} 732 f() async {}
786 '''); 733 ''');
787 computeLibrarySourceErrors(source);
788 assertNoErrors(source); 734 assertNoErrors(source);
789 verify([source]); 735 verify([source]);
790 } 736 }
791 737
792 void test_asyncForInWrongContext_async() { 738 void test_asyncForInWrongContext_async() {
793 Source source = addSource(r''' 739 Source source = addSource(r'''
794 f(list) async { 740 f(list) async {
795 await for (var e in list) { 741 await for (var e in list) {
796 } 742 }
797 }'''); 743 }''');
798 computeLibrarySourceErrors(source);
799 assertNoErrors(source); 744 assertNoErrors(source);
800 verify([source]); 745 verify([source]);
801 } 746 }
802 747
803 void test_asyncForInWrongContext_asyncStar() { 748 void test_asyncForInWrongContext_asyncStar() {
804 Source source = addSource(r''' 749 Source source = addSource(r'''
805 f(list) async* { 750 f(list) async* {
806 await for (var e in list) { 751 await for (var e in list) {
807 } 752 }
808 }'''); 753 }''');
809 computeLibrarySourceErrors(source);
810 assertNoErrors(source); 754 assertNoErrors(source);
811 verify([source]); 755 verify([source]);
812 } 756 }
813 757
814 void test_await_flattened() { 758 void test_await_flattened() {
815 Source source = addSource(''' 759 Source source = addSource('''
816 import 'dart:async'; 760 import 'dart:async';
817 Future<Future<int>> ffi() => null; 761 Future<Future<int>> ffi() => null;
818 f() async { 762 f() async {
819 int b = await ffi(); 763 int b = await ffi();
820 } 764 }
821 '''); 765 ''');
822 computeLibrarySourceErrors(source);
823 assertNoErrors(source); 766 assertNoErrors(source);
824 verify([source]); 767 verify([source]);
825 } 768 }
826 769
827 void test_await_simple() { 770 void test_await_simple() {
828 Source source = addSource(''' 771 Source source = addSource('''
829 import 'dart:async'; 772 import 'dart:async';
830 Future<int> fi() => null; 773 Future<int> fi() => null;
831 f() async { 774 f() async {
832 int a = await fi(); 775 int a = await fi();
833 } 776 }
834 '''); 777 ''');
835 computeLibrarySourceErrors(source);
836 assertNoErrors(source); 778 assertNoErrors(source);
837 verify([source]); 779 verify([source]);
838 } 780 }
839 781
840 void test_awaitInWrongContext_async() { 782 void test_awaitInWrongContext_async() {
841 Source source = addSource(r''' 783 Source source = addSource(r'''
842 f(x, y) async { 784 f(x, y) async {
843 return await x + await y; 785 return await x + await y;
844 }'''); 786 }''');
845 computeLibrarySourceErrors(source);
846 assertNoErrors(source); 787 assertNoErrors(source);
847 verify([source]); 788 verify([source]);
848 } 789 }
849 790
850 void test_awaitInWrongContext_asyncStar() { 791 void test_awaitInWrongContext_asyncStar() {
851 Source source = addSource(r''' 792 Source source = addSource(r'''
852 f(x, y) async* { 793 f(x, y) async* {
853 yield await x + await y; 794 yield await x + await y;
854 }'''); 795 }''');
855 computeLibrarySourceErrors(source);
856 assertNoErrors(source); 796 assertNoErrors(source);
857 verify([source]); 797 verify([source]);
858 } 798 }
859 799
860 void test_breakWithoutLabelInSwitch() { 800 void test_breakWithoutLabelInSwitch() {
861 Source source = addSource(r''' 801 Source source = addSource(r'''
862 class A { 802 class A {
863 void m(int i) { 803 void m(int i) {
864 switch (i) { 804 switch (i) {
865 case 0: 805 case 0:
866 break; 806 break;
867 } 807 }
868 } 808 }
869 }'''); 809 }''');
870 computeLibrarySourceErrors(source);
871 assertNoErrors(source); 810 assertNoErrors(source);
872 verify([source]); 811 verify([source]);
873 } 812 }
874 813
875 void test_bug_24539_getter() { 814 void test_bug_24539_getter() {
876 Source source = addSource(''' 815 Source source = addSource('''
877 class C<T> { 816 class C<T> {
878 List<Foo> get x => null; 817 List<Foo> get x => null;
879 } 818 }
880 819
881 typedef Foo(param); 820 typedef Foo(param);
882 '''); 821 ''');
883 computeLibrarySourceErrors(source);
884 assertNoErrors(source); 822 assertNoErrors(source);
885 verify([source]); 823 verify([source]);
886 } 824 }
887 825
888 void test_bug_24539_setter() { 826 void test_bug_24539_setter() {
889 Source source = addSource(''' 827 Source source = addSource('''
890 class C<T> { 828 class C<T> {
891 void set x(List<Foo> value) {} 829 void set x(List<Foo> value) {}
892 } 830 }
893 831
894 typedef Foo(param); 832 typedef Foo(param);
895 '''); 833 ''');
896 computeLibrarySourceErrors(source);
897 assertNoErrors(source); 834 assertNoErrors(source);
898 verify([source]); 835 verify([source]);
899 } 836 }
900 837
901 void test_builtInIdentifierAsType_dynamic() { 838 void test_builtInIdentifierAsType_dynamic() {
902 Source source = addSource(r''' 839 Source source = addSource(r'''
903 f() { 840 f() {
904 dynamic x; 841 dynamic x;
905 }'''); 842 }''');
906 computeLibrarySourceErrors(source);
907 assertNoErrors(source); 843 assertNoErrors(source);
908 verify([source]); 844 verify([source]);
909 } 845 }
910 846
911 void test_caseBlockNotTerminated() { 847 void test_caseBlockNotTerminated() {
912 Source source = addSource(r''' 848 Source source = addSource(r'''
913 f(int p) { 849 f(int p) {
914 for (int i = 0; i < 10; i++) { 850 for (int i = 0; i < 10; i++) {
915 switch (p) { 851 switch (p) {
916 case 0: 852 case 0:
917 break; 853 break;
918 case 1: 854 case 1:
919 continue; 855 continue;
920 case 2: 856 case 2:
921 return; 857 return;
922 case 3: 858 case 3:
923 throw new Object(); 859 throw new Object();
924 case 4: 860 case 4:
925 case 5: 861 case 5:
926 return; 862 return;
927 case 6: 863 case 6:
928 default: 864 default:
929 return; 865 return;
930 } 866 }
931 } 867 }
932 }'''); 868 }''');
933 computeLibrarySourceErrors(source);
934 assertNoErrors(source); 869 assertNoErrors(source);
935 verify([source]); 870 verify([source]);
936 } 871 }
937 872
938 void test_caseBlockNotTerminated_lastCase() { 873 void test_caseBlockNotTerminated_lastCase() {
939 Source source = addSource(r''' 874 Source source = addSource(r'''
940 f(int p) { 875 f(int p) {
941 switch (p) { 876 switch (p) {
942 case 0: 877 case 0:
943 p = p + 1; 878 p = p + 1;
944 } 879 }
945 }'''); 880 }''');
946 computeLibrarySourceErrors(source);
947 assertNoErrors(source); 881 assertNoErrors(source);
948 verify([source]); 882 verify([source]);
949 } 883 }
950 884
951 void test_caseExpressionTypeImplementsEquals() { 885 void test_caseExpressionTypeImplementsEquals() {
952 Source source = addSource(r''' 886 Source source = addSource(r'''
953 print(p) {} 887 print(p) {}
954 888
955 abstract class B { 889 abstract class B {
956 final id; 890 final id;
957 const B(this.id); 891 const B(this.id);
958 String toString() => 'C($id)'; 892 String toString() => 'C($id)';
959 /** Equality is identity equality, the id isn't used. */ 893 /** Equality is identity equality, the id isn't used. */
960 bool operator==(Object other); 894 bool operator==(Object other);
961 } 895 }
962 896
963 class C extends B { 897 class C extends B {
964 const C(id) : super(id); 898 const C(id) : super(id);
965 } 899 }
966 900
967 void doSwitch(c) { 901 void doSwitch(c) {
968 switch (c) { 902 switch (c) {
969 case const C(0): print('Switch: 0'); break; 903 case const C(0): print('Switch: 0'); break;
970 case const C(1): print('Switch: 1'); break; 904 case const C(1): print('Switch: 1'); break;
971 } 905 }
972 }'''); 906 }''');
973 computeLibrarySourceErrors(source);
974 assertNoErrors(source); 907 assertNoErrors(source);
975 verify([source]); 908 verify([source]);
976 } 909 }
977 910
978 void test_caseExpressionTypeImplementsEquals_int() { 911 void test_caseExpressionTypeImplementsEquals_int() {
979 Source source = addSource(r''' 912 Source source = addSource(r'''
980 f(int i) { 913 f(int i) {
981 switch(i) { 914 switch(i) {
982 case(1) : return 1; 915 case(1) : return 1;
983 default: return 0; 916 default: return 0;
984 } 917 }
985 }'''); 918 }''');
986 computeLibrarySourceErrors(source);
987 assertNoErrors(source); 919 assertNoErrors(source);
988 verify([source]); 920 verify([source]);
989 } 921 }
990 922
991 void test_caseExpressionTypeImplementsEquals_Object() { 923 void test_caseExpressionTypeImplementsEquals_Object() {
992 Source source = addSource(r''' 924 Source source = addSource(r'''
993 class IntWrapper { 925 class IntWrapper {
994 final int value; 926 final int value;
995 const IntWrapper(this.value); 927 const IntWrapper(this.value);
996 } 928 }
997 929
998 f(IntWrapper intWrapper) { 930 f(IntWrapper intWrapper) {
999 switch(intWrapper) { 931 switch(intWrapper) {
1000 case(const IntWrapper(1)) : return 1; 932 case(const IntWrapper(1)) : return 1;
1001 default: return 0; 933 default: return 0;
1002 } 934 }
1003 }'''); 935 }''');
1004 computeLibrarySourceErrors(source);
1005 assertNoErrors(source); 936 assertNoErrors(source);
1006 verify([source]); 937 verify([source]);
1007 } 938 }
1008 939
1009 void test_caseExpressionTypeImplementsEquals_String() { 940 void test_caseExpressionTypeImplementsEquals_String() {
1010 Source source = addSource(r''' 941 Source source = addSource(r'''
1011 f(String s) { 942 f(String s) {
1012 switch(s) { 943 switch(s) {
1013 case('1') : return 1; 944 case('1') : return 1;
1014 default: return 0; 945 default: return 0;
1015 } 946 }
1016 }'''); 947 }''');
1017 computeLibrarySourceErrors(source);
1018 assertNoErrors(source); 948 assertNoErrors(source);
1019 verify([source]); 949 verify([source]);
1020 } 950 }
1021 951
1022 void test_class_type_alias_documentationComment() { 952 void test_class_type_alias_documentationComment() {
1023 Source source = addSource(''' 953 Source source = addSource('''
1024 /** 954 /**
1025 * Documentation 955 * Documentation
1026 */ 956 */
1027 class C = D with E; 957 class C = D with E;
1028 958
1029 class D {} 959 class D {}
1030 class E {}'''); 960 class E {}''');
1031 computeLibrarySourceErrors(source);
1032 computeLibrarySourceErrors(source);
1033 assertNoErrors(source); 961 assertNoErrors(source);
1034 verify([source]); 962 verify([source]);
1035 CompilationUnit unit = _getResolvedLibraryUnit(source); 963 CompilationUnit unit = _getResolvedLibraryUnit(source);
1036 ClassElement classC = 964 ClassElement classC =
1037 resolutionMap.elementDeclaredByCompilationUnit(unit).getType('C'); 965 resolutionMap.elementDeclaredByCompilationUnit(unit).getType('C');
1038 expect(classC.documentationComment, isNotNull); 966 expect(classC.documentationComment, isNotNull);
1039 } 967 }
1040 968
1041 void test_commentReference_beforeConstructor() { 969 void test_commentReference_beforeConstructor() {
1042 String code = r''' 970 String code = r'''
1043 abstract class A { 971 abstract class A {
1044 /// [p] 972 /// [p]
1045 A(int p) {} 973 A(int p) {}
1046 }'''; 974 }''';
1047 Source source = addSource(code); 975 Source source = addSource(code);
1048 computeLibrarySourceErrors(source);
1049 assertNoErrors(source); 976 assertNoErrors(source);
1050 verify([source]); 977 verify([source]);
1051 CompilationUnit unit = _getResolvedLibraryUnit(source); 978 CompilationUnit unit = _getResolvedLibraryUnit(source);
1052 { 979 {
1053 SimpleIdentifier ref = 980 SimpleIdentifier ref =
1054 EngineTestCase.findSimpleIdentifier(unit, code, "p]"); 981 EngineTestCase.findSimpleIdentifier(unit, code, "p]");
1055 expect(ref.staticElement, new isInstanceOf<ParameterElement>()); 982 expect(ref.staticElement, new isInstanceOf<ParameterElement>());
1056 } 983 }
1057 } 984 }
1058 985
1059 void test_commentReference_beforeEnum() { 986 void test_commentReference_beforeEnum() {
1060 String code = r''' 987 String code = r'''
1061 /// This is the [Samurai] kind. 988 /// This is the [Samurai] kind.
1062 enum Samurai { 989 enum Samurai {
1063 /// Use [int]. 990 /// Use [int].
1064 WITH_SWORD, 991 WITH_SWORD,
1065 /// Like [WITH_SWORD], but only without one. 992 /// Like [WITH_SWORD], but only without one.
1066 WITHOUT_SWORD 993 WITHOUT_SWORD
1067 }'''; 994 }''';
1068 Source source = addSource(code); 995 Source source = addSource(code);
1069 computeLibrarySourceErrors(source);
1070 assertNoErrors(source); 996 assertNoErrors(source);
1071 verify([source]); 997 verify([source]);
1072 CompilationUnit unit = _getResolvedLibraryUnit(source); 998 CompilationUnit unit = _getResolvedLibraryUnit(source);
1073 { 999 {
1074 SimpleIdentifier ref = 1000 SimpleIdentifier ref =
1075 EngineTestCase.findSimpleIdentifier(unit, code, 'Samurai]'); 1001 EngineTestCase.findSimpleIdentifier(unit, code, 'Samurai]');
1076 ClassElement refElement = ref.staticElement; 1002 ClassElement refElement = ref.staticElement;
1077 expect(refElement, isNotNull); 1003 expect(refElement, isNotNull);
1078 expect(refElement.name, 'Samurai'); 1004 expect(refElement.name, 'Samurai');
1079 } 1005 }
(...skipping 12 matching lines...) Expand all
1092 expect(refElement.name, 'WITH_SWORD'); 1018 expect(refElement.name, 'WITH_SWORD');
1093 } 1019 }
1094 } 1020 }
1095 1021
1096 void test_commentReference_beforeFunction_blockBody() { 1022 void test_commentReference_beforeFunction_blockBody() {
1097 String code = r''' 1023 String code = r'''
1098 /// [p] 1024 /// [p]
1099 foo(int p) { 1025 foo(int p) {
1100 }'''; 1026 }''';
1101 Source source = addSource(code); 1027 Source source = addSource(code);
1102 computeLibrarySourceErrors(source);
1103 assertNoErrors(source); 1028 assertNoErrors(source);
1104 verify([source]); 1029 verify([source]);
1105 CompilationUnit unit = _getResolvedLibraryUnit(source); 1030 CompilationUnit unit = _getResolvedLibraryUnit(source);
1106 SimpleIdentifier ref = 1031 SimpleIdentifier ref =
1107 EngineTestCase.findSimpleIdentifier(unit, code, 'p]'); 1032 EngineTestCase.findSimpleIdentifier(unit, code, 'p]');
1108 expect(ref.staticElement, new isInstanceOf<ParameterElement>()); 1033 expect(ref.staticElement, new isInstanceOf<ParameterElement>());
1109 } 1034 }
1110 1035
1111 void test_commentReference_beforeFunction_expressionBody() { 1036 void test_commentReference_beforeFunction_expressionBody() {
1112 String code = r''' 1037 String code = r'''
1113 /// [p] 1038 /// [p]
1114 foo(int p) => null;'''; 1039 foo(int p) => null;''';
1115 Source source = addSource(code); 1040 Source source = addSource(code);
1116 computeLibrarySourceErrors(source);
1117 assertNoErrors(source); 1041 assertNoErrors(source);
1118 verify([source]); 1042 verify([source]);
1119 CompilationUnit unit = _getResolvedLibraryUnit(source); 1043 CompilationUnit unit = _getResolvedLibraryUnit(source);
1120 SimpleIdentifier ref = 1044 SimpleIdentifier ref =
1121 EngineTestCase.findSimpleIdentifier(unit, code, 'p]'); 1045 EngineTestCase.findSimpleIdentifier(unit, code, 'p]');
1122 expect(ref.staticElement, new isInstanceOf<ParameterElement>()); 1046 expect(ref.staticElement, new isInstanceOf<ParameterElement>());
1123 } 1047 }
1124 1048
1125 void test_commentReference_beforeFunctionTypeAlias() { 1049 void test_commentReference_beforeFunctionTypeAlias() {
1126 String code = r''' 1050 String code = r'''
1127 /// [p] 1051 /// [p]
1128 typedef Foo(int p); 1052 typedef Foo(int p);
1129 '''; 1053 ''';
1130 Source source = addSource(code); 1054 Source source = addSource(code);
1131 computeLibrarySourceErrors(source);
1132 assertNoErrors(source); 1055 assertNoErrors(source);
1133 verify([source]); 1056 verify([source]);
1134 CompilationUnit unit = _getResolvedLibraryUnit(source); 1057 CompilationUnit unit = _getResolvedLibraryUnit(source);
1135 SimpleIdentifier ref = 1058 SimpleIdentifier ref =
1136 EngineTestCase.findSimpleIdentifier(unit, code, 'p]'); 1059 EngineTestCase.findSimpleIdentifier(unit, code, 'p]');
1137 expect(ref.staticElement, new isInstanceOf<ParameterElement>()); 1060 expect(ref.staticElement, new isInstanceOf<ParameterElement>());
1138 } 1061 }
1139 1062
1140 void test_commentReference_beforeGetter() { 1063 void test_commentReference_beforeGetter() {
1141 String code = r''' 1064 String code = r'''
1142 abstract class A { 1065 abstract class A {
1143 /// [int] 1066 /// [int]
1144 get g => null; 1067 get g => null;
1145 }'''; 1068 }''';
1146 Source source = addSource(code); 1069 Source source = addSource(code);
1147 computeLibrarySourceErrors(source);
1148 assertNoErrors(source); 1070 assertNoErrors(source);
1149 verify([source]); 1071 verify([source]);
1150 CompilationUnit unit = _getResolvedLibraryUnit(source); 1072 CompilationUnit unit = _getResolvedLibraryUnit(source);
1151 { 1073 {
1152 SimpleIdentifier ref = 1074 SimpleIdentifier ref =
1153 EngineTestCase.findSimpleIdentifier(unit, code, 'int]'); 1075 EngineTestCase.findSimpleIdentifier(unit, code, 'int]');
1154 expect(ref.staticElement, isNotNull); 1076 expect(ref.staticElement, isNotNull);
1155 } 1077 }
1156 } 1078 }
1157 1079
1158 void test_commentReference_beforeMethod() { 1080 void test_commentReference_beforeMethod() {
1159 String code = r''' 1081 String code = r'''
1160 abstract class A { 1082 abstract class A {
1161 /// [p1] 1083 /// [p1]
1162 ma(int p1) {} 1084 ma(int p1) {}
1163 /// [p2] 1085 /// [p2]
1164 mb(int p2); 1086 mb(int p2);
1165 /// [p3] and [p4] 1087 /// [p3] and [p4]
1166 mc(int p3, p4()); 1088 mc(int p3, p4());
1167 /// [p5] 1089 /// [p5]
1168 md(int p5, {int p6}); 1090 md(int p5, {int p6});
1169 }'''; 1091 }''';
1170 Source source = addSource(code); 1092 Source source = addSource(code);
1171 computeLibrarySourceErrors(source);
1172 assertNoErrors(source); 1093 assertNoErrors(source);
1173 verify([source]); 1094 verify([source]);
1174 CompilationUnit unit = _getResolvedLibraryUnit(source); 1095 CompilationUnit unit = _getResolvedLibraryUnit(source);
1175 assertIsParameter(String search) { 1096 assertIsParameter(String search) {
1176 SimpleIdentifier ref = 1097 SimpleIdentifier ref =
1177 EngineTestCase.findSimpleIdentifier(unit, code, search); 1098 EngineTestCase.findSimpleIdentifier(unit, code, search);
1178 expect(ref.staticElement, new isInstanceOf<ParameterElement>()); 1099 expect(ref.staticElement, new isInstanceOf<ParameterElement>());
1179 } 1100 }
1180 1101
1181 assertIsParameter('p1'); 1102 assertIsParameter('p1');
1182 assertIsParameter('p2'); 1103 assertIsParameter('p2');
1183 assertIsParameter('p3'); 1104 assertIsParameter('p3');
1184 assertIsParameter('p4'); 1105 assertIsParameter('p4');
1185 assertIsParameter('p5'); 1106 assertIsParameter('p5');
1186 assertIsParameter('p6'); 1107 assertIsParameter('p6');
1187 } 1108 }
1188 1109
1189 void test_commentReference_class() { 1110 void test_commentReference_class() {
1190 String code = r''' 1111 String code = r'''
1191 /// [foo] 1112 /// [foo]
1192 class A { 1113 class A {
1193 foo() {} 1114 foo() {}
1194 }'''; 1115 }''';
1195 Source source = addSource(code); 1116 Source source = addSource(code);
1196 computeLibrarySourceErrors(source);
1197 assertNoErrors(source); 1117 assertNoErrors(source);
1198 verify([source]); 1118 verify([source]);
1199 CompilationUnit unit = _getResolvedLibraryUnit(source); 1119 CompilationUnit unit = _getResolvedLibraryUnit(source);
1200 SimpleIdentifier ref = 1120 SimpleIdentifier ref =
1201 EngineTestCase.findSimpleIdentifier(unit, code, 'foo]'); 1121 EngineTestCase.findSimpleIdentifier(unit, code, 'foo]');
1202 expect(ref.staticElement, new isInstanceOf<MethodElement>()); 1122 expect(ref.staticElement, new isInstanceOf<MethodElement>());
1203 } 1123 }
1204 1124
1205 void test_commentReference_setter() { 1125 void test_commentReference_setter() {
1206 String code = r''' 1126 String code = r'''
1207 class A { 1127 class A {
1208 /// [x] in A 1128 /// [x] in A
1209 mA() {} 1129 mA() {}
1210 set x(value) {} 1130 set x(value) {}
1211 } 1131 }
1212 class B extends A { 1132 class B extends A {
1213 /// [x] in B 1133 /// [x] in B
1214 mB() {} 1134 mB() {}
1215 } 1135 }
1216 '''; 1136 ''';
1217 Source source = addSource(code); 1137 Source source = addSource(code);
1218 computeLibrarySourceErrors(source);
1219 assertNoErrors(source); 1138 assertNoErrors(source);
1220 verify([source]); 1139 verify([source]);
1221 CompilationUnit unit = _getResolvedLibraryUnit(source); 1140 CompilationUnit unit = _getResolvedLibraryUnit(source);
1222 { 1141 {
1223 SimpleIdentifier ref = 1142 SimpleIdentifier ref =
1224 EngineTestCase.findSimpleIdentifier(unit, code, "x] in A"); 1143 EngineTestCase.findSimpleIdentifier(unit, code, "x] in A");
1225 expect(ref.staticElement, new isInstanceOf<PropertyAccessorElement>()); 1144 expect(ref.staticElement, new isInstanceOf<PropertyAccessorElement>());
1226 } 1145 }
1227 { 1146 {
1228 SimpleIdentifier ref = 1147 SimpleIdentifier ref =
1229 EngineTestCase.findSimpleIdentifier(unit, code, 'x] in B'); 1148 EngineTestCase.findSimpleIdentifier(unit, code, 'x] in B');
1230 expect(ref.staticElement, new isInstanceOf<PropertyAccessorElement>()); 1149 expect(ref.staticElement, new isInstanceOf<PropertyAccessorElement>());
1231 } 1150 }
1232 } 1151 }
1233 1152
1234 void test_concreteClassWithAbstractMember() { 1153 void test_concreteClassWithAbstractMember() {
1235 Source source = addSource(r''' 1154 Source source = addSource(r'''
1236 abstract class A { 1155 abstract class A {
1237 m(); 1156 m();
1238 }'''); 1157 }''');
1239 computeLibrarySourceErrors(source);
1240 assertNoErrors(source); 1158 assertNoErrors(source);
1241 verify([source]); 1159 verify([source]);
1242 } 1160 }
1243 1161
1244 void test_concreteClassWithAbstractMember_inherited() { 1162 void test_concreteClassWithAbstractMember_inherited() {
1245 Source source = addSource(r''' 1163 Source source = addSource(r'''
1246 class A { 1164 class A {
1247 m() {} 1165 m() {}
1248 } 1166 }
1249 class B extends A { 1167 class B extends A {
1250 m(); 1168 m();
1251 }'''); 1169 }''');
1252 computeLibrarySourceErrors(source);
1253 assertNoErrors(source); 1170 assertNoErrors(source);
1254 verify([source]); 1171 verify([source]);
1255 } 1172 }
1256 1173
1257 void test_conflictingInstanceGetterAndSuperclassMember_instance() { 1174 void test_conflictingInstanceGetterAndSuperclassMember_instance() {
1258 Source source = addSource(r''' 1175 Source source = addSource(r'''
1259 class A { 1176 class A {
1260 get v => 0; 1177 get v => 0;
1261 } 1178 }
1262 class B extends A { 1179 class B extends A {
1263 get v => 1; 1180 get v => 1;
1264 }'''); 1181 }''');
1265 computeLibrarySourceErrors(source);
1266 assertNoErrors(source); 1182 assertNoErrors(source);
1267 verify([source]); 1183 verify([source]);
1268 } 1184 }
1269 1185
1270 void test_conflictingStaticGetterAndInstanceSetter_thisClass() { 1186 void test_conflictingStaticGetterAndInstanceSetter_thisClass() {
1271 Source source = addSource(r''' 1187 Source source = addSource(r'''
1272 class A { 1188 class A {
1273 static get x => 0; 1189 static get x => 0;
1274 static set x(int p) {} 1190 static set x(int p) {}
1275 }'''); 1191 }''');
1276 computeLibrarySourceErrors(source);
1277 assertNoErrors(source); 1192 assertNoErrors(source);
1278 verify([source]); 1193 verify([source]);
1279 } 1194 }
1280 1195
1281 void test_conflictingStaticSetterAndInstanceMember_thisClass_method() { 1196 void test_conflictingStaticSetterAndInstanceMember_thisClass_method() {
1282 Source source = addSource(r''' 1197 Source source = addSource(r'''
1283 class A { 1198 class A {
1284 static x() {} 1199 static x() {}
1285 static set x(int p) {} 1200 static set x(int p) {}
1286 }'''); 1201 }''');
1287 computeLibrarySourceErrors(source);
1288 assertNoErrors(source); 1202 assertNoErrors(source);
1289 verify([source]); 1203 verify([source]);
1290 } 1204 }
1291 1205
1292 void test_const_constructor_with_named_generic_parameter() { 1206 void test_const_constructor_with_named_generic_parameter() {
1293 Source source = addSource(''' 1207 Source source = addSource('''
1294 class C<T> { 1208 class C<T> {
1295 const C({T t}); 1209 const C({T t});
1296 } 1210 }
1297 const c = const C(t: 1); 1211 const c = const C(t: 1);
1298 '''); 1212 ''');
1299 computeLibrarySourceErrors(source);
1300 assertNoErrors(source); 1213 assertNoErrors(source);
1301 verify([source]); 1214 verify([source]);
1302 } 1215 }
1303 1216
1304 void test_const_dynamic() { 1217 void test_const_dynamic() {
1305 Source source = addSource(''' 1218 Source source = addSource('''
1306 const Type d = dynamic; 1219 const Type d = dynamic;
1307 '''); 1220 ''');
1308 computeLibrarySourceErrors(source);
1309 assertNoErrors(source); 1221 assertNoErrors(source);
1310 verify([source]); 1222 verify([source]);
1311 } 1223 }
1312 1224
1313 void test_constConstructorWithNonConstSuper_explicit() { 1225 void test_constConstructorWithNonConstSuper_explicit() {
1314 Source source = addSource(r''' 1226 Source source = addSource(r'''
1315 class A { 1227 class A {
1316 const A(); 1228 const A();
1317 } 1229 }
1318 class B extends A { 1230 class B extends A {
1319 const B(): super(); 1231 const B(): super();
1320 }'''); 1232 }''');
1321 computeLibrarySourceErrors(source);
1322 assertNoErrors(source); 1233 assertNoErrors(source);
1323 verify([source]); 1234 verify([source]);
1324 } 1235 }
1325 1236
1326 void test_constConstructorWithNonConstSuper_redirectingFactory() { 1237 void test_constConstructorWithNonConstSuper_redirectingFactory() {
1327 Source source = addSource(r''' 1238 Source source = addSource(r'''
1328 class A { 1239 class A {
1329 A(); 1240 A();
1330 } 1241 }
1331 class B implements C { 1242 class B implements C {
1332 const B(); 1243 const B();
1333 } 1244 }
1334 class C extends A { 1245 class C extends A {
1335 const factory C() = B; 1246 const factory C() = B;
1336 }'''); 1247 }''');
1337 computeLibrarySourceErrors(source);
1338 assertNoErrors(source); 1248 assertNoErrors(source);
1339 verify([source]); 1249 verify([source]);
1340 } 1250 }
1341 1251
1342 void test_constConstructorWithNonConstSuper_unresolved() { 1252 void test_constConstructorWithNonConstSuper_unresolved() {
1343 Source source = addSource(r''' 1253 Source source = addSource(r'''
1344 class A { 1254 class A {
1345 A.a(); 1255 A.a();
1346 } 1256 }
1347 class B extends A { 1257 class B extends A {
1348 const B(): super(); 1258 const B(): super();
1349 }'''); 1259 }''');
1350 computeLibrarySourceErrors(source);
1351 assertErrors(source, 1260 assertErrors(source,
1352 [CompileTimeErrorCode.UNDEFINED_CONSTRUCTOR_IN_INITIALIZER_DEFAULT]); 1261 [CompileTimeErrorCode.UNDEFINED_CONSTRUCTOR_IN_INITIALIZER_DEFAULT]);
1353 verify([source]); 1262 verify([source]);
1354 } 1263 }
1355 1264
1356 void test_constConstructorWithNonFinalField_finalInstanceVar() { 1265 void test_constConstructorWithNonFinalField_finalInstanceVar() {
1357 Source source = addSource(r''' 1266 Source source = addSource(r'''
1358 class A { 1267 class A {
1359 final int x = 0; 1268 final int x = 0;
1360 const A(); 1269 const A();
1361 }'''); 1270 }''');
1362 computeLibrarySourceErrors(source);
1363 assertNoErrors(source); 1271 assertNoErrors(source);
1364 verify([source]); 1272 verify([source]);
1365 } 1273 }
1366 1274
1367 void test_constConstructorWithNonFinalField_mixin() { 1275 void test_constConstructorWithNonFinalField_mixin() {
1368 Source source = addSource(r''' 1276 Source source = addSource(r'''
1369 class A { 1277 class A {
1370 a() {} 1278 a() {}
1371 } 1279 }
1372 class B extends Object with A { 1280 class B extends Object with A {
1373 const B(); 1281 const B();
1374 }'''); 1282 }''');
1375 computeLibrarySourceErrors(source);
1376 assertErrors(source, [CompileTimeErrorCode.CONST_CONSTRUCTOR_WITH_MIXIN]); 1283 assertErrors(source, [CompileTimeErrorCode.CONST_CONSTRUCTOR_WITH_MIXIN]);
1377 verify([source]); 1284 verify([source]);
1378 } 1285 }
1379 1286
1380 void test_constConstructorWithNonFinalField_static() { 1287 void test_constConstructorWithNonFinalField_static() {
1381 Source source = addSource(r''' 1288 Source source = addSource(r'''
1382 class A { 1289 class A {
1383 static int x; 1290 static int x;
1384 const A(); 1291 const A();
1385 }'''); 1292 }''');
1386 computeLibrarySourceErrors(source);
1387 assertNoErrors(source); 1293 assertNoErrors(source);
1388 verify([source]); 1294 verify([source]);
1389 } 1295 }
1390 1296
1391 void test_constConstructorWithNonFinalField_syntheticField() { 1297 void test_constConstructorWithNonFinalField_syntheticField() {
1392 Source source = addSource(r''' 1298 Source source = addSource(r'''
1393 class A { 1299 class A {
1394 const A(); 1300 const A();
1395 set x(value) {} 1301 set x(value) {}
1396 get x {return 0;} 1302 get x {return 0;}
1397 }'''); 1303 }''');
1398 computeLibrarySourceErrors(source);
1399 assertNoErrors(source); 1304 assertNoErrors(source);
1400 verify([source]); 1305 verify([source]);
1401 } 1306 }
1402 1307
1403 void test_constDeferredClass_new() { 1308 void test_constDeferredClass_new() {
1404 resolveWithErrors(<String>[ 1309 resolveWithErrors(<String>[
1405 r''' 1310 r'''
1406 library lib1; 1311 library lib1;
1407 class A { 1312 class A {
1408 const A.b(); 1313 const A.b();
1409 }''', 1314 }''',
1410 r''' 1315 r'''
1411 library root; 1316 library root;
1412 import 'lib1.dart' deferred as a; 1317 import 'lib1.dart' deferred as a;
1413 main() { 1318 main() {
1414 new a.A.b(); 1319 new a.A.b();
1415 }''' 1320 }'''
1416 ], <ErrorCode>[]); 1321 ], <ErrorCode>[]);
1417 } 1322 }
1418 1323
1419 void test_constEval_functionTypeLiteral() { 1324 void test_constEval_functionTypeLiteral() {
1420 Source source = addSource(r''' 1325 Source source = addSource(r'''
1421 typedef F(); 1326 typedef F();
1422 const C = F;'''); 1327 const C = F;''');
1423 computeLibrarySourceErrors(source);
1424 assertNoErrors(source); 1328 assertNoErrors(source);
1425 verify([source]); 1329 verify([source]);
1426 } 1330 }
1427 1331
1428 void test_constEval_propertyExtraction_fieldStatic_targetType() { 1332 void test_constEval_propertyExtraction_fieldStatic_targetType() {
1429 addNamedSource( 1333 addNamedSource(
1430 "/math.dart", 1334 "/math.dart",
1431 r''' 1335 r'''
1432 library math; 1336 library math;
1433 const PI = 3.14;'''); 1337 const PI = 3.14;''');
1434 Source source = addSource(r''' 1338 Source source = addSource(r'''
1435 import 'math.dart' as math; 1339 import 'math.dart' as math;
1436 const C = math.PI;'''); 1340 const C = math.PI;''');
1437 computeLibrarySourceErrors(source);
1438 assertNoErrors(source); 1341 assertNoErrors(source);
1439 verify([source]); 1342 verify([source]);
1440 } 1343 }
1441 1344
1442 void test_constEval_propertyExtraction_methodStatic_targetType() { 1345 void test_constEval_propertyExtraction_methodStatic_targetType() {
1443 Source source = addSource(r''' 1346 Source source = addSource(r'''
1444 class A { 1347 class A {
1445 const A(); 1348 const A();
1446 static m() {} 1349 static m() {}
1447 } 1350 }
1448 const C = A.m;'''); 1351 const C = A.m;''');
1449 computeLibrarySourceErrors(source);
1450 assertNoErrors(source); 1352 assertNoErrors(source);
1451 verify([source]); 1353 verify([source]);
1452 } 1354 }
1453 1355
1454 void test_constEval_symbol() { 1356 void test_constEval_symbol() {
1455 addNamedSource( 1357 addNamedSource(
1456 "/math.dart", 1358 "/math.dart",
1457 r''' 1359 r'''
1458 library math; 1360 library math;
1459 const PI = 3.14;'''); 1361 const PI = 3.14;''');
1460 Source source = addSource(r''' 1362 Source source = addSource(r'''
1461 const C = #foo; 1363 const C = #foo;
1462 foo() {}'''); 1364 foo() {}''');
1463 computeLibrarySourceErrors(source);
1464 assertNoErrors(source); 1365 assertNoErrors(source);
1465 verify([source]); 1366 verify([source]);
1466 } 1367 }
1467 1368
1468 void test_constEvalTypeBoolNumString_equal() { 1369 void test_constEvalTypeBoolNumString_equal() {
1469 Source source = addSource(r''' 1370 Source source = addSource(r'''
1470 class A { 1371 class A {
1471 const A(); 1372 const A();
1472 } 1373 }
1473 class B { 1374 class B {
1474 final v; 1375 final v;
1475 const B.a1(bool p) : v = p == true; 1376 const B.a1(bool p) : v = p == true;
1476 const B.a2(bool p) : v = p == false; 1377 const B.a2(bool p) : v = p == false;
1477 const B.a3(bool p) : v = p == 0; 1378 const B.a3(bool p) : v = p == 0;
1478 const B.a4(bool p) : v = p == 0.0; 1379 const B.a4(bool p) : v = p == 0.0;
1479 const B.a5(bool p) : v = p == ''; 1380 const B.a5(bool p) : v = p == '';
1480 const B.b1(int p) : v = p == true; 1381 const B.b1(int p) : v = p == true;
1481 const B.b2(int p) : v = p == false; 1382 const B.b2(int p) : v = p == false;
1482 const B.b3(int p) : v = p == 0; 1383 const B.b3(int p) : v = p == 0;
1483 const B.b4(int p) : v = p == 0.0; 1384 const B.b4(int p) : v = p == 0.0;
1484 const B.b5(int p) : v = p == ''; 1385 const B.b5(int p) : v = p == '';
1485 const B.c1(String p) : v = p == true; 1386 const B.c1(String p) : v = p == true;
1486 const B.c2(String p) : v = p == false; 1387 const B.c2(String p) : v = p == false;
1487 const B.c3(String p) : v = p == 0; 1388 const B.c3(String p) : v = p == 0;
1488 const B.c4(String p) : v = p == 0.0; 1389 const B.c4(String p) : v = p == 0.0;
1489 const B.c5(String p) : v = p == ''; 1390 const B.c5(String p) : v = p == '';
1490 const B.n1(num p) : v = p == null; 1391 const B.n1(num p) : v = p == null;
1491 const B.n2(num p) : v = null == p; 1392 const B.n2(num p) : v = null == p;
1492 }'''); 1393 }''');
1493 computeLibrarySourceErrors(source);
1494 assertNoErrors(source); 1394 assertNoErrors(source);
1495 } 1395 }
1496 1396
1497 void test_constEvalTypeBoolNumString_notEqual() { 1397 void test_constEvalTypeBoolNumString_notEqual() {
1498 Source source = addSource(r''' 1398 Source source = addSource(r'''
1499 class A { 1399 class A {
1500 const A(); 1400 const A();
1501 } 1401 }
1502 class B { 1402 class B {
1503 final v; 1403 final v;
1504 const B.a1(bool p) : v = p != true; 1404 const B.a1(bool p) : v = p != true;
1505 const B.a2(bool p) : v = p != false; 1405 const B.a2(bool p) : v = p != false;
1506 const B.a3(bool p) : v = p != 0; 1406 const B.a3(bool p) : v = p != 0;
1507 const B.a4(bool p) : v = p != 0.0; 1407 const B.a4(bool p) : v = p != 0.0;
1508 const B.a5(bool p) : v = p != ''; 1408 const B.a5(bool p) : v = p != '';
1509 const B.b1(int p) : v = p != true; 1409 const B.b1(int p) : v = p != true;
1510 const B.b2(int p) : v = p != false; 1410 const B.b2(int p) : v = p != false;
1511 const B.b3(int p) : v = p != 0; 1411 const B.b3(int p) : v = p != 0;
1512 const B.b4(int p) : v = p != 0.0; 1412 const B.b4(int p) : v = p != 0.0;
1513 const B.b5(int p) : v = p != ''; 1413 const B.b5(int p) : v = p != '';
1514 const B.c1(String p) : v = p != true; 1414 const B.c1(String p) : v = p != true;
1515 const B.c2(String p) : v = p != false; 1415 const B.c2(String p) : v = p != false;
1516 const B.c3(String p) : v = p != 0; 1416 const B.c3(String p) : v = p != 0;
1517 const B.c4(String p) : v = p != 0.0; 1417 const B.c4(String p) : v = p != 0.0;
1518 const B.c5(String p) : v = p != ''; 1418 const B.c5(String p) : v = p != '';
1519 const B.n1(num p) : v = p != null; 1419 const B.n1(num p) : v = p != null;
1520 const B.n2(num p) : v = null != p; 1420 const B.n2(num p) : v = null != p;
1521 }'''); 1421 }''');
1522 computeLibrarySourceErrors(source);
1523 assertNoErrors(source); 1422 assertNoErrors(source);
1524 verify([source]); 1423 verify([source]);
1525 } 1424 }
1526 1425
1527 void test_constEvelTypeNum_String() { 1426 void test_constEvelTypeNum_String() {
1528 Source source = addSource(r''' 1427 Source source = addSource(r'''
1529 const String A = 'a'; 1428 const String A = 'a';
1530 const String B = A + 'b'; 1429 const String B = A + 'b';
1531 '''); 1430 ''');
1532 computeLibrarySourceErrors(source);
1533 assertNoErrors(source); 1431 assertNoErrors(source);
1534 verify([source]); 1432 verify([source]);
1535 } 1433 }
1536 1434
1537 void test_constMapKeyExpressionTypeImplementsEquals_abstract() { 1435 void test_constMapKeyExpressionTypeImplementsEquals_abstract() {
1538 Source source = addSource(r''' 1436 Source source = addSource(r'''
1539 abstract class B { 1437 abstract class B {
1540 final id; 1438 final id;
1541 const B(this.id); 1439 const B(this.id);
1542 String toString() => 'C($id)'; 1440 String toString() => 'C($id)';
1543 /** Equality is identity equality, the id isn't used. */ 1441 /** Equality is identity equality, the id isn't used. */
1544 bool operator==(Object other); 1442 bool operator==(Object other);
1545 } 1443 }
1546 1444
1547 class C extends B { 1445 class C extends B {
1548 const C(id) : super(id); 1446 const C(id) : super(id);
1549 } 1447 }
1550 1448
1551 Map getMap() { 1449 Map getMap() {
1552 return const { const C(0): 'Map: 0' }; 1450 return const { const C(0): 'Map: 0' };
1553 }'''); 1451 }''');
1554 computeLibrarySourceErrors(source);
1555 assertNoErrors(source); 1452 assertNoErrors(source);
1556 verify([source]); 1453 verify([source]);
1557 } 1454 }
1558 1455
1559 void test_constNotInitialized_field() { 1456 void test_constNotInitialized_field() {
1560 Source source = addSource(r''' 1457 Source source = addSource(r'''
1561 class A { 1458 class A {
1562 static const int x = 0; 1459 static const int x = 0;
1563 }'''); 1460 }''');
1564 computeLibrarySourceErrors(source);
1565 assertNoErrors(source); 1461 assertNoErrors(source);
1566 verify([source]); 1462 verify([source]);
1567 } 1463 }
1568 1464
1569 void test_constNotInitialized_local() { 1465 void test_constNotInitialized_local() {
1570 Source source = addSource(r''' 1466 Source source = addSource(r'''
1571 main() { 1467 main() {
1572 const int x = 0; 1468 const int x = 0;
1573 }'''); 1469 }''');
1574 computeLibrarySourceErrors(source);
1575 assertNoErrors(source); 1470 assertNoErrors(source);
1576 verify([source]); 1471 verify([source]);
1577 } 1472 }
1578 1473
1579 void test_constRedirectSkipsSupertype() { 1474 void test_constRedirectSkipsSupertype() {
1580 // Since C redirects to C.named, it doesn't implicitly refer to B's 1475 // Since C redirects to C.named, it doesn't implicitly refer to B's
1581 // unnamed constructor. Therefore there is no cycle. 1476 // unnamed constructor. Therefore there is no cycle.
1582 Source source = addSource(''' 1477 Source source = addSource('''
1583 class B { 1478 class B {
1584 final x; 1479 final x;
1585 const B() : x = y; 1480 const B() : x = y;
1586 const B.named() : x = null; 1481 const B.named() : x = null;
1587 } 1482 }
1588 class C extends B { 1483 class C extends B {
1589 const C() : this.named(); 1484 const C() : this.named();
1590 const C.named() : super.named(); 1485 const C.named() : super.named();
1591 } 1486 }
1592 const y = const C(); 1487 const y = const C();
1593 '''); 1488 ''');
1594 computeLibrarySourceErrors(source);
1595 assertNoErrors(source); 1489 assertNoErrors(source);
1596 verify([source]); 1490 verify([source]);
1597 } 1491 }
1598 1492
1599 void test_constructorDeclaration_scope_signature() { 1493 void test_constructorDeclaration_scope_signature() {
1600 Source source = addSource(r''' 1494 Source source = addSource(r'''
1601 const app = 0; 1495 const app = 0;
1602 class A { 1496 class A {
1603 A(@app int app) {} 1497 A(@app int app) {}
1604 }'''); 1498 }''');
1605 computeLibrarySourceErrors(source);
1606 assertNoErrors(source); 1499 assertNoErrors(source);
1607 verify([source]); 1500 verify([source]);
1608 } 1501 }
1609 1502
1610 void test_constWithNonConstantArgument_constField() { 1503 void test_constWithNonConstantArgument_constField() {
1611 Source source = addSource(r''' 1504 Source source = addSource(r'''
1612 class A { 1505 class A {
1613 const A(x); 1506 const A(x);
1614 } 1507 }
1615 main() { 1508 main() {
1616 const A(double.INFINITY); 1509 const A(double.INFINITY);
1617 }'''); 1510 }''');
1618 computeLibrarySourceErrors(source);
1619 assertNoErrors(source); 1511 assertNoErrors(source);
1620 verify([source]); 1512 verify([source]);
1621 } 1513 }
1622 1514
1623 void test_constWithNonConstantArgument_literals() { 1515 void test_constWithNonConstantArgument_literals() {
1624 Source source = addSource(r''' 1516 Source source = addSource(r'''
1625 class A { 1517 class A {
1626 const A(a, b, c, d); 1518 const A(a, b, c, d);
1627 } 1519 }
1628 f() { return const A(true, 0, 1.0, '2'); }'''); 1520 f() { return const A(true, 0, 1.0, '2'); }''');
1629 computeLibrarySourceErrors(source);
1630 assertNoErrors(source); 1521 assertNoErrors(source);
1631 verify([source]); 1522 verify([source]);
1632 } 1523 }
1633 1524
1634 void test_constWithTypeParameters_direct() { 1525 void test_constWithTypeParameters_direct() {
1635 Source source = addSource(r''' 1526 Source source = addSource(r'''
1636 class A<T> { 1527 class A<T> {
1637 static const V = const A<int>(); 1528 static const V = const A<int>();
1638 const A(); 1529 const A();
1639 }'''); 1530 }''');
1640 computeLibrarySourceErrors(source);
1641 assertNoErrors(source); 1531 assertNoErrors(source);
1642 verify([source]); 1532 verify([source]);
1643 } 1533 }
1644 1534
1645 void test_constWithUndefinedConstructor() { 1535 void test_constWithUndefinedConstructor() {
1646 Source source = addSource(r''' 1536 Source source = addSource(r'''
1647 class A { 1537 class A {
1648 const A.name(); 1538 const A.name();
1649 } 1539 }
1650 f() { 1540 f() {
1651 return const A.name(); 1541 return const A.name();
1652 }'''); 1542 }''');
1653 computeLibrarySourceErrors(source);
1654 assertNoErrors(source); 1543 assertNoErrors(source);
1655 verify([source]); 1544 verify([source]);
1656 } 1545 }
1657 1546
1658 void test_constWithUndefinedConstructorDefault() { 1547 void test_constWithUndefinedConstructorDefault() {
1659 Source source = addSource(r''' 1548 Source source = addSource(r'''
1660 class A { 1549 class A {
1661 const A(); 1550 const A();
1662 } 1551 }
1663 f() { 1552 f() {
1664 return const A(); 1553 return const A();
1665 }'''); 1554 }''');
1666 computeLibrarySourceErrors(source);
1667 assertNoErrors(source); 1555 assertNoErrors(source);
1668 verify([source]); 1556 verify([source]);
1669 } 1557 }
1670 1558
1671 void test_defaultValueInFunctionTypeAlias() { 1559 void test_defaultValueInFunctionTypeAlias() {
1672 Source source = addSource("typedef F([x]);"); 1560 Source source = addSource("typedef F([x]);");
1673 computeLibrarySourceErrors(source);
1674 assertNoErrors(source); 1561 assertNoErrors(source);
1675 verify([source]); 1562 verify([source]);
1676 } 1563 }
1677 1564
1678 void test_defaultValueInFunctionTypedParameter_named() { 1565 void test_defaultValueInFunctionTypedParameter_named() {
1679 Source source = addSource("f(g({p})) {}"); 1566 Source source = addSource("f(g({p})) {}");
1680 computeLibrarySourceErrors(source);
1681 assertNoErrors(source); 1567 assertNoErrors(source);
1682 verify([source]); 1568 verify([source]);
1683 } 1569 }
1684 1570
1685 void test_defaultValueInFunctionTypedParameter_optional() { 1571 void test_defaultValueInFunctionTypedParameter_optional() {
1686 Source source = addSource("f(g([p])) {}"); 1572 Source source = addSource("f(g([p])) {}");
1687 computeLibrarySourceErrors(source);
1688 assertNoErrors(source); 1573 assertNoErrors(source);
1689 verify([source]); 1574 verify([source]);
1690 } 1575 }
1691 1576
1692 void test_deprecatedMemberUse_hide() { 1577 void test_deprecatedMemberUse_hide() {
1693 Source source = addSource(r''' 1578 Source source = addSource(r'''
1694 library lib; 1579 library lib;
1695 import 'lib1.dart' hide B; 1580 import 'lib1.dart' hide B;
1696 A a = new A();'''); 1581 A a = new A();''');
1697 addNamedSource( 1582 addNamedSource(
1698 "/lib1.dart", 1583 "/lib1.dart",
1699 r''' 1584 r'''
1700 library lib1; 1585 library lib1;
1701 class A {} 1586 class A {}
1702 @deprecated 1587 @deprecated
1703 class B {}'''); 1588 class B {}''');
1704 computeLibrarySourceErrors(source);
1705 assertNoErrors(source); 1589 assertNoErrors(source);
1706 verify([source]); 1590 verify([source]);
1707 } 1591 }
1708 1592
1709 void test_duplicateDefinition_emptyName() { 1593 void test_duplicateDefinition_emptyName() {
1710 // Note: This code has two FunctionElements '() {}' with an empty name, 1594 // Note: This code has two FunctionElements '() {}' with an empty name,
1711 // this tests that the empty string is not put into the scope 1595 // this tests that the empty string is not put into the scope
1712 // (more than once). 1596 // (more than once).
1713 Source source = addSource(r''' 1597 Source source = addSource(r'''
1714 Map _globalMap = { 1598 Map _globalMap = {
1715 'a' : () {}, 1599 'a' : () {},
1716 'b' : () {} 1600 'b' : () {}
1717 };'''); 1601 };''');
1718 computeLibrarySourceErrors(source);
1719 assertNoErrors(source); 1602 assertNoErrors(source);
1720 verify([source]); 1603 verify([source]);
1721 } 1604 }
1722 1605
1723 void test_duplicateDefinition_getter() { 1606 void test_duplicateDefinition_getter() {
1724 Source source = addSource("bool get a => true;"); 1607 Source source = addSource("bool get a => true;");
1725 computeLibrarySourceErrors(source);
1726 assertNoErrors(source); 1608 assertNoErrors(source);
1727 verify([source]); 1609 verify([source]);
1728 } 1610 }
1729 1611
1730 void test_duplicatePart() { 1612 void test_duplicatePart() {
1731 addNamedSource('/part1.dart', 'part of lib;'); 1613 addNamedSource('/part1.dart', 'part of lib;');
1732 addNamedSource('/part2.dart', 'part of lib;'); 1614 addNamedSource('/part2.dart', 'part of lib;');
1733 Source source = addSource(r''' 1615 Source source = addSource(r'''
1734 library lib; 1616 library lib;
1735 part 'part1.dart'; 1617 part 'part1.dart';
1736 part 'part2.dart'; 1618 part 'part2.dart';
1737 '''); 1619 ''');
1738 computeLibrarySourceErrors(source);
1739 assertNoErrors(source); 1620 assertNoErrors(source);
1740 verify([source]); 1621 verify([source]);
1741 } 1622 }
1742 1623
1743 void test_dynamicIdentifier() { 1624 void test_dynamicIdentifier() {
1744 Source source = addSource(r''' 1625 Source source = addSource(r'''
1745 main() { 1626 main() {
1746 var v = dynamic; 1627 var v = dynamic;
1747 }'''); 1628 }''');
1748 computeLibrarySourceErrors(source);
1749 assertNoErrors(source); 1629 assertNoErrors(source);
1750 verify([source]); 1630 verify([source]);
1751 } 1631 }
1752 1632
1753 void test_empty_generator_async() { 1633 void test_empty_generator_async() {
1754 Source source = addSource(''' 1634 Source source = addSource('''
1755 import 'dart:async'; 1635 import 'dart:async';
1756 Stream<int> f() async* { 1636 Stream<int> f() async* {
1757 } 1637 }
1758 '''); 1638 ''');
1759 computeLibrarySourceErrors(source);
1760 assertNoErrors(source); 1639 assertNoErrors(source);
1761 verify([source]); 1640 verify([source]);
1762 } 1641 }
1763 1642
1764 void test_empty_generator_sync() { 1643 void test_empty_generator_sync() {
1765 Source source = addSource(''' 1644 Source source = addSource('''
1766 Iterable<int> f() sync* { 1645 Iterable<int> f() sync* {
1767 } 1646 }
1768 '''); 1647 ''');
1769 computeLibrarySourceErrors(source);
1770 assertNoErrors(source); 1648 assertNoErrors(source);
1771 verify([source]); 1649 verify([source]);
1772 } 1650 }
1773 1651
1774 void test_expectedOneListTypeArgument() { 1652 void test_expectedOneListTypeArgument() {
1775 Source source = addSource(r''' 1653 Source source = addSource(r'''
1776 main() { 1654 main() {
1777 <int> []; 1655 <int> [];
1778 }'''); 1656 }''');
1779 computeLibrarySourceErrors(source);
1780 assertNoErrors(source); 1657 assertNoErrors(source);
1781 verify([source]); 1658 verify([source]);
1782 } 1659 }
1783 1660
1784 void test_expectedTwoMapTypeArguments() { 1661 void test_expectedTwoMapTypeArguments() {
1785 Source source = addSource(r''' 1662 Source source = addSource(r'''
1786 main() { 1663 main() {
1787 <int, int> {}; 1664 <int, int> {};
1788 }'''); 1665 }''');
1789 computeLibrarySourceErrors(source);
1790 assertNoErrors(source); 1666 assertNoErrors(source);
1791 verify([source]); 1667 verify([source]);
1792 } 1668 }
1793 1669
1794 void test_exportDuplicatedLibraryUnnamed() { 1670 void test_exportDuplicatedLibraryUnnamed() {
1795 Source source = addSource(r''' 1671 Source source = addSource(r'''
1796 library test; 1672 library test;
1797 export 'lib1.dart'; 1673 export 'lib1.dart';
1798 export 'lib2.dart';'''); 1674 export 'lib2.dart';''');
1799 addNamedSource("/lib1.dart", ""); 1675 addNamedSource("/lib1.dart", "");
1800 addNamedSource("/lib2.dart", ""); 1676 addNamedSource("/lib2.dart", "");
1801 computeLibrarySourceErrors(source);
1802 assertNoErrors(source); 1677 assertNoErrors(source);
1803 verify([source]); 1678 verify([source]);
1804 } 1679 }
1805 1680
1806 void test_exportOfNonLibrary_libraryDeclared() { 1681 void test_exportOfNonLibrary_libraryDeclared() {
1807 Source source = addSource(r''' 1682 Source source = addSource(r'''
1808 library L; 1683 library L;
1809 export 'lib1.dart';'''); 1684 export 'lib1.dart';''');
1810 addNamedSource("/lib1.dart", "library lib1;"); 1685 addNamedSource("/lib1.dart", "library lib1;");
1811 computeLibrarySourceErrors(source);
1812 assertNoErrors(source); 1686 assertNoErrors(source);
1813 verify([source]); 1687 verify([source]);
1814 } 1688 }
1815 1689
1816 void test_exportOfNonLibrary_libraryNotDeclared() { 1690 void test_exportOfNonLibrary_libraryNotDeclared() {
1817 Source source = addSource(r''' 1691 Source source = addSource(r'''
1818 library L; 1692 library L;
1819 export 'lib1.dart';'''); 1693 export 'lib1.dart';''');
1820 addNamedSource("/lib1.dart", ""); 1694 addNamedSource("/lib1.dart", "");
1821 computeLibrarySourceErrors(source);
1822 assertNoErrors(source); 1695 assertNoErrors(source);
1823 verify([source]); 1696 verify([source]);
1824 } 1697 }
1825 1698
1826 void test_extraPositionalArguments_function() { 1699 void test_extraPositionalArguments_function() {
1827 Source source = addSource(r''' 1700 Source source = addSource(r'''
1828 f(p1, p2) {} 1701 f(p1, p2) {}
1829 main() { 1702 main() {
1830 f(1, 2); 1703 f(1, 2);
1831 }'''); 1704 }''');
1832 computeLibrarySourceErrors(source);
1833 assertNoErrors(source); 1705 assertNoErrors(source);
1834 verify([source]); 1706 verify([source]);
1835 } 1707 }
1836 1708
1837 void test_extraPositionalArguments_Function() { 1709 void test_extraPositionalArguments_Function() {
1838 Source source = addSource(r''' 1710 Source source = addSource(r'''
1839 f(Function a) { 1711 f(Function a) {
1840 a(1, 2); 1712 a(1, 2);
1841 }'''); 1713 }''');
1842 computeLibrarySourceErrors(source);
1843 assertNoErrors(source); 1714 assertNoErrors(source);
1844 verify([source]); 1715 verify([source]);
1845 } 1716 }
1846 1717
1847 void test_extraPositionalArguments_implicitConstructor() { 1718 void test_extraPositionalArguments_implicitConstructor() {
1848 Source source = addSource(r''' 1719 Source source = addSource(r'''
1849 class A<E extends num> { 1720 class A<E extends num> {
1850 A(E x, E y); 1721 A(E x, E y);
1851 } 1722 }
1852 class M {} 1723 class M {}
1853 class B<E extends num> = A<E> with M; 1724 class B<E extends num> = A<E> with M;
1854 void main() { 1725 void main() {
1855 B<int> x = new B<int>(0,0); 1726 B<int> x = new B<int>(0,0);
1856 }'''); 1727 }''');
1857 computeLibrarySourceErrors(source);
1858 assertNoErrors(source); 1728 assertNoErrors(source);
1859 verify([source]); 1729 verify([source]);
1860 } 1730 }
1861 1731
1862 void test_extraPositionalArguments_typedef_local() { 1732 void test_extraPositionalArguments_typedef_local() {
1863 Source source = addSource(r''' 1733 Source source = addSource(r'''
1864 typedef A(p1, p2); 1734 typedef A(p1, p2);
1865 A getA() => null; 1735 A getA() => null;
1866 f() { 1736 f() {
1867 A a = getA(); 1737 A a = getA();
1868 a(1, 2); 1738 a(1, 2);
1869 }'''); 1739 }''');
1870 computeLibrarySourceErrors(source);
1871 assertNoErrors(source); 1740 assertNoErrors(source);
1872 verify([source]); 1741 verify([source]);
1873 } 1742 }
1874 1743
1875 void test_extraPositionalArguments_typedef_parameter() { 1744 void test_extraPositionalArguments_typedef_parameter() {
1876 Source source = addSource(r''' 1745 Source source = addSource(r'''
1877 typedef A(p1, p2); 1746 typedef A(p1, p2);
1878 f(A a) { 1747 f(A a) {
1879 a(1, 2); 1748 a(1, 2);
1880 }'''); 1749 }''');
1881 computeLibrarySourceErrors(source);
1882 assertNoErrors(source); 1750 assertNoErrors(source);
1883 verify([source]); 1751 verify([source]);
1884 } 1752 }
1885 1753
1886 void test_fieldInitializedByMultipleInitializers() { 1754 void test_fieldInitializedByMultipleInitializers() {
1887 Source source = addSource(r''' 1755 Source source = addSource(r'''
1888 class A { 1756 class A {
1889 int x; 1757 int x;
1890 int y; 1758 int y;
1891 A() : x = 0, y = 0 {} 1759 A() : x = 0, y = 0 {}
1892 }'''); 1760 }''');
1893 computeLibrarySourceErrors(source);
1894 assertNoErrors(source); 1761 assertNoErrors(source);
1895 verify([source]); 1762 verify([source]);
1896 } 1763 }
1897 1764
1898 void test_fieldInitializedInInitializerAndDeclaration_fieldNotFinal() { 1765 void test_fieldInitializedInInitializerAndDeclaration_fieldNotFinal() {
1899 Source source = addSource(r''' 1766 Source source = addSource(r'''
1900 class A { 1767 class A {
1901 int x = 0; 1768 int x = 0;
1902 A() : x = 1 {} 1769 A() : x = 1 {}
1903 }'''); 1770 }''');
1904 computeLibrarySourceErrors(source);
1905 assertNoErrors(source); 1771 assertNoErrors(source);
1906 verify([source]); 1772 verify([source]);
1907 } 1773 }
1908 1774
1909 void test_fieldInitializedInInitializerAndDeclaration_finalFieldNotSet() { 1775 void test_fieldInitializedInInitializerAndDeclaration_finalFieldNotSet() {
1910 Source source = addSource(r''' 1776 Source source = addSource(r'''
1911 class A { 1777 class A {
1912 final int x; 1778 final int x;
1913 A() : x = 1 {} 1779 A() : x = 1 {}
1914 }'''); 1780 }''');
1915 computeLibrarySourceErrors(source);
1916 assertNoErrors(source); 1781 assertNoErrors(source);
1917 verify([source]); 1782 verify([source]);
1918 } 1783 }
1919 1784
1920 void test_fieldInitializerOutsideConstructor() { 1785 void test_fieldInitializerOutsideConstructor() {
1921 Source source = addSource(r''' 1786 Source source = addSource(r'''
1922 class A { 1787 class A {
1923 int x; 1788 int x;
1924 A(this.x) {} 1789 A(this.x) {}
1925 }'''); 1790 }''');
1926 computeLibrarySourceErrors(source);
1927 assertNoErrors(source); 1791 assertNoErrors(source);
1928 verify([source]); 1792 verify([source]);
1929 } 1793 }
1930 1794
1931 void test_fieldInitializerOutsideConstructor_defaultParameters() { 1795 void test_fieldInitializerOutsideConstructor_defaultParameters() {
1932 Source source = addSource(r''' 1796 Source source = addSource(r'''
1933 class A { 1797 class A {
1934 int x; 1798 int x;
1935 A([this.x]) {} 1799 A([this.x]) {}
1936 }'''); 1800 }''');
1937 computeLibrarySourceErrors(source);
1938 assertNoErrors(source); 1801 assertNoErrors(source);
1939 verify([source]); 1802 verify([source]);
1940 } 1803 }
1941 1804
1942 void test_fieldInitializerRedirectingConstructor_super() { 1805 void test_fieldInitializerRedirectingConstructor_super() {
1943 Source source = addSource(r''' 1806 Source source = addSource(r'''
1944 class A { 1807 class A {
1945 A() {} 1808 A() {}
1946 } 1809 }
1947 class B extends A { 1810 class B extends A {
1948 int x; 1811 int x;
1949 B(this.x) : super(); 1812 B(this.x) : super();
1950 }'''); 1813 }''');
1951 computeLibrarySourceErrors(source);
1952 assertNoErrors(source); 1814 assertNoErrors(source);
1953 verify([source]); 1815 verify([source]);
1954 } 1816 }
1955 1817
1956 void test_finalInitializedInDeclarationAndConstructor_initializer() { 1818 void test_finalInitializedInDeclarationAndConstructor_initializer() {
1957 Source source = addSource(r''' 1819 Source source = addSource(r'''
1958 class A { 1820 class A {
1959 final x; 1821 final x;
1960 A() : x = 1 {} 1822 A() : x = 1 {}
1961 }'''); 1823 }''');
1962 computeLibrarySourceErrors(source);
1963 assertNoErrors(source); 1824 assertNoErrors(source);
1964 verify([source]); 1825 verify([source]);
1965 } 1826 }
1966 1827
1967 void test_finalInitializedInDeclarationAndConstructor_initializingFormal() { 1828 void test_finalInitializedInDeclarationAndConstructor_initializingFormal() {
1968 Source source = addSource(r''' 1829 Source source = addSource(r'''
1969 class A { 1830 class A {
1970 final x; 1831 final x;
1971 A(this.x) {} 1832 A(this.x) {}
1972 }'''); 1833 }''');
1973 computeLibrarySourceErrors(source);
1974 assertNoErrors(source); 1834 assertNoErrors(source);
1975 verify([source]); 1835 verify([source]);
1976 } 1836 }
1977 1837
1978 void test_finalNotInitialized_atDeclaration() { 1838 void test_finalNotInitialized_atDeclaration() {
1979 Source source = addSource(r''' 1839 Source source = addSource(r'''
1980 class A { 1840 class A {
1981 final int x = 0; 1841 final int x = 0;
1982 A() {} 1842 A() {}
1983 }'''); 1843 }''');
1984 computeLibrarySourceErrors(source);
1985 assertNoErrors(source); 1844 assertNoErrors(source);
1986 verify([source]); 1845 verify([source]);
1987 } 1846 }
1988 1847
1989 void test_finalNotInitialized_fieldFormal() { 1848 void test_finalNotInitialized_fieldFormal() {
1990 Source source = addSource(r''' 1849 Source source = addSource(r'''
1991 class A { 1850 class A {
1992 final int x = 0; 1851 final int x = 0;
1993 A() {} 1852 A() {}
1994 }'''); 1853 }''');
1995 computeLibrarySourceErrors(source);
1996 assertNoErrors(source); 1854 assertNoErrors(source);
1997 verify([source]); 1855 verify([source]);
1998 } 1856 }
1999 1857
2000 void test_finalNotInitialized_functionTypedFieldFormal() { 1858 void test_finalNotInitialized_functionTypedFieldFormal() {
2001 Source source = addSource(r''' 1859 Source source = addSource(r'''
2002 class A { 1860 class A {
2003 final Function x; 1861 final Function x;
2004 A(int this.x(int p)) {} 1862 A(int this.x(int p)) {}
2005 }'''); 1863 }''');
2006 computeLibrarySourceErrors(source);
2007 assertNoErrors(source); 1864 assertNoErrors(source);
2008 verify([source]); 1865 verify([source]);
2009 } 1866 }
2010 1867
2011 void test_finalNotInitialized_hasNativeClause_hasConstructor() { 1868 void test_finalNotInitialized_hasNativeClause_hasConstructor() {
2012 Source source = addSource(r''' 1869 Source source = addSource(r'''
2013 class A native 'something' { 1870 class A native 'something' {
2014 final int x; 1871 final int x;
2015 A() {} 1872 A() {}
2016 }'''); 1873 }''');
2017 computeLibrarySourceErrors(source);
2018 assertErrors(source, [ParserErrorCode.NATIVE_CLAUSE_IN_NON_SDK_CODE]); 1874 assertErrors(source, [ParserErrorCode.NATIVE_CLAUSE_IN_NON_SDK_CODE]);
2019 verify([source]); 1875 verify([source]);
2020 } 1876 }
2021 1877
2022 void test_finalNotInitialized_hasNativeClause_noConstructor() { 1878 void test_finalNotInitialized_hasNativeClause_noConstructor() {
2023 Source source = addSource(r''' 1879 Source source = addSource(r'''
2024 class A native 'something' { 1880 class A native 'something' {
2025 final int x; 1881 final int x;
2026 }'''); 1882 }''');
2027 computeLibrarySourceErrors(source);
2028 assertErrors(source, [ParserErrorCode.NATIVE_CLAUSE_IN_NON_SDK_CODE]); 1883 assertErrors(source, [ParserErrorCode.NATIVE_CLAUSE_IN_NON_SDK_CODE]);
2029 verify([source]); 1884 verify([source]);
2030 } 1885 }
2031 1886
2032 void test_finalNotInitialized_initializer() { 1887 void test_finalNotInitialized_initializer() {
2033 Source source = addSource(r''' 1888 Source source = addSource(r'''
2034 class A { 1889 class A {
2035 final int x; 1890 final int x;
2036 A() : x = 0 {} 1891 A() : x = 0 {}
2037 }'''); 1892 }''');
2038 computeLibrarySourceErrors(source);
2039 assertNoErrors(source); 1893 assertNoErrors(source);
2040 verify([source]); 1894 verify([source]);
2041 } 1895 }
2042 1896
2043 void test_finalNotInitialized_redirectingConstructor() { 1897 void test_finalNotInitialized_redirectingConstructor() {
2044 Source source = addSource(r''' 1898 Source source = addSource(r'''
2045 class A { 1899 class A {
2046 final int x; 1900 final int x;
2047 A(this.x); 1901 A(this.x);
2048 A.named() : this (42); 1902 A.named() : this (42);
2049 }'''); 1903 }''');
2050 computeLibrarySourceErrors(source);
2051 assertNoErrors(source); 1904 assertNoErrors(source);
2052 verify([source]); 1905 verify([source]);
2053 } 1906 }
2054 1907
2055 void test_functionDeclaration_scope_returnType() { 1908 void test_functionDeclaration_scope_returnType() {
2056 Source source = addSource("int f(int) { return 0; }"); 1909 Source source = addSource("int f(int) { return 0; }");
2057 computeLibrarySourceErrors(source);
2058 assertNoErrors(source); 1910 assertNoErrors(source);
2059 verify([source]); 1911 verify([source]);
2060 } 1912 }
2061 1913
2062 void test_functionDeclaration_scope_signature() { 1914 void test_functionDeclaration_scope_signature() {
2063 Source source = addSource(r''' 1915 Source source = addSource(r'''
2064 const app = 0; 1916 const app = 0;
2065 f(@app int app) {}'''); 1917 f(@app int app) {}''');
2066 computeLibrarySourceErrors(source);
2067 assertNoErrors(source); 1918 assertNoErrors(source);
2068 verify([source]); 1919 verify([source]);
2069 } 1920 }
2070 1921
2071 void test_functionTypeAlias_scope_returnType() { 1922 void test_functionTypeAlias_scope_returnType() {
2072 Source source = addSource("typedef int f(int);"); 1923 Source source = addSource("typedef int f(int);");
2073 computeLibrarySourceErrors(source);
2074 assertNoErrors(source); 1924 assertNoErrors(source);
2075 verify([source]); 1925 verify([source]);
2076 } 1926 }
2077 1927
2078 void test_functionTypeAlias_scope_signature() { 1928 void test_functionTypeAlias_scope_signature() {
2079 Source source = addSource(r''' 1929 Source source = addSource(r'''
2080 const app = 0; 1930 const app = 0;
2081 typedef int f(@app int app);'''); 1931 typedef int f(@app int app);''');
2082 computeLibrarySourceErrors(source);
2083 assertNoErrors(source); 1932 assertNoErrors(source);
2084 verify([source]); 1933 verify([source]);
2085 } 1934 }
2086 1935
2087 void test_functionWithoutCall() { 1936 void test_functionWithoutCall() {
2088 Source source = addSource(r''' 1937 Source source = addSource(r'''
2089 abstract class A implements Function { 1938 abstract class A implements Function {
2090 } 1939 }
2091 class B implements A { 1940 class B implements A {
2092 void call() {} 1941 void call() {}
2093 } 1942 }
2094 class C extends A { 1943 class C extends A {
2095 void call() {} 1944 void call() {}
2096 } 1945 }
2097 class D extends C { 1946 class D extends C {
2098 }'''); 1947 }''');
2099 computeLibrarySourceErrors(source);
2100 assertNoErrors(source); 1948 assertNoErrors(source);
2101 verify([source]); 1949 verify([source]);
2102 } 1950 }
2103 1951
2104 void test_functionWithoutCall_doesNotImplementFunction() { 1952 void test_functionWithoutCall_doesNotImplementFunction() {
2105 Source source = addSource("class A {}"); 1953 Source source = addSource("class A {}");
2106 computeLibrarySourceErrors(source);
2107 assertNoErrors(source); 1954 assertNoErrors(source);
2108 verify([source]); 1955 verify([source]);
2109 } 1956 }
2110 1957
2111 void test_functionWithoutCall_staticCallMethod() { 1958 void test_functionWithoutCall_staticCallMethod() {
2112 Source source = addSource(r''' 1959 Source source = addSource(r'''
2113 class A { } 1960 class A { }
2114 class B extends A { 1961 class B extends A {
2115 static call() { } 1962 static call() { }
2116 } 1963 }
2117 '''); 1964 ''');
2118 computeLibrarySourceErrors(source);
2119 assertNoErrors(source); 1965 assertNoErrors(source);
2120 verify([source]); 1966 verify([source]);
2121 } 1967 }
2122 1968
2123 void test_functionWithoutCall_withNoSuchMethod() { 1969 void test_functionWithoutCall_withNoSuchMethod() {
2124 // 16078 1970 // 16078
2125 Source source = addSource(r''' 1971 Source source = addSource(r'''
2126 class A implements Function { 1972 class A implements Function {
2127 noSuchMethod(inv) { 1973 noSuchMethod(inv) {
2128 return 42; 1974 return 42;
2129 } 1975 }
2130 }'''); 1976 }''');
2131 computeLibrarySourceErrors(source);
2132 assertNoErrors(source); 1977 assertNoErrors(source);
2133 verify([source]); 1978 verify([source]);
2134 } 1979 }
2135 1980
2136 void test_functionWithoutCall_withNoSuchMethod_mixin() { 1981 void test_functionWithoutCall_withNoSuchMethod_mixin() {
2137 Source source = addSource(r''' 1982 Source source = addSource(r'''
2138 class A { 1983 class A {
2139 noSuchMethod(inv) {} 1984 noSuchMethod(inv) {}
2140 } 1985 }
2141 class B extends Object with A implements Function { 1986 class B extends Object with A implements Function {
2142 }'''); 1987 }''');
2143 computeLibrarySourceErrors(source);
2144 assertNoErrors(source); 1988 assertNoErrors(source);
2145 verify([source]); 1989 verify([source]);
2146 } 1990 }
2147 1991
2148 void test_functionWithoutCall_withNoSuchMethod_superclass() { 1992 void test_functionWithoutCall_withNoSuchMethod_superclass() {
2149 Source source = addSource(r''' 1993 Source source = addSource(r'''
2150 class A { 1994 class A {
2151 noSuchMethod(inv) {} 1995 noSuchMethod(inv) {}
2152 } 1996 }
2153 class B extends A implements Function { 1997 class B extends A implements Function {
2154 }'''); 1998 }''');
2155 computeLibrarySourceErrors(source);
2156 assertNoErrors(source); 1999 assertNoErrors(source);
2157 verify([source]); 2000 verify([source]);
2158 } 2001 }
2159 2002
2160 void test_implicitConstructorDependencies() { 2003 void test_implicitConstructorDependencies() {
2161 // No warning should be generated for the code below; this requires that 2004 // No warning should be generated for the code below; this requires that
2162 // implicit constructors are generated for C1 before C2, even though C1 2005 // implicit constructors are generated for C1 before C2, even though C1
2163 // follows C2 in the file. See dartbug.com/21600. 2006 // follows C2 in the file. See dartbug.com/21600.
2164 Source source = addSource(r''' 2007 Source source = addSource(r'''
2165 class B { 2008 class B {
2166 B(int i); 2009 B(int i);
2167 } 2010 }
2168 class M1 {} 2011 class M1 {}
2169 class M2 {} 2012 class M2 {}
2170 2013
2171 class C2 = C1 with M2; 2014 class C2 = C1 with M2;
2172 class C1 = B with M1; 2015 class C1 = B with M1;
2173 2016
2174 main() { 2017 main() {
2175 new C2(5); 2018 new C2(5);
2176 } 2019 }
2177 '''); 2020 ''');
2178 computeLibrarySourceErrors(source);
2179 assertNoErrors(source); 2021 assertNoErrors(source);
2180 verify([source]); 2022 verify([source]);
2181 } 2023 }
2182 2024
2183 void test_implicitThisReferenceInInitializer_constructorName() { 2025 void test_implicitThisReferenceInInitializer_constructorName() {
2184 Source source = addSource(r''' 2026 Source source = addSource(r'''
2185 class A { 2027 class A {
2186 A.named() {} 2028 A.named() {}
2187 } 2029 }
2188 class B { 2030 class B {
2189 var v; 2031 var v;
2190 B() : v = new A.named(); 2032 B() : v = new A.named();
2191 }'''); 2033 }''');
2192 computeLibrarySourceErrors(source);
2193 assertNoErrors(source); 2034 assertNoErrors(source);
2194 verify([source]); 2035 verify([source]);
2195 } 2036 }
2196 2037
2197 void test_implicitThisReferenceInInitializer_importPrefix() { 2038 void test_implicitThisReferenceInInitializer_importPrefix() {
2198 Source source = addSource(r''' 2039 Source source = addSource(r'''
2199 import 'dart:async' as abstract; 2040 import 'dart:async' as abstract;
2200 class A { 2041 class A {
2201 var v = new abstract.Completer(); 2042 var v = new abstract.Completer();
2202 }'''); 2043 }''');
2203 computeLibrarySourceErrors(source);
2204 assertNoErrors(source); 2044 assertNoErrors(source);
2205 verify([source]); 2045 verify([source]);
2206 } 2046 }
2207 2047
2208 void test_implicitThisReferenceInInitializer_prefixedIdentifier() { 2048 void test_implicitThisReferenceInInitializer_prefixedIdentifier() {
2209 Source source = addSource(r''' 2049 Source source = addSource(r'''
2210 class A { 2050 class A {
2211 var f; 2051 var f;
2212 } 2052 }
2213 class B { 2053 class B {
2214 var v; 2054 var v;
2215 B(A a) : v = a.f; 2055 B(A a) : v = a.f;
2216 }'''); 2056 }''');
2217 computeLibrarySourceErrors(source);
2218 assertNoErrors(source); 2057 assertNoErrors(source);
2219 verify([source]); 2058 verify([source]);
2220 } 2059 }
2221 2060
2222 void test_implicitThisReferenceInInitializer_qualifiedMethodInvocation() { 2061 void test_implicitThisReferenceInInitializer_qualifiedMethodInvocation() {
2223 Source source = addSource(r''' 2062 Source source = addSource(r'''
2224 class A { 2063 class A {
2225 f() {} 2064 f() {}
2226 } 2065 }
2227 class B { 2066 class B {
2228 var v; 2067 var v;
2229 B() : v = new A().f(); 2068 B() : v = new A().f();
2230 }'''); 2069 }''');
2231 computeLibrarySourceErrors(source);
2232 assertNoErrors(source); 2070 assertNoErrors(source);
2233 verify([source]); 2071 verify([source]);
2234 } 2072 }
2235 2073
2236 void test_implicitThisReferenceInInitializer_qualifiedPropertyAccess() { 2074 void test_implicitThisReferenceInInitializer_qualifiedPropertyAccess() {
2237 Source source = addSource(r''' 2075 Source source = addSource(r'''
2238 class A { 2076 class A {
2239 var f; 2077 var f;
2240 } 2078 }
2241 class B { 2079 class B {
2242 var v; 2080 var v;
2243 B() : v = new A().f; 2081 B() : v = new A().f;
2244 }'''); 2082 }''');
2245 computeLibrarySourceErrors(source);
2246 assertNoErrors(source); 2083 assertNoErrors(source);
2247 verify([source]); 2084 verify([source]);
2248 } 2085 }
2249 2086
2250 void test_implicitThisReferenceInInitializer_staticField_thisClass() { 2087 void test_implicitThisReferenceInInitializer_staticField_thisClass() {
2251 Source source = addSource(r''' 2088 Source source = addSource(r'''
2252 class A { 2089 class A {
2253 var v; 2090 var v;
2254 A() : v = f; 2091 A() : v = f;
2255 static var f; 2092 static var f;
2256 }'''); 2093 }''');
2257 computeLibrarySourceErrors(source);
2258 assertNoErrors(source); 2094 assertNoErrors(source);
2259 verify([source]); 2095 verify([source]);
2260 } 2096 }
2261 2097
2262 void test_implicitThisReferenceInInitializer_staticGetter() { 2098 void test_implicitThisReferenceInInitializer_staticGetter() {
2263 Source source = addSource(r''' 2099 Source source = addSource(r'''
2264 class A { 2100 class A {
2265 var v; 2101 var v;
2266 A() : v = f; 2102 A() : v = f;
2267 static get f => 42; 2103 static get f => 42;
2268 }'''); 2104 }''');
2269 computeLibrarySourceErrors(source);
2270 assertNoErrors(source); 2105 assertNoErrors(source);
2271 verify([source]); 2106 verify([source]);
2272 } 2107 }
2273 2108
2274 void test_implicitThisReferenceInInitializer_staticMethod() { 2109 void test_implicitThisReferenceInInitializer_staticMethod() {
2275 Source source = addSource(r''' 2110 Source source = addSource(r'''
2276 class A { 2111 class A {
2277 var v; 2112 var v;
2278 A() : v = f(); 2113 A() : v = f();
2279 static f() => 42; 2114 static f() => 42;
2280 }'''); 2115 }''');
2281 computeLibrarySourceErrors(source);
2282 assertNoErrors(source); 2116 assertNoErrors(source);
2283 verify([source]); 2117 verify([source]);
2284 } 2118 }
2285 2119
2286 void test_implicitThisReferenceInInitializer_topLevelField() { 2120 void test_implicitThisReferenceInInitializer_topLevelField() {
2287 Source source = addSource(r''' 2121 Source source = addSource(r'''
2288 class A { 2122 class A {
2289 var v; 2123 var v;
2290 A() : v = f; 2124 A() : v = f;
2291 } 2125 }
2292 var f = 42;'''); 2126 var f = 42;''');
2293 computeLibrarySourceErrors(source);
2294 assertNoErrors(source); 2127 assertNoErrors(source);
2295 verify([source]); 2128 verify([source]);
2296 } 2129 }
2297 2130
2298 void test_implicitThisReferenceInInitializer_topLevelFunction() { 2131 void test_implicitThisReferenceInInitializer_topLevelFunction() {
2299 Source source = addSource(r''' 2132 Source source = addSource(r'''
2300 class A { 2133 class A {
2301 var v; 2134 var v;
2302 A() : v = f(); 2135 A() : v = f();
2303 } 2136 }
2304 f() => 42;'''); 2137 f() => 42;''');
2305 computeLibrarySourceErrors(source);
2306 assertNoErrors(source); 2138 assertNoErrors(source);
2307 verify([source]); 2139 verify([source]);
2308 } 2140 }
2309 2141
2310 void test_implicitThisReferenceInInitializer_topLevelGetter() { 2142 void test_implicitThisReferenceInInitializer_topLevelGetter() {
2311 Source source = addSource(r''' 2143 Source source = addSource(r'''
2312 class A { 2144 class A {
2313 var v; 2145 var v;
2314 A() : v = f; 2146 A() : v = f;
2315 } 2147 }
2316 get f => 42;'''); 2148 get f => 42;''');
2317 computeLibrarySourceErrors(source);
2318 assertNoErrors(source); 2149 assertNoErrors(source);
2319 verify([source]); 2150 verify([source]);
2320 } 2151 }
2321 2152
2322 void test_implicitThisReferenceInInitializer_typeParameter() { 2153 void test_implicitThisReferenceInInitializer_typeParameter() {
2323 Source source = addSource(r''' 2154 Source source = addSource(r'''
2324 class A<T> { 2155 class A<T> {
2325 var v; 2156 var v;
2326 A(p) : v = (p is T); 2157 A(p) : v = (p is T);
2327 }'''); 2158 }''');
2328 computeLibrarySourceErrors(source);
2329 assertNoErrors(source); 2159 assertNoErrors(source);
2330 verify([source]); 2160 verify([source]);
2331 } 2161 }
2332 2162
2333 void test_importDuplicatedLibraryName() { 2163 void test_importDuplicatedLibraryName() {
2334 Source source = addSource(r''' 2164 Source source = addSource(r'''
2335 library test; 2165 library test;
2336 import 'lib.dart'; 2166 import 'lib.dart';
2337 import 'lib.dart';'''); 2167 import 'lib.dart';''');
2338 addNamedSource("/lib.dart", "library lib;"); 2168 addNamedSource("/lib.dart", "library lib;");
2339 computeLibrarySourceErrors(source);
2340 assertErrors(source, [ 2169 assertErrors(source, [
2341 HintCode.UNUSED_IMPORT, 2170 HintCode.UNUSED_IMPORT,
2342 HintCode.UNUSED_IMPORT, 2171 HintCode.UNUSED_IMPORT,
2343 HintCode.DUPLICATE_IMPORT 2172 HintCode.DUPLICATE_IMPORT
2344 ]); 2173 ]);
2345 verify([source]); 2174 verify([source]);
2346 } 2175 }
2347 2176
2348 void test_importDuplicatedLibraryUnnamed() { 2177 void test_importDuplicatedLibraryUnnamed() {
2349 Source source = addSource(r''' 2178 Source source = addSource(r'''
2350 library test; 2179 library test;
2351 import 'lib1.dart'; 2180 import 'lib1.dart';
2352 import 'lib2.dart';'''); 2181 import 'lib2.dart';''');
2353 addNamedSource("/lib1.dart", ""); 2182 addNamedSource("/lib1.dart", "");
2354 addNamedSource("/lib2.dart", ""); 2183 addNamedSource("/lib2.dart", "");
2355 computeLibrarySourceErrors(source);
2356 assertErrors(source, [ 2184 assertErrors(source, [
2357 // No warning on duplicate import (https://github.com/dart-lang/sdk/issues /24156) 2185 // No warning on duplicate import (https://github.com/dart-lang/sdk/issues /24156)
2358 HintCode.UNUSED_IMPORT, 2186 HintCode.UNUSED_IMPORT,
2359 HintCode.UNUSED_IMPORT 2187 HintCode.UNUSED_IMPORT
2360 ]); 2188 ]);
2361 verify([source]); 2189 verify([source]);
2362 } 2190 }
2363 2191
2364 void test_importOfNonLibrary_libraryDeclared() { 2192 void test_importOfNonLibrary_libraryDeclared() {
2365 Source source = addSource(r''' 2193 Source source = addSource(r'''
2366 library lib; 2194 library lib;
2367 import 'part.dart'; 2195 import 'part.dart';
2368 A a;'''); 2196 A a;''');
2369 addNamedSource( 2197 addNamedSource(
2370 "/part.dart", 2198 "/part.dart",
2371 r''' 2199 r'''
2372 library lib1; 2200 library lib1;
2373 class A {}'''); 2201 class A {}''');
2374 computeLibrarySourceErrors(source);
2375 assertNoErrors(source); 2202 assertNoErrors(source);
2376 verify([source]); 2203 verify([source]);
2377 } 2204 }
2378 2205
2379 void test_importOfNonLibrary_libraryNotDeclared() { 2206 void test_importOfNonLibrary_libraryNotDeclared() {
2380 Source source = addSource(r''' 2207 Source source = addSource(r'''
2381 library lib; 2208 library lib;
2382 import 'part.dart'; 2209 import 'part.dart';
2383 A a;'''); 2210 A a;''');
2384 addNamedSource("/part.dart", "class A {}"); 2211 addNamedSource("/part.dart", "class A {}");
2385 computeLibrarySourceErrors(source);
2386 assertNoErrors(source); 2212 assertNoErrors(source);
2387 verify([source]); 2213 verify([source]);
2388 } 2214 }
2389 2215
2390 void test_importPrefixes_withFirstLetterDifference() { 2216 void test_importPrefixes_withFirstLetterDifference() {
2391 Source source = addSource(r''' 2217 Source source = addSource(r'''
2392 library L; 2218 library L;
2393 import 'lib1.dart' as math; 2219 import 'lib1.dart' as math;
2394 import 'lib2.dart' as path; 2220 import 'lib2.dart' as path;
2395 main() { 2221 main() {
2396 math.test1(); 2222 math.test1();
2397 path.test2(); 2223 path.test2();
2398 }'''); 2224 }''');
2399 addNamedSource( 2225 addNamedSource(
2400 "/lib1.dart", 2226 "/lib1.dart",
2401 r''' 2227 r'''
2402 library lib1; 2228 library lib1;
2403 test1() {}'''); 2229 test1() {}''');
2404 addNamedSource( 2230 addNamedSource(
2405 "/lib2.dart", 2231 "/lib2.dart",
2406 r''' 2232 r'''
2407 library lib2; 2233 library lib2;
2408 test2() {}'''); 2234 test2() {}''');
2409 computeLibrarySourceErrors(source);
2410 assertNoErrors(source); 2235 assertNoErrors(source);
2411 verify([source]); 2236 verify([source]);
2412 } 2237 }
2413 2238
2414 void test_inconsistentCaseExpressionTypes() { 2239 void test_inconsistentCaseExpressionTypes() {
2415 Source source = addSource(r''' 2240 Source source = addSource(r'''
2416 f(var p) { 2241 f(var p) {
2417 switch (p) { 2242 switch (p) {
2418 case 1: 2243 case 1:
2419 break; 2244 break;
2420 case 2: 2245 case 2:
2421 break; 2246 break;
2422 } 2247 }
2423 }'''); 2248 }''');
2424 computeLibrarySourceErrors(source);
2425 assertNoErrors(source); 2249 assertNoErrors(source);
2426 verify([source]); 2250 verify([source]);
2427 } 2251 }
2428 2252
2429 void test_inconsistentMethodInheritance_accessors_typeParameter2() { 2253 void test_inconsistentMethodInheritance_accessors_typeParameter2() {
2430 Source source = addSource(r''' 2254 Source source = addSource(r'''
2431 abstract class A<E> { 2255 abstract class A<E> {
2432 E get x {return null;} 2256 E get x {return null;}
2433 } 2257 }
2434 class B<E> { 2258 class B<E> {
2435 E get x {return null;} 2259 E get x {return null;}
2436 } 2260 }
2437 class C<E> extends A<E> implements B<E> {}'''); 2261 class C<E> extends A<E> implements B<E> {}''');
2438 computeLibrarySourceErrors(source);
2439 assertNoErrors(source); 2262 assertNoErrors(source);
2440 verify([source]); 2263 verify([source]);
2441 } 2264 }
2442 2265
2443 void test_inconsistentMethodInheritance_accessors_typeParameters1() { 2266 void test_inconsistentMethodInheritance_accessors_typeParameters1() {
2444 Source source = addSource(r''' 2267 Source source = addSource(r'''
2445 abstract class A<E> { 2268 abstract class A<E> {
2446 E get x; 2269 E get x;
2447 } 2270 }
2448 abstract class B<E> { 2271 abstract class B<E> {
2449 E get x; 2272 E get x;
2450 } 2273 }
2451 class C<E> implements A<E>, B<E> { 2274 class C<E> implements A<E>, B<E> {
2452 E get x => null; 2275 E get x => null;
2453 }'''); 2276 }''');
2454 computeLibrarySourceErrors(source);
2455 assertNoErrors(source); 2277 assertNoErrors(source);
2456 verify([source]); 2278 verify([source]);
2457 } 2279 }
2458 2280
2459 void test_inconsistentMethodInheritance_accessors_typeParameters_diamond() { 2281 void test_inconsistentMethodInheritance_accessors_typeParameters_diamond() {
2460 Source source = addSource(r''' 2282 Source source = addSource(r'''
2461 abstract class F<E> extends B<E> {} 2283 abstract class F<E> extends B<E> {}
2462 class D<E> extends F<E> { 2284 class D<E> extends F<E> {
2463 external E get g; 2285 external E get g;
2464 } 2286 }
2465 abstract class C<E> { 2287 abstract class C<E> {
2466 E get g; 2288 E get g;
2467 } 2289 }
2468 abstract class B<E> implements C<E> { 2290 abstract class B<E> implements C<E> {
2469 E get g { return null; } 2291 E get g { return null; }
2470 } 2292 }
2471 class A<E> extends B<E> implements D<E> { 2293 class A<E> extends B<E> implements D<E> {
2472 }'''); 2294 }''');
2473 computeLibrarySourceErrors(source);
2474 assertNoErrors(source); 2295 assertNoErrors(source);
2475 verify([source]); 2296 verify([source]);
2476 } 2297 }
2477 2298
2478 void test_inconsistentMethodInheritance_methods_typeParameter2() { 2299 void test_inconsistentMethodInheritance_methods_typeParameter2() {
2479 Source source = addSource(r''' 2300 Source source = addSource(r'''
2480 class A<E> { 2301 class A<E> {
2481 x(E e) {} 2302 x(E e) {}
2482 } 2303 }
2483 class B<E> { 2304 class B<E> {
2484 x(E e) {} 2305 x(E e) {}
2485 } 2306 }
2486 class C<E> extends A<E> implements B<E> { 2307 class C<E> extends A<E> implements B<E> {
2487 x(E e) {} 2308 x(E e) {}
2488 }'''); 2309 }''');
2489 computeLibrarySourceErrors(source);
2490 assertNoErrors(source); 2310 assertNoErrors(source);
2491 verify([source]); 2311 verify([source]);
2492 } 2312 }
2493 2313
2494 void test_inconsistentMethodInheritance_methods_typeParameters1() { 2314 void test_inconsistentMethodInheritance_methods_typeParameters1() {
2495 Source source = addSource(r''' 2315 Source source = addSource(r'''
2496 class A<E> { 2316 class A<E> {
2497 x(E e) {} 2317 x(E e) {}
2498 } 2318 }
2499 class B<E> { 2319 class B<E> {
2500 x(E e) {} 2320 x(E e) {}
2501 } 2321 }
2502 class C<E> implements A<E>, B<E> { 2322 class C<E> implements A<E>, B<E> {
2503 x(E e) {} 2323 x(E e) {}
2504 }'''); 2324 }''');
2505 computeLibrarySourceErrors(source);
2506 assertNoErrors(source); 2325 assertNoErrors(source);
2507 verify([source]); 2326 verify([source]);
2508 } 2327 }
2509 2328
2510 void test_inconsistentMethodInheritance_overrideTrumpsInherits_getter() { 2329 void test_inconsistentMethodInheritance_overrideTrumpsInherits_getter() {
2511 // 16134 2330 // 16134
2512 Source source = addSource(r''' 2331 Source source = addSource(r'''
2513 class B<S> { 2332 class B<S> {
2514 S get g => null; 2333 S get g => null;
2515 } 2334 }
2516 abstract class I<U> { 2335 abstract class I<U> {
2517 U get g => null; 2336 U get g => null;
2518 } 2337 }
2519 class C extends B<double> implements I<int> { 2338 class C extends B<double> implements I<int> {
2520 num get g => null; 2339 num get g => null;
2521 }'''); 2340 }''');
2522 computeLibrarySourceErrors(source);
2523 assertNoErrors(source); 2341 assertNoErrors(source);
2524 verify([source]); 2342 verify([source]);
2525 } 2343 }
2526 2344
2527 void test_inconsistentMethodInheritance_overrideTrumpsInherits_method() { 2345 void test_inconsistentMethodInheritance_overrideTrumpsInherits_method() {
2528 // 16134 2346 // 16134
2529 Source source = addSource(r''' 2347 Source source = addSource(r'''
2530 class B<S> { 2348 class B<S> {
2531 m(S s) => null; 2349 m(S s) => null;
2532 } 2350 }
2533 abstract class I<U> { 2351 abstract class I<U> {
2534 m(U u) => null; 2352 m(U u) => null;
2535 } 2353 }
2536 class C extends B<double> implements I<int> { 2354 class C extends B<double> implements I<int> {
2537 m(num n) => null; 2355 m(num n) => null;
2538 }'''); 2356 }''');
2539 computeLibrarySourceErrors(source);
2540 assertNoErrors(source); 2357 assertNoErrors(source);
2541 verify([source]); 2358 verify([source]);
2542 } 2359 }
2543 2360
2544 void test_inconsistentMethodInheritance_overrideTrumpsInherits_setter() { 2361 void test_inconsistentMethodInheritance_overrideTrumpsInherits_setter() {
2545 // 16134 2362 // 16134
2546 Source source = addSource(r''' 2363 Source source = addSource(r'''
2547 class B<S> { 2364 class B<S> {
2548 set t(S s) {} 2365 set t(S s) {}
2549 } 2366 }
2550 abstract class I<U> { 2367 abstract class I<U> {
2551 set t(U u) {} 2368 set t(U u) {}
2552 } 2369 }
2553 class C extends B<double> implements I<int> { 2370 class C extends B<double> implements I<int> {
2554 set t(num n) {} 2371 set t(num n) {}
2555 }'''); 2372 }''');
2556 computeLibrarySourceErrors(source);
2557 assertNoErrors(source); 2373 assertNoErrors(source);
2558 verify([source]); 2374 verify([source]);
2559 } 2375 }
2560 2376
2561 void test_inconsistentMethodInheritance_simple() { 2377 void test_inconsistentMethodInheritance_simple() {
2562 Source source = addSource(r''' 2378 Source source = addSource(r'''
2563 abstract class A { 2379 abstract class A {
2564 x(); 2380 x();
2565 } 2381 }
2566 abstract class B { 2382 abstract class B {
2567 x(); 2383 x();
2568 } 2384 }
2569 class C implements A, B { 2385 class C implements A, B {
2570 x() {} 2386 x() {}
2571 }'''); 2387 }''');
2572 computeLibrarySourceErrors(source);
2573 assertNoErrors(source); 2388 assertNoErrors(source);
2574 verify([source]); 2389 verify([source]);
2575 } 2390 }
2576 2391
2577 void test_initializingFormalForNonExistentField() { 2392 void test_initializingFormalForNonExistentField() {
2578 Source source = addSource(r''' 2393 Source source = addSource(r'''
2579 class A { 2394 class A {
2580 int x; 2395 int x;
2581 A(this.x) {} 2396 A(this.x) {}
2582 }'''); 2397 }''');
2583 computeLibrarySourceErrors(source);
2584 assertNoErrors(source); 2398 assertNoErrors(source);
2585 verify([source]); 2399 verify([source]);
2586 } 2400 }
2587 2401
2588 void test_instance_creation_inside_annotation() { 2402 void test_instance_creation_inside_annotation() {
2589 Source source = addSource(''' 2403 Source source = addSource('''
2590 class C { 2404 class C {
2591 const C(); 2405 const C();
2592 } 2406 }
2593 class D { 2407 class D {
2594 final C c; 2408 final C c;
2595 const D(this.c); 2409 const D(this.c);
2596 } 2410 }
2597 @D(const C()) 2411 @D(const C())
2598 f() {} 2412 f() {}
2599 '''); 2413 ''');
2600 computeLibrarySourceErrors(source);
2601 assertNoErrors(source); 2414 assertNoErrors(source);
2602 verify([source]); 2415 verify([source]);
2603 } 2416 }
2604 2417
2605 void test_instanceAccessToStaticMember_fromComment() { 2418 void test_instanceAccessToStaticMember_fromComment() {
2606 Source source = addSource(r''' 2419 Source source = addSource(r'''
2607 class A { 2420 class A {
2608 static m() {} 2421 static m() {}
2609 } 2422 }
2610 /// [A.m] 2423 /// [A.m]
2611 main() { 2424 main() {
2612 }'''); 2425 }''');
2613 computeLibrarySourceErrors(source);
2614 assertNoErrors(source); 2426 assertNoErrors(source);
2615 verify([source]); 2427 verify([source]);
2616 } 2428 }
2617 2429
2618 void test_instanceAccessToStaticMember_topLevel() { 2430 void test_instanceAccessToStaticMember_topLevel() {
2619 Source source = addSource(r''' 2431 Source source = addSource(r'''
2620 m() {} 2432 m() {}
2621 main() { 2433 main() {
2622 m(); 2434 m();
2623 }'''); 2435 }''');
2624 computeLibrarySourceErrors(source);
2625 assertNoErrors(source); 2436 assertNoErrors(source);
2626 verify([source]); 2437 verify([source]);
2627 } 2438 }
2628 2439
2629 void test_instanceMemberAccessFromStatic_fromComment() { 2440 void test_instanceMemberAccessFromStatic_fromComment() {
2630 Source source = addSource(r''' 2441 Source source = addSource(r'''
2631 class A { 2442 class A {
2632 m() {} 2443 m() {}
2633 /// [m] 2444 /// [m]
2634 static foo() { 2445 static foo() {
2635 } 2446 }
2636 }'''); 2447 }''');
2637 computeLibrarySourceErrors(source);
2638 assertNoErrors(source); 2448 assertNoErrors(source);
2639 verify([source]); 2449 verify([source]);
2640 } 2450 }
2641 2451
2642 void test_instanceMethodNameCollidesWithSuperclassStatic_field() { 2452 void test_instanceMethodNameCollidesWithSuperclassStatic_field() {
2643 Source source = addSource(r''' 2453 Source source = addSource(r'''
2644 import 'lib.dart'; 2454 import 'lib.dart';
2645 class B extends A { 2455 class B extends A {
2646 _m() {} 2456 _m() {}
2647 }'''); 2457 }''');
2648 addNamedSource( 2458 addNamedSource(
2649 "/lib.dart", 2459 "/lib.dart",
2650 r''' 2460 r'''
2651 library L; 2461 library L;
2652 class A { 2462 class A {
2653 static var _m; 2463 static var _m;
2654 }'''); 2464 }''');
2655 computeLibrarySourceErrors(source);
2656 assertNoErrors(source); 2465 assertNoErrors(source);
2657 verify([source]); 2466 verify([source]);
2658 } 2467 }
2659 2468
2660 void test_instanceMethodNameCollidesWithSuperclassStatic_method() { 2469 void test_instanceMethodNameCollidesWithSuperclassStatic_method() {
2661 Source source = addSource(r''' 2470 Source source = addSource(r'''
2662 import 'lib.dart'; 2471 import 'lib.dart';
2663 class B extends A { 2472 class B extends A {
2664 _m() {} 2473 _m() {}
2665 }'''); 2474 }''');
2666 addNamedSource( 2475 addNamedSource(
2667 "/lib.dart", 2476 "/lib.dart",
2668 r''' 2477 r'''
2669 library L; 2478 library L;
2670 class A { 2479 class A {
2671 static _m() {} 2480 static _m() {}
2672 }'''); 2481 }''');
2673 computeLibrarySourceErrors(source);
2674 assertNoErrors(source); 2482 assertNoErrors(source);
2675 verify([source]); 2483 verify([source]);
2676 } 2484 }
2677 2485
2678 void test_invalidAnnotation_constantVariable_field() { 2486 void test_invalidAnnotation_constantVariable_field() {
2679 Source source = addSource(r''' 2487 Source source = addSource(r'''
2680 @A.C 2488 @A.C
2681 class A { 2489 class A {
2682 static const C = 0; 2490 static const C = 0;
2683 }'''); 2491 }''');
2684 computeLibrarySourceErrors(source);
2685 assertNoErrors(source); 2492 assertNoErrors(source);
2686 verify([source]); 2493 verify([source]);
2687 } 2494 }
2688 2495
2689 void test_invalidAnnotation_constantVariable_field_importWithPrefix() { 2496 void test_invalidAnnotation_constantVariable_field_importWithPrefix() {
2690 addNamedSource( 2497 addNamedSource(
2691 "/lib.dart", 2498 "/lib.dart",
2692 r''' 2499 r'''
2693 library lib; 2500 library lib;
2694 class A { 2501 class A {
2695 static const C = 0; 2502 static const C = 0;
2696 }'''); 2503 }''');
2697 Source source = addSource(r''' 2504 Source source = addSource(r'''
2698 import 'lib.dart' as p; 2505 import 'lib.dart' as p;
2699 @p.A.C 2506 @p.A.C
2700 main() { 2507 main() {
2701 }'''); 2508 }''');
2702 computeLibrarySourceErrors(source);
2703 assertNoErrors(source); 2509 assertNoErrors(source);
2704 verify([source]); 2510 verify([source]);
2705 } 2511 }
2706 2512
2707 void test_invalidAnnotation_constantVariable_topLevel() { 2513 void test_invalidAnnotation_constantVariable_topLevel() {
2708 Source source = addSource(r''' 2514 Source source = addSource(r'''
2709 const C = 0; 2515 const C = 0;
2710 @C 2516 @C
2711 main() { 2517 main() {
2712 }'''); 2518 }''');
2713 computeLibrarySourceErrors(source);
2714 assertNoErrors(source); 2519 assertNoErrors(source);
2715 verify([source]); 2520 verify([source]);
2716 } 2521 }
2717 2522
2718 void test_invalidAnnotation_constantVariable_topLevel_importWithPrefix() { 2523 void test_invalidAnnotation_constantVariable_topLevel_importWithPrefix() {
2719 addNamedSource( 2524 addNamedSource(
2720 "/lib.dart", 2525 "/lib.dart",
2721 r''' 2526 r'''
2722 library lib; 2527 library lib;
2723 const C = 0;'''); 2528 const C = 0;''');
2724 Source source = addSource(r''' 2529 Source source = addSource(r'''
2725 import 'lib.dart' as p; 2530 import 'lib.dart' as p;
2726 @p.C 2531 @p.C
2727 main() { 2532 main() {
2728 }'''); 2533 }''');
2729 computeLibrarySourceErrors(source);
2730 assertNoErrors(source); 2534 assertNoErrors(source);
2731 verify([source]); 2535 verify([source]);
2732 } 2536 }
2733 2537
2734 void test_invalidAnnotation_constConstructor_importWithPrefix() { 2538 void test_invalidAnnotation_constConstructor_importWithPrefix() {
2735 addNamedSource( 2539 addNamedSource(
2736 "/lib.dart", 2540 "/lib.dart",
2737 r''' 2541 r'''
2738 library lib; 2542 library lib;
2739 class A { 2543 class A {
2740 const A(int p); 2544 const A(int p);
2741 }'''); 2545 }''');
2742 Source source = addSource(r''' 2546 Source source = addSource(r'''
2743 import 'lib.dart' as p; 2547 import 'lib.dart' as p;
2744 @p.A(42) 2548 @p.A(42)
2745 main() { 2549 main() {
2746 }'''); 2550 }''');
2747 computeLibrarySourceErrors(source);
2748 assertNoErrors(source); 2551 assertNoErrors(source);
2749 verify([source]); 2552 verify([source]);
2750 } 2553 }
2751 2554
2752 void test_invalidAnnotation_constConstructor_named_importWithPrefix() { 2555 void test_invalidAnnotation_constConstructor_named_importWithPrefix() {
2753 addNamedSource( 2556 addNamedSource(
2754 "/lib.dart", 2557 "/lib.dart",
2755 r''' 2558 r'''
2756 library lib; 2559 library lib;
2757 class A { 2560 class A {
2758 const A.named(int p); 2561 const A.named(int p);
2759 }'''); 2562 }''');
2760 Source source = addSource(r''' 2563 Source source = addSource(r'''
2761 import 'lib.dart' as p; 2564 import 'lib.dart' as p;
2762 @p.A.named(42) 2565 @p.A.named(42)
2763 main() { 2566 main() {
2764 }'''); 2567 }''');
2765 computeLibrarySourceErrors(source);
2766 assertNoErrors(source); 2568 assertNoErrors(source);
2767 verify([source]); 2569 verify([source]);
2768 } 2570 }
2769 2571
2770 void test_invalidAssignment() { 2572 void test_invalidAssignment() {
2771 Source source = addSource(r''' 2573 Source source = addSource(r'''
2772 f() { 2574 f() {
2773 var x; 2575 var x;
2774 var y; 2576 var y;
2775 x = y; 2577 x = y;
2776 }'''); 2578 }''');
2777 computeLibrarySourceErrors(source);
2778 assertNoErrors(source); 2579 assertNoErrors(source);
2779 verify([source]); 2580 verify([source]);
2780 } 2581 }
2781 2582
2782 void test_invalidAssignment_compoundAssignment() { 2583 void test_invalidAssignment_compoundAssignment() {
2783 Source source = addSource(r''' 2584 Source source = addSource(r'''
2784 class byte { 2585 class byte {
2785 int _value; 2586 int _value;
2786 byte(this._value); 2587 byte(this._value);
2787 byte operator +(int val) { return this; } 2588 byte operator +(int val) { return this; }
2788 } 2589 }
2789 2590
2790 void main() { 2591 void main() {
2791 byte b = new byte(52); 2592 byte b = new byte(52);
2792 b += 3; 2593 b += 3;
2793 }'''); 2594 }''');
2794 computeLibrarySourceErrors(source);
2795 assertNoErrors(source); 2595 assertNoErrors(source);
2796 verify([source]); 2596 verify([source]);
2797 } 2597 }
2798 2598
2799 void test_invalidAssignment_defaultValue_named() { 2599 void test_invalidAssignment_defaultValue_named() {
2800 Source source = addSource(r''' 2600 Source source = addSource(r'''
2801 f({String x: '0'}) { 2601 f({String x: '0'}) {
2802 }'''); 2602 }''');
2803 computeLibrarySourceErrors(source);
2804 assertNoErrors(source); 2603 assertNoErrors(source);
2805 verify([source]); 2604 verify([source]);
2806 } 2605 }
2807 2606
2808 void test_invalidAssignment_defaultValue_optional() { 2607 void test_invalidAssignment_defaultValue_optional() {
2809 Source source = addSource(r''' 2608 Source source = addSource(r'''
2810 f([String x = '0']) { 2609 f([String x = '0']) {
2811 }'''); 2610 }''');
2812 computeLibrarySourceErrors(source);
2813 assertNoErrors(source); 2611 assertNoErrors(source);
2814 verify([source]); 2612 verify([source]);
2815 } 2613 }
2816 2614
2817 void test_invalidAssignment_ifNullAssignment_compatibleType() { 2615 void test_invalidAssignment_ifNullAssignment_compatibleType() {
2818 Source source = addSource(''' 2616 Source source = addSource('''
2819 void f(int i) { 2617 void f(int i) {
2820 num n; 2618 num n;
2821 n ??= i; 2619 n ??= i;
2822 } 2620 }
2823 '''); 2621 ''');
2824 computeLibrarySourceErrors(source);
2825 assertNoErrors(source); 2622 assertNoErrors(source);
2826 verify([source]); 2623 verify([source]);
2827 } 2624 }
2828 2625
2829 void test_invalidAssignment_ifNullAssignment_sameType() { 2626 void test_invalidAssignment_ifNullAssignment_sameType() {
2830 Source source = addSource(''' 2627 Source source = addSource('''
2831 void f(int i) { 2628 void f(int i) {
2832 int j; 2629 int j;
2833 j ??= i; 2630 j ??= i;
2834 } 2631 }
2835 '''); 2632 ''');
2836 computeLibrarySourceErrors(source);
2837 assertNoErrors(source); 2633 assertNoErrors(source);
2838 verify([source]); 2634 verify([source]);
2839 } 2635 }
2840 2636
2841 void test_invalidAssignment_implicitlyImplementFunctionViaCall_1() { 2637 void test_invalidAssignment_implicitlyImplementFunctionViaCall_1() {
2842 // 18341 2638 // 18341
2843 // 2639 //
2844 // This test and 2640 // This test and
2845 // 'test_invalidAssignment_implicitlyImplementFunctionViaCall_2()' 2641 // 'test_invalidAssignment_implicitlyImplementFunctionViaCall_2()'
2846 // are closely related: here we see that 'I' checks as a subtype of 2642 // are closely related: here we see that 'I' checks as a subtype of
2847 // 'IntToInt'. 2643 // 'IntToInt'.
2848 Source source = addSource(r''' 2644 Source source = addSource(r'''
2849 class I { 2645 class I {
2850 int call(int x) => 0; 2646 int call(int x) => 0;
2851 } 2647 }
2852 class C implements I { 2648 class C implements I {
2853 noSuchMethod(_) => null; 2649 noSuchMethod(_) => null;
2854 } 2650 }
2855 typedef int IntToInt(int x); 2651 typedef int IntToInt(int x);
2856 IntToInt f = new I();'''); 2652 IntToInt f = new I();''');
2857 computeLibrarySourceErrors(source);
2858 assertNoErrors(source); 2653 assertNoErrors(source);
2859 verify([source]); 2654 verify([source]);
2860 } 2655 }
2861 2656
2862 void test_invalidAssignment_implicitlyImplementFunctionViaCall_2() { 2657 void test_invalidAssignment_implicitlyImplementFunctionViaCall_2() {
2863 // 18341 2658 // 18341
2864 // 2659 //
2865 // Here 'C' checks as a subtype of 'I', but 'C' does not 2660 // Here 'C' checks as a subtype of 'I', but 'C' does not
2866 // check as a subtype of 'IntToInt'. Together with 2661 // check as a subtype of 'IntToInt'. Together with
2867 // 'test_invalidAssignment_implicitlyImplementFunctionViaCall_1()' we see 2662 // 'test_invalidAssignment_implicitlyImplementFunctionViaCall_1()' we see
2868 // that subtyping is not transitive here. 2663 // that subtyping is not transitive here.
2869 Source source = addSource(r''' 2664 Source source = addSource(r'''
2870 class I { 2665 class I {
2871 int call(int x) => 0; 2666 int call(int x) => 0;
2872 } 2667 }
2873 class C implements I { 2668 class C implements I {
2874 noSuchMethod(_) => null; 2669 noSuchMethod(_) => null;
2875 } 2670 }
2876 typedef int IntToInt(int x); 2671 typedef int IntToInt(int x);
2877 IntToInt f = new C();'''); 2672 IntToInt f = new C();''');
2878 computeLibrarySourceErrors(source);
2879 assertNoErrors(source); 2673 assertNoErrors(source);
2880 verify([source]); 2674 verify([source]);
2881 } 2675 }
2882 2676
2883 void test_invalidAssignment_implicitlyImplementFunctionViaCall_3() { 2677 void test_invalidAssignment_implicitlyImplementFunctionViaCall_3() {
2884 // 18341 2678 // 18341
2885 // 2679 //
2886 // Like 'test_invalidAssignment_implicitlyImplementFunctionViaCall_2()', 2680 // Like 'test_invalidAssignment_implicitlyImplementFunctionViaCall_2()',
2887 // but uses type 'Function' instead of more precise type 'IntToInt' for 'f'. 2681 // but uses type 'Function' instead of more precise type 'IntToInt' for 'f'.
2888 Source source = addSource(r''' 2682 Source source = addSource(r'''
2889 class I { 2683 class I {
2890 int call(int x) => 0; 2684 int call(int x) => 0;
2891 } 2685 }
2892 class C implements I { 2686 class C implements I {
2893 noSuchMethod(_) => null; 2687 noSuchMethod(_) => null;
2894 } 2688 }
2895 typedef int IntToInt(int x); 2689 typedef int IntToInt(int x);
2896 Function f = new C();'''); 2690 Function f = new C();''');
2897 computeLibrarySourceErrors(source);
2898 assertNoErrors(source); 2691 assertNoErrors(source);
2899 verify([source]); 2692 verify([source]);
2900 } 2693 }
2901 2694
2902 void test_invalidAssignment_implicitlyImplementFunctionViaCall_4() { 2695 void test_invalidAssignment_implicitlyImplementFunctionViaCall_4() {
2903 // 18341 2696 // 18341
2904 // 2697 //
2905 // Like 'test_invalidAssignment_implicitlyImplementFunctionViaCall_2()', 2698 // Like 'test_invalidAssignment_implicitlyImplementFunctionViaCall_2()',
2906 // but uses type 'VoidToInt' instead of more precise type 'IntToInt' for 2699 // but uses type 'VoidToInt' instead of more precise type 'IntToInt' for
2907 // 'f'. 2700 // 'f'.
2908 // 2701 //
2909 // Here 'C <: IntToInt <: VoidToInt', but the spec gives no transitivity 2702 // Here 'C <: IntToInt <: VoidToInt', but the spec gives no transitivity
2910 // rule for '<:'. However, many of the :/tools/test.py tests assume this 2703 // rule for '<:'. However, many of the :/tools/test.py tests assume this
2911 // transitivity for 'JsBuilder' objects, assigning them to 2704 // transitivity for 'JsBuilder' objects, assigning them to
2912 // '(String) -> dynamic'. The declared type of 'JsBuilder.call' is 2705 // '(String) -> dynamic'. The declared type of 'JsBuilder.call' is
2913 // '(String, [dynamic]) -> Expression'. 2706 // '(String, [dynamic]) -> Expression'.
2914 Source source = addSource(r''' 2707 Source source = addSource(r'''
2915 class I { 2708 class I {
2916 int call([int x]) => 0; 2709 int call([int x]) => 0;
2917 } 2710 }
2918 class C implements I { 2711 class C implements I {
2919 noSuchMethod(_) => null; 2712 noSuchMethod(_) => null;
2920 } 2713 }
2921 typedef int VoidToInt(); 2714 typedef int VoidToInt();
2922 VoidToInt f = new C();'''); 2715 VoidToInt f = new C();''');
2923 computeLibrarySourceErrors(source);
2924 assertNoErrors(source); 2716 assertNoErrors(source);
2925 verify([source]); 2717 verify([source]);
2926 } 2718 }
2927 2719
2928 void test_invalidAssignment_toDynamic() { 2720 void test_invalidAssignment_toDynamic() {
2929 Source source = addSource(r''' 2721 Source source = addSource(r'''
2930 f() { 2722 f() {
2931 var g; 2723 var g;
2932 g = () => 0; 2724 g = () => 0;
2933 }'''); 2725 }''');
2934 computeLibrarySourceErrors(source);
2935 assertNoErrors(source); 2726 assertNoErrors(source);
2936 verify([source]); 2727 verify([source]);
2937 } 2728 }
2938 2729
2939 void test_invalidFactoryNameNotAClass() { 2730 void test_invalidFactoryNameNotAClass() {
2940 Source source = addSource(r''' 2731 Source source = addSource(r'''
2941 class A { 2732 class A {
2942 factory A() => null; 2733 factory A() => null;
2943 }'''); 2734 }''');
2944 computeLibrarySourceErrors(source);
2945 assertNoErrors(source); 2735 assertNoErrors(source);
2946 verify([source]); 2736 verify([source]);
2947 } 2737 }
2948 2738
2949 void test_invalidIdentifierInAsync() { 2739 void test_invalidIdentifierInAsync() {
2950 Source source = addSource(r''' 2740 Source source = addSource(r'''
2951 class A { 2741 class A {
2952 m() { 2742 m() {
2953 int async; 2743 int async;
2954 int await; 2744 int await;
2955 int yield; 2745 int yield;
2956 } 2746 }
2957 }'''); 2747 }''');
2958 computeLibrarySourceErrors(source);
2959 assertNoErrors(source); 2748 assertNoErrors(source);
2960 verify([source]); 2749 verify([source]);
2961 } 2750 }
2962 2751
2963 void test_invalidMethodOverrideNamedParamType() { 2752 void test_invalidMethodOverrideNamedParamType() {
2964 Source source = addSource(r''' 2753 Source source = addSource(r'''
2965 class A { 2754 class A {
2966 m({int a}) {} 2755 m({int a}) {}
2967 } 2756 }
2968 class B implements A { 2757 class B implements A {
2969 m({int a, int b}) {} 2758 m({int a, int b}) {}
2970 }'''); 2759 }''');
2971 computeLibrarySourceErrors(source);
2972 assertNoErrors(source); 2760 assertNoErrors(source);
2973 verify([source]); 2761 verify([source]);
2974 } 2762 }
2975 2763
2976 void test_invalidOverrideDifferentDefaultValues_named() { 2764 void test_invalidOverrideDifferentDefaultValues_named() {
2977 Source source = addSource(r''' 2765 Source source = addSource(r'''
2978 class A { 2766 class A {
2979 m({int p : 0}) {} 2767 m({int p : 0}) {}
2980 } 2768 }
2981 class B extends A { 2769 class B extends A {
2982 m({int p : 0}) {} 2770 m({int p : 0}) {}
2983 }'''); 2771 }''');
2984 computeLibrarySourceErrors(source);
2985 assertNoErrors(source); 2772 assertNoErrors(source);
2986 verify([source]); 2773 verify([source]);
2987 } 2774 }
2988 2775
2989 void test_invalidOverrideDifferentDefaultValues_named_function() { 2776 void test_invalidOverrideDifferentDefaultValues_named_function() {
2990 Source source = addSource(r''' 2777 Source source = addSource(r'''
2991 nothing() => 'nothing'; 2778 nothing() => 'nothing';
2992 class A { 2779 class A {
2993 thing(String a, {orElse : nothing}) {} 2780 thing(String a, {orElse : nothing}) {}
2994 } 2781 }
2995 class B extends A { 2782 class B extends A {
2996 thing(String a, {orElse : nothing}) {} 2783 thing(String a, {orElse : nothing}) {}
2997 }'''); 2784 }''');
2998 computeLibrarySourceErrors(source);
2999 assertNoErrors(source); 2785 assertNoErrors(source);
3000 verify([source]); 2786 verify([source]);
3001 } 2787 }
3002 2788
3003 void test_invalidOverrideDifferentDefaultValues_positional() { 2789 void test_invalidOverrideDifferentDefaultValues_positional() {
3004 Source source = addSource(r''' 2790 Source source = addSource(r'''
3005 class A { 2791 class A {
3006 m([int p = 0]) {} 2792 m([int p = 0]) {}
3007 } 2793 }
3008 class B extends A { 2794 class B extends A {
3009 m([int p = 0]) {} 2795 m([int p = 0]) {}
3010 }'''); 2796 }''');
3011 computeLibrarySourceErrors(source);
3012 assertNoErrors(source); 2797 assertNoErrors(source);
3013 verify([source]); 2798 verify([source]);
3014 } 2799 }
3015 2800
3016 void test_invalidOverrideDifferentDefaultValues_positional_changedOrder() { 2801 void test_invalidOverrideDifferentDefaultValues_positional_changedOrder() {
3017 Source source = addSource(r''' 2802 Source source = addSource(r'''
3018 class A { 2803 class A {
3019 m([int a = 0, String b = '0']) {} 2804 m([int a = 0, String b = '0']) {}
3020 } 2805 }
3021 class B extends A { 2806 class B extends A {
3022 m([int b = 0, String a = '0']) {} 2807 m([int b = 0, String a = '0']) {}
3023 }'''); 2808 }''');
3024 computeLibrarySourceErrors(source);
3025 assertNoErrors(source); 2809 assertNoErrors(source);
3026 verify([source]); 2810 verify([source]);
3027 } 2811 }
3028 2812
3029 void test_invalidOverrideDifferentDefaultValues_positional_function() { 2813 void test_invalidOverrideDifferentDefaultValues_positional_function() {
3030 Source source = addSource(r''' 2814 Source source = addSource(r'''
3031 nothing() => 'nothing'; 2815 nothing() => 'nothing';
3032 class A { 2816 class A {
3033 thing(String a, [orElse = nothing]) {} 2817 thing(String a, [orElse = nothing]) {}
3034 } 2818 }
3035 class B extends A { 2819 class B extends A {
3036 thing(String a, [orElse = nothing]) {} 2820 thing(String a, [orElse = nothing]) {}
3037 }'''); 2821 }''');
3038 computeLibrarySourceErrors(source);
3039 assertNoErrors(source); 2822 assertNoErrors(source);
3040 verify([source]); 2823 verify([source]);
3041 } 2824 }
3042 2825
3043 void test_invalidOverrideNamed_unorderedNamedParameter() { 2826 void test_invalidOverrideNamed_unorderedNamedParameter() {
3044 Source source = addSource(r''' 2827 Source source = addSource(r'''
3045 class A { 2828 class A {
3046 m({a, b}) {} 2829 m({a, b}) {}
3047 } 2830 }
3048 class B extends A { 2831 class B extends A {
3049 m({b, a}) {} 2832 m({b, a}) {}
3050 }'''); 2833 }''');
3051 computeLibrarySourceErrors(source);
3052 assertNoErrors(source); 2834 assertNoErrors(source);
3053 verify([source]); 2835 verify([source]);
3054 } 2836 }
3055 2837
3056 void test_invalidOverrideRequired_less() { 2838 void test_invalidOverrideRequired_less() {
3057 Source source = addSource(r''' 2839 Source source = addSource(r'''
3058 class A { 2840 class A {
3059 m(a, b) {} 2841 m(a, b) {}
3060 } 2842 }
3061 class B extends A { 2843 class B extends A {
3062 m(a, [b]) {} 2844 m(a, [b]) {}
3063 }'''); 2845 }''');
3064 computeLibrarySourceErrors(source);
3065 assertNoErrors(source); 2846 assertNoErrors(source);
3066 verify([source]); 2847 verify([source]);
3067 } 2848 }
3068 2849
3069 void test_invalidOverrideRequired_same() { 2850 void test_invalidOverrideRequired_same() {
3070 Source source = addSource(r''' 2851 Source source = addSource(r'''
3071 class A { 2852 class A {
3072 m(a) {} 2853 m(a) {}
3073 } 2854 }
3074 class B extends A { 2855 class B extends A {
3075 m(a) {} 2856 m(a) {}
3076 }'''); 2857 }''');
3077 computeLibrarySourceErrors(source);
3078 assertNoErrors(source); 2858 assertNoErrors(source);
3079 verify([source]); 2859 verify([source]);
3080 } 2860 }
3081 2861
3082 void test_invalidOverrideReturnType_returnType_interface() { 2862 void test_invalidOverrideReturnType_returnType_interface() {
3083 Source source = addNamedSource( 2863 Source source = addNamedSource(
3084 "/test.dart", 2864 "/test.dart",
3085 r''' 2865 r'''
3086 abstract class A { 2866 abstract class A {
3087 num m(); 2867 num m();
3088 } 2868 }
3089 class B implements A { 2869 class B implements A {
3090 int m() { return 1; } 2870 int m() { return 1; }
3091 }'''); 2871 }''');
3092 computeLibrarySourceErrors(source);
3093 assertNoErrors(source); 2872 assertNoErrors(source);
3094 verify([source]); 2873 verify([source]);
3095 } 2874 }
3096 2875
3097 void test_invalidOverrideReturnType_returnType_interface2() { 2876 void test_invalidOverrideReturnType_returnType_interface2() {
3098 Source source = addNamedSource( 2877 Source source = addNamedSource(
3099 "/test.dart", 2878 "/test.dart",
3100 r''' 2879 r'''
3101 abstract class A { 2880 abstract class A {
3102 num m(); 2881 num m();
3103 } 2882 }
3104 abstract class B implements A { 2883 abstract class B implements A {
3105 } 2884 }
3106 class C implements B { 2885 class C implements B {
3107 int m() { return 1; } 2886 int m() { return 1; }
3108 }'''); 2887 }''');
3109 computeLibrarySourceErrors(source);
3110 assertNoErrors(source); 2888 assertNoErrors(source);
3111 verify([source]); 2889 verify([source]);
3112 } 2890 }
3113 2891
3114 void test_invalidOverrideReturnType_returnType_mixin() { 2892 void test_invalidOverrideReturnType_returnType_mixin() {
3115 Source source = addNamedSource( 2893 Source source = addNamedSource(
3116 "/test.dart", 2894 "/test.dart",
3117 r''' 2895 r'''
3118 class A { 2896 class A {
3119 num m() { return 0; } 2897 num m() { return 0; }
3120 } 2898 }
3121 class B extends Object with A { 2899 class B extends Object with A {
3122 int m() { return 1; } 2900 int m() { return 1; }
3123 }'''); 2901 }''');
3124 computeLibrarySourceErrors(source);
3125 assertNoErrors(source); 2902 assertNoErrors(source);
3126 verify([source]); 2903 verify([source]);
3127 } 2904 }
3128 2905
3129 void test_invalidOverrideReturnType_returnType_parameterizedTypes() { 2906 void test_invalidOverrideReturnType_returnType_parameterizedTypes() {
3130 Source source = addSource(r''' 2907 Source source = addSource(r'''
3131 abstract class A<E> { 2908 abstract class A<E> {
3132 List<E> m(); 2909 List<E> m();
3133 } 2910 }
3134 class B extends A<dynamic> { 2911 class B extends A<dynamic> {
3135 List<dynamic> m() { return new List<dynamic>(); } 2912 List<dynamic> m() { return new List<dynamic>(); }
3136 }'''); 2913 }''');
3137 computeLibrarySourceErrors(source);
3138 assertNoErrors(source); 2914 assertNoErrors(source);
3139 verify([source]); 2915 verify([source]);
3140 } 2916 }
3141 2917
3142 void test_invalidOverrideReturnType_returnType_sameType() { 2918 void test_invalidOverrideReturnType_returnType_sameType() {
3143 Source source = addNamedSource( 2919 Source source = addNamedSource(
3144 "/test.dart", 2920 "/test.dart",
3145 r''' 2921 r'''
3146 class A { 2922 class A {
3147 int m() { return 0; } 2923 int m() { return 0; }
3148 } 2924 }
3149 class B extends A { 2925 class B extends A {
3150 int m() { return 1; } 2926 int m() { return 1; }
3151 }'''); 2927 }''');
3152 computeLibrarySourceErrors(source);
3153 assertNoErrors(source); 2928 assertNoErrors(source);
3154 verify([source]); 2929 verify([source]);
3155 } 2930 }
3156 2931
3157 void test_invalidOverrideReturnType_returnType_superclass() { 2932 void test_invalidOverrideReturnType_returnType_superclass() {
3158 Source source = addNamedSource( 2933 Source source = addNamedSource(
3159 "/test.dart", 2934 "/test.dart",
3160 r''' 2935 r'''
3161 class A { 2936 class A {
3162 num m() { return 0; } 2937 num m() { return 0; }
3163 } 2938 }
3164 class B extends A { 2939 class B extends A {
3165 int m() { return 1; } 2940 int m() { return 1; }
3166 }'''); 2941 }''');
3167 computeLibrarySourceErrors(source);
3168 assertNoErrors(source); 2942 assertNoErrors(source);
3169 verify([source]); 2943 verify([source]);
3170 } 2944 }
3171 2945
3172 void test_invalidOverrideReturnType_returnType_superclass2() { 2946 void test_invalidOverrideReturnType_returnType_superclass2() {
3173 Source source = addNamedSource( 2947 Source source = addNamedSource(
3174 "/test.dart", 2948 "/test.dart",
3175 r''' 2949 r'''
3176 class A { 2950 class A {
3177 num m() { return 0; } 2951 num m() { return 0; }
3178 } 2952 }
3179 class B extends A { 2953 class B extends A {
3180 } 2954 }
3181 class C extends B { 2955 class C extends B {
3182 int m() { return 1; } 2956 int m() { return 1; }
3183 }'''); 2957 }''');
3184 computeLibrarySourceErrors(source);
3185 assertNoErrors(source); 2958 assertNoErrors(source);
3186 verify([source]); 2959 verify([source]);
3187 } 2960 }
3188 2961
3189 void test_invalidOverrideReturnType_returnType_void() { 2962 void test_invalidOverrideReturnType_returnType_void() {
3190 Source source = addSource(r''' 2963 Source source = addSource(r'''
3191 class A { 2964 class A {
3192 void m() {} 2965 void m() {}
3193 } 2966 }
3194 class B extends A { 2967 class B extends A {
3195 int m() { return 0; } 2968 int m() { return 0; }
3196 }'''); 2969 }''');
3197 computeLibrarySourceErrors(source);
3198 assertNoErrors(source); 2970 assertNoErrors(source);
3199 verify([source]); 2971 verify([source]);
3200 } 2972 }
3201 2973
3202 void test_invalidReferenceToThis_constructor() { 2974 void test_invalidReferenceToThis_constructor() {
3203 Source source = addSource(r''' 2975 Source source = addSource(r'''
3204 class A { 2976 class A {
3205 A() { 2977 A() {
3206 var v = this; 2978 var v = this;
3207 } 2979 }
3208 }'''); 2980 }''');
3209 computeLibrarySourceErrors(source);
3210 assertNoErrors(source); 2981 assertNoErrors(source);
3211 verify([source]); 2982 verify([source]);
3212 } 2983 }
3213 2984
3214 void test_invalidReferenceToThis_instanceMethod() { 2985 void test_invalidReferenceToThis_instanceMethod() {
3215 Source source = addSource(r''' 2986 Source source = addSource(r'''
3216 class A { 2987 class A {
3217 m() { 2988 m() {
3218 var v = this; 2989 var v = this;
3219 } 2990 }
3220 }'''); 2991 }''');
3221 computeLibrarySourceErrors(source);
3222 assertNoErrors(source); 2992 assertNoErrors(source);
3223 verify([source]); 2993 verify([source]);
3224 } 2994 }
3225 2995
3226 void test_invalidTypeArgumentForKey() { 2996 void test_invalidTypeArgumentForKey() {
3227 Source source = addSource(r''' 2997 Source source = addSource(r'''
3228 class A { 2998 class A {
3229 m() { 2999 m() {
3230 return const <int, int>{}; 3000 return const <int, int>{};
3231 } 3001 }
3232 }'''); 3002 }''');
3233 computeLibrarySourceErrors(source);
3234 assertNoErrors(source); 3003 assertNoErrors(source);
3235 verify([source]); 3004 verify([source]);
3236 } 3005 }
3237 3006
3238 void test_invalidTypeArgumentInConstList() { 3007 void test_invalidTypeArgumentInConstList() {
3239 Source source = addSource(r''' 3008 Source source = addSource(r'''
3240 class A<E> { 3009 class A<E> {
3241 m() { 3010 m() {
3242 return <E>[]; 3011 return <E>[];
3243 } 3012 }
3244 }'''); 3013 }''');
3245 computeLibrarySourceErrors(source);
3246 assertNoErrors(source); 3014 assertNoErrors(source);
3247 verify([source]); 3015 verify([source]);
3248 } 3016 }
3249 3017
3250 void test_invalidTypeArgumentInConstMap() { 3018 void test_invalidTypeArgumentInConstMap() {
3251 Source source = addSource(r''' 3019 Source source = addSource(r'''
3252 class A<E> { 3020 class A<E> {
3253 m() { 3021 m() {
3254 return <String, E>{}; 3022 return <String, E>{};
3255 } 3023 }
3256 }'''); 3024 }''');
3257 computeLibrarySourceErrors(source);
3258 assertNoErrors(source); 3025 assertNoErrors(source);
3259 verify([source]); 3026 verify([source]);
3260 } 3027 }
3261 3028
3262 void test_invocationOfNonFunction_dynamic() { 3029 void test_invocationOfNonFunction_dynamic() {
3263 Source source = addSource(r''' 3030 Source source = addSource(r'''
3264 class A { 3031 class A {
3265 var f; 3032 var f;
3266 } 3033 }
3267 class B extends A { 3034 class B extends A {
3268 g() { 3035 g() {
3269 f(); 3036 f();
3270 } 3037 }
3271 }'''); 3038 }''');
3272 computeLibrarySourceErrors(source);
3273 assertNoErrors(source); 3039 assertNoErrors(source);
3274 verify([source]); 3040 verify([source]);
3275 } 3041 }
3276 3042
3277 void test_invocationOfNonFunction_functionTypeTypeParameter() { 3043 void test_invocationOfNonFunction_functionTypeTypeParameter() {
3278 Source source = addSource(r''' 3044 Source source = addSource(r'''
3279 typedef void Action<T>(T x); 3045 typedef void Action<T>(T x);
3280 class C<T, U extends Action<T>> { 3046 class C<T, U extends Action<T>> {
3281 T value; 3047 T value;
3282 U action; 3048 U action;
3283 C(this.value, [this.action]); 3049 C(this.value, [this.action]);
3284 void act() { 3050 void act() {
3285 action(value); 3051 action(value);
3286 } 3052 }
3287 } 3053 }
3288 '''); 3054 ''');
3289 computeLibrarySourceErrors(source);
3290 assertNoErrors(source); 3055 assertNoErrors(source);
3291 verify([source]); 3056 verify([source]);
3292 } 3057 }
3293 3058
3294 void test_invocationOfNonFunction_getter() { 3059 void test_invocationOfNonFunction_getter() {
3295 Source source = addSource(r''' 3060 Source source = addSource(r'''
3296 class A { 3061 class A {
3297 var g; 3062 var g;
3298 } 3063 }
3299 f() { 3064 f() {
3300 A a; 3065 A a;
3301 a.g(); 3066 a.g();
3302 }'''); 3067 }''');
3303 computeLibrarySourceErrors(source);
3304 assertNoErrors(source); 3068 assertNoErrors(source);
3305 verify([source]); 3069 verify([source]);
3306 } 3070 }
3307 3071
3308 void test_invocationOfNonFunction_localVariable() { 3072 void test_invocationOfNonFunction_localVariable() {
3309 Source source = addSource(r''' 3073 Source source = addSource(r'''
3310 f() { 3074 f() {
3311 var g; 3075 var g;
3312 g(); 3076 g();
3313 }'''); 3077 }''');
3314 computeLibrarySourceErrors(source);
3315 assertNoErrors(source); 3078 assertNoErrors(source);
3316 verify([source]); 3079 verify([source]);
3317 } 3080 }
3318 3081
3319 void test_invocationOfNonFunction_localVariable_dynamic() { 3082 void test_invocationOfNonFunction_localVariable_dynamic() {
3320 Source source = addSource(r''' 3083 Source source = addSource(r'''
3321 f() {} 3084 f() {}
3322 main() { 3085 main() {
3323 var v = f; 3086 var v = f;
3324 v(); 3087 v();
3325 }'''); 3088 }''');
3326 computeLibrarySourceErrors(source);
3327 assertNoErrors(source); 3089 assertNoErrors(source);
3328 verify([source]); 3090 verify([source]);
3329 } 3091 }
3330 3092
3331 void test_invocationOfNonFunction_localVariable_dynamic2() { 3093 void test_invocationOfNonFunction_localVariable_dynamic2() {
3332 Source source = addSource(r''' 3094 Source source = addSource(r'''
3333 f() {} 3095 f() {}
3334 main() { 3096 main() {
3335 var v = f; 3097 var v = f;
3336 v = 1; 3098 v = 1;
3337 v(); 3099 v();
3338 }'''); 3100 }''');
3339 computeLibrarySourceErrors(source);
3340 assertNoErrors(source); 3101 assertNoErrors(source);
3341 verify([source]); 3102 verify([source]);
3342 } 3103 }
3343 3104
3344 void test_invocationOfNonFunction_Object() { 3105 void test_invocationOfNonFunction_Object() {
3345 Source source = addSource(r''' 3106 Source source = addSource(r'''
3346 main() { 3107 main() {
3347 Object v = null; 3108 Object v = null;
3348 v(); 3109 v();
3349 }'''); 3110 }''');
3350 computeLibrarySourceErrors(source);
3351 assertNoErrors(source); 3111 assertNoErrors(source);
3352 verify([source]); 3112 verify([source]);
3353 } 3113 }
3354 3114
3355 void test_invocationOfNonFunction_proxyOnFunctionClass() { 3115 void test_invocationOfNonFunction_proxyOnFunctionClass() {
3356 // 16078 3116 // 16078
3357 Source source = addSource(r''' 3117 Source source = addSource(r'''
3358 @proxy 3118 @proxy
3359 class Functor implements Function { 3119 class Functor implements Function {
3360 noSuchMethod(inv) { 3120 noSuchMethod(inv) {
3361 return 42; 3121 return 42;
3362 } 3122 }
3363 } 3123 }
3364 main() { 3124 main() {
3365 Functor f = new Functor(); 3125 Functor f = new Functor();
3366 f(); 3126 f();
3367 }'''); 3127 }''');
3368 computeLibrarySourceErrors(source);
3369 assertNoErrors(source); 3128 assertNoErrors(source);
3370 verify([source]); 3129 verify([source]);
3371 } 3130 }
3372 3131
3373 void test_issue_24191() { 3132 void test_issue_24191() {
3374 Source source = addSource(''' 3133 Source source = addSource('''
3375 import 'dart:async'; 3134 import 'dart:async';
3376 3135
3377 class S extends Stream {} 3136 class S extends Stream {}
3378 f(S s) async { 3137 f(S s) async {
3379 await for (var v in s) { 3138 await for (var v in s) {
3380 print(v); 3139 print(v);
3381 } 3140 }
3382 } 3141 }
3383 '''); 3142 ''');
3384 computeLibrarySourceErrors(source);
3385 assertNoErrors(source); 3143 assertNoErrors(source);
3386 verify([source]); 3144 verify([source]);
3387 } 3145 }
3388 3146
3389 void test_listElementTypeNotAssignable() { 3147 void test_listElementTypeNotAssignable() {
3390 Source source = addSource(r''' 3148 Source source = addSource(r'''
3391 var v1 = <int> [42]; 3149 var v1 = <int> [42];
3392 var v2 = const <int> [42];'''); 3150 var v2 = const <int> [42];''');
3393 computeLibrarySourceErrors(source);
3394 assertNoErrors(source); 3151 assertNoErrors(source);
3395 verify([source]); 3152 verify([source]);
3396 } 3153 }
3397 3154
3398 void test_loadLibraryDefined() { 3155 void test_loadLibraryDefined() {
3399 resolveWithErrors(<String>[ 3156 resolveWithErrors(<String>[
3400 r''' 3157 r'''
3401 library lib1; 3158 library lib1;
3402 foo() => 22;''', 3159 foo() => 22;''',
3403 r''' 3160 r'''
3404 import 'lib1.dart' deferred as other; 3161 import 'lib1.dart' deferred as other;
3405 main() { 3162 main() {
3406 other.loadLibrary().then((_) => other.foo()); 3163 other.loadLibrary().then((_) => other.foo());
3407 }''' 3164 }'''
3408 ], <ErrorCode>[]); 3165 ], <ErrorCode>[]);
3409 } 3166 }
3410 3167
3411 void test_local_generator_async() { 3168 void test_local_generator_async() {
3412 Source source = addSource(''' 3169 Source source = addSource('''
3413 f() { 3170 f() {
3414 return () async* { yield 0; }; 3171 return () async* { yield 0; };
3415 } 3172 }
3416 '''); 3173 ''');
3417 computeLibrarySourceErrors(source);
3418 assertNoErrors(source); 3174 assertNoErrors(source);
3419 verify([source]); 3175 verify([source]);
3420 } 3176 }
3421 3177
3422 void test_local_generator_sync() { 3178 void test_local_generator_sync() {
3423 Source source = addSource(''' 3179 Source source = addSource('''
3424 f() { 3180 f() {
3425 return () sync* { yield 0; }; 3181 return () sync* { yield 0; };
3426 } 3182 }
3427 '''); 3183 ''');
3428 computeLibrarySourceErrors(source);
3429 assertNoErrors(source); 3184 assertNoErrors(source);
3430 verify([source]); 3185 verify([source]);
3431 } 3186 }
3432 3187
3433 void test_mapKeyTypeNotAssignable() { 3188 void test_mapKeyTypeNotAssignable() {
3434 Source source = addSource("var v = <String, int > {'a' : 1};"); 3189 Source source = addSource("var v = <String, int > {'a' : 1};");
3435 computeLibrarySourceErrors(source);
3436 assertNoErrors(source); 3190 assertNoErrors(source);
3437 verify([source]); 3191 verify([source]);
3438 } 3192 }
3439 3193
3440 void test_memberWithClassName_setter() { 3194 void test_memberWithClassName_setter() {
3441 Source source = addSource(r''' 3195 Source source = addSource(r'''
3442 class A { 3196 class A {
3443 set A(v) {} 3197 set A(v) {}
3444 }'''); 3198 }''');
3445 computeLibrarySourceErrors(source);
3446 assertNoErrors(source); 3199 assertNoErrors(source);
3447 verify([source]); 3200 verify([source]);
3448 } 3201 }
3449 3202
3450 void test_methodDeclaration_scope_signature() { 3203 void test_methodDeclaration_scope_signature() {
3451 Source source = addSource(r''' 3204 Source source = addSource(r'''
3452 const app = 0; 3205 const app = 0;
3453 class A { 3206 class A {
3454 foo(@app int app) {} 3207 foo(@app int app) {}
3455 }'''); 3208 }''');
3456 computeLibrarySourceErrors(source);
3457 assertNoErrors(source); 3209 assertNoErrors(source);
3458 verify([source]); 3210 verify([source]);
3459 } 3211 }
3460 3212
3461 void test_misMatchedGetterAndSetterTypes_instance_sameTypes() { 3213 void test_misMatchedGetterAndSetterTypes_instance_sameTypes() {
3462 Source source = addSource(r''' 3214 Source source = addSource(r'''
3463 class C { 3215 class C {
3464 int get x => 0; 3216 int get x => 0;
3465 set x(int v) {} 3217 set x(int v) {}
3466 }'''); 3218 }''');
3467 computeLibrarySourceErrors(source);
3468 assertNoErrors(source); 3219 assertNoErrors(source);
3469 verify([source]); 3220 verify([source]);
3470 } 3221 }
3471 3222
3472 void test_misMatchedGetterAndSetterTypes_instance_unspecifiedGetter() { 3223 void test_misMatchedGetterAndSetterTypes_instance_unspecifiedGetter() {
3473 Source source = addSource(r''' 3224 Source source = addSource(r'''
3474 class C { 3225 class C {
3475 get x => 0; 3226 get x => 0;
3476 set x(String v) {} 3227 set x(String v) {}
3477 }'''); 3228 }''');
3478 computeLibrarySourceErrors(source);
3479 assertNoErrors(source); 3229 assertNoErrors(source);
3480 verify([source]); 3230 verify([source]);
3481 } 3231 }
3482 3232
3483 void test_misMatchedGetterAndSetterTypes_instance_unspecifiedSetter() { 3233 void test_misMatchedGetterAndSetterTypes_instance_unspecifiedSetter() {
3484 Source source = addSource(r''' 3234 Source source = addSource(r'''
3485 class C { 3235 class C {
3486 int get x => 0; 3236 int get x => 0;
3487 set x(v) {} 3237 set x(v) {}
3488 }'''); 3238 }''');
3489 computeLibrarySourceErrors(source);
3490 assertNoErrors(source); 3239 assertNoErrors(source);
3491 verify([source]); 3240 verify([source]);
3492 } 3241 }
3493 3242
3494 void test_misMatchedGetterAndSetterTypes_topLevel_sameTypes() { 3243 void test_misMatchedGetterAndSetterTypes_topLevel_sameTypes() {
3495 Source source = addSource(r''' 3244 Source source = addSource(r'''
3496 int get x => 0; 3245 int get x => 0;
3497 set x(int v) {}'''); 3246 set x(int v) {}''');
3498 computeLibrarySourceErrors(source);
3499 assertNoErrors(source); 3247 assertNoErrors(source);
3500 verify([source]); 3248 verify([source]);
3501 } 3249 }
3502 3250
3503 void test_misMatchedGetterAndSetterTypes_topLevel_unspecifiedGetter() { 3251 void test_misMatchedGetterAndSetterTypes_topLevel_unspecifiedGetter() {
3504 Source source = addSource(r''' 3252 Source source = addSource(r'''
3505 get x => 0; 3253 get x => 0;
3506 set x(String v) {}'''); 3254 set x(String v) {}''');
3507 computeLibrarySourceErrors(source);
3508 assertNoErrors(source); 3255 assertNoErrors(source);
3509 verify([source]); 3256 verify([source]);
3510 } 3257 }
3511 3258
3512 void test_misMatchedGetterAndSetterTypes_topLevel_unspecifiedSetter() { 3259 void test_misMatchedGetterAndSetterTypes_topLevel_unspecifiedSetter() {
3513 Source source = addSource(r''' 3260 Source source = addSource(r'''
3514 int get x => 0; 3261 int get x => 0;
3515 set x(v) {}'''); 3262 set x(v) {}''');
3516 computeLibrarySourceErrors(source);
3517 assertNoErrors(source); 3263 assertNoErrors(source);
3518 verify([source]); 3264 verify([source]);
3519 } 3265 }
3520 3266
3521 void test_missingEnumConstantInSwitch_all() { 3267 void test_missingEnumConstantInSwitch_all() {
3522 Source source = addSource(r''' 3268 Source source = addSource(r'''
3523 enum E { A, B, C } 3269 enum E { A, B, C }
3524 3270
3525 f(E e) { 3271 f(E e) {
3526 switch (e) { 3272 switch (e) {
3527 case E.A: break; 3273 case E.A: break;
3528 case E.B: break; 3274 case E.B: break;
3529 case E.C: break; 3275 case E.C: break;
3530 } 3276 }
3531 }'''); 3277 }''');
3532 computeLibrarySourceErrors(source);
3533 assertNoErrors(source); 3278 assertNoErrors(source);
3534 verify([source]); 3279 verify([source]);
3535 } 3280 }
3536 3281
3537 void test_missingEnumConstantInSwitch_default() { 3282 void test_missingEnumConstantInSwitch_default() {
3538 Source source = addSource(r''' 3283 Source source = addSource(r'''
3539 enum E { A, B, C } 3284 enum E { A, B, C }
3540 3285
3541 f(E e) { 3286 f(E e) {
3542 switch (e) { 3287 switch (e) {
3543 case E.B: break; 3288 case E.B: break;
3544 default: break; 3289 default: break;
3545 } 3290 }
3546 }'''); 3291 }''');
3547 computeLibrarySourceErrors(source);
3548 assertNoErrors(source); 3292 assertNoErrors(source);
3549 verify([source]); 3293 verify([source]);
3550 } 3294 }
3551 3295
3552 void test_mixedReturnTypes_differentScopes() { 3296 void test_mixedReturnTypes_differentScopes() {
3553 Source source = addSource(r''' 3297 Source source = addSource(r'''
3554 class C { 3298 class C {
3555 m(int x) { 3299 m(int x) {
3556 f(int y) { 3300 f(int y) {
3557 return; 3301 return;
3558 } 3302 }
3559 f(x); 3303 f(x);
3560 return 0; 3304 return 0;
3561 } 3305 }
3562 }'''); 3306 }''');
3563 computeLibrarySourceErrors(source);
3564 assertNoErrors(source); 3307 assertNoErrors(source);
3565 verify([source]); 3308 verify([source]);
3566 } 3309 }
3567 3310
3568 void test_mixedReturnTypes_ignoreImplicit() { 3311 void test_mixedReturnTypes_ignoreImplicit() {
3569 Source source = addSource(r''' 3312 Source source = addSource(r'''
3570 f(bool p) { 3313 f(bool p) {
3571 if (p) return 42; 3314 if (p) return 42;
3572 // implicit 'return;' is ignored 3315 // implicit 'return;' is ignored
3573 }'''); 3316 }''');
3574 computeLibrarySourceErrors(source);
3575 assertNoErrors(source); 3317 assertNoErrors(source);
3576 verify([source]); 3318 verify([source]);
3577 } 3319 }
3578 3320
3579 void test_mixedReturnTypes_ignoreImplicit2() { 3321 void test_mixedReturnTypes_ignoreImplicit2() {
3580 Source source = addSource(r''' 3322 Source source = addSource(r'''
3581 f(bool p) { 3323 f(bool p) {
3582 if (p) { 3324 if (p) {
3583 return 42; 3325 return 42;
3584 } else { 3326 } else {
3585 return 42; 3327 return 42;
3586 } 3328 }
3587 // implicit 'return;' is ignored 3329 // implicit 'return;' is ignored
3588 }'''); 3330 }''');
3589 computeLibrarySourceErrors(source);
3590 assertNoErrors(source); 3331 assertNoErrors(source);
3591 verify([source]); 3332 verify([source]);
3592 } 3333 }
3593 3334
3594 void test_mixedReturnTypes_sameKind() { 3335 void test_mixedReturnTypes_sameKind() {
3595 Source source = addSource(r''' 3336 Source source = addSource(r'''
3596 class C { 3337 class C {
3597 m(int x) { 3338 m(int x) {
3598 if (x < 0) { 3339 if (x < 0) {
3599 return 1; 3340 return 1;
3600 } 3341 }
3601 return 0; 3342 return 0;
3602 } 3343 }
3603 }'''); 3344 }''');
3604 computeLibrarySourceErrors(source);
3605 assertNoErrors(source); 3345 assertNoErrors(source);
3606 verify([source]); 3346 verify([source]);
3607 } 3347 }
3608 3348
3609 void test_mixinDeclaresConstructor() { 3349 void test_mixinDeclaresConstructor() {
3610 Source source = addSource(r''' 3350 Source source = addSource(r'''
3611 class A { 3351 class A {
3612 m() {} 3352 m() {}
3613 } 3353 }
3614 class B extends Object with A {}'''); 3354 class B extends Object with A {}''');
3615 computeLibrarySourceErrors(source);
3616 assertNoErrors(source); 3355 assertNoErrors(source);
3617 verify([source]); 3356 verify([source]);
3618 } 3357 }
3619 3358
3620 void test_mixinDeclaresConstructor_factory() { 3359 void test_mixinDeclaresConstructor_factory() {
3621 Source source = addSource(r''' 3360 Source source = addSource(r'''
3622 class A { 3361 class A {
3623 factory A() => null; 3362 factory A() => null;
3624 } 3363 }
3625 class B extends Object with A {}'''); 3364 class B extends Object with A {}''');
3626 computeLibrarySourceErrors(source);
3627 assertNoErrors(source); 3365 assertNoErrors(source);
3628 verify([source]); 3366 verify([source]);
3629 } 3367 }
3630 3368
3631 void test_mixinInheritsFromNotObject_classDeclaration_extends() { 3369 void test_mixinInheritsFromNotObject_classDeclaration_extends() {
3632 AnalysisOptionsImpl options = new AnalysisOptionsImpl(); 3370 AnalysisOptionsImpl options = new AnalysisOptionsImpl();
3633 options.enableSuperMixins = true; 3371 options.enableSuperMixins = true;
3634 resetWithOptions(options); 3372 resetWithOptions(options);
3635 Source source = addSource(r''' 3373 Source source = addSource(r'''
3636 class A {} 3374 class A {}
3637 class B extends A {} 3375 class B extends A {}
3638 class C extends Object with B {}'''); 3376 class C extends Object with B {}''');
3639 computeLibrarySourceErrors(source);
3640 assertNoErrors(source); 3377 assertNoErrors(source);
3641 verify([source]); 3378 verify([source]);
3642 } 3379 }
3643 3380
3644 void test_mixinInheritsFromNotObject_classDeclaration_mixTypeAlias() { 3381 void test_mixinInheritsFromNotObject_classDeclaration_mixTypeAlias() {
3645 Source source = addSource(r''' 3382 Source source = addSource(r'''
3646 class A {} 3383 class A {}
3647 class B = Object with A; 3384 class B = Object with A;
3648 class C extends Object with B {}'''); 3385 class C extends Object with B {}''');
3649 computeLibrarySourceErrors(source);
3650 assertNoErrors(source); 3386 assertNoErrors(source);
3651 verify([source]); 3387 verify([source]);
3652 } 3388 }
3653 3389
3654 void test_mixinInheritsFromNotObject_classDeclaration_with() { 3390 void test_mixinInheritsFromNotObject_classDeclaration_with() {
3655 AnalysisOptionsImpl options = new AnalysisOptionsImpl(); 3391 AnalysisOptionsImpl options = new AnalysisOptionsImpl();
3656 options.enableSuperMixins = true; 3392 options.enableSuperMixins = true;
3657 resetWithOptions(options); 3393 resetWithOptions(options);
3658 Source source = addSource(r''' 3394 Source source = addSource(r'''
3659 class A {} 3395 class A {}
3660 class B extends Object with A {} 3396 class B extends Object with A {}
3661 class C extends Object with B {}'''); 3397 class C extends Object with B {}''');
3662 computeLibrarySourceErrors(source);
3663 assertNoErrors(source); 3398 assertNoErrors(source);
3664 verify([source]); 3399 verify([source]);
3665 } 3400 }
3666 3401
3667 void test_mixinInheritsFromNotObject_typeAlias_extends() { 3402 void test_mixinInheritsFromNotObject_typeAlias_extends() {
3668 AnalysisOptionsImpl options = new AnalysisOptionsImpl(); 3403 AnalysisOptionsImpl options = new AnalysisOptionsImpl();
3669 options.enableSuperMixins = true; 3404 options.enableSuperMixins = true;
3670 resetWithOptions(options); 3405 resetWithOptions(options);
3671 Source source = addSource(r''' 3406 Source source = addSource(r'''
3672 class A {} 3407 class A {}
3673 class B extends A {} 3408 class B extends A {}
3674 class C = Object with B;'''); 3409 class C = Object with B;''');
3675 computeLibrarySourceErrors(source);
3676 assertNoErrors(source); 3410 assertNoErrors(source);
3677 verify([source]); 3411 verify([source]);
3678 } 3412 }
3679 3413
3680 void test_mixinInheritsFromNotObject_typeAlias_with() { 3414 void test_mixinInheritsFromNotObject_typeAlias_with() {
3681 AnalysisOptionsImpl options = new AnalysisOptionsImpl(); 3415 AnalysisOptionsImpl options = new AnalysisOptionsImpl();
3682 options.enableSuperMixins = true; 3416 options.enableSuperMixins = true;
3683 resetWithOptions(options); 3417 resetWithOptions(options);
3684 Source source = addSource(r''' 3418 Source source = addSource(r'''
3685 class A {} 3419 class A {}
3686 class B extends Object with A {} 3420 class B extends Object with A {}
3687 class C = Object with B;'''); 3421 class C = Object with B;''');
3688 computeLibrarySourceErrors(source);
3689 assertNoErrors(source); 3422 assertNoErrors(source);
3690 verify([source]); 3423 verify([source]);
3691 } 3424 }
3692 3425
3693 void test_mixinInheritsFromNotObject_typedef_mixTypeAlias() { 3426 void test_mixinInheritsFromNotObject_typedef_mixTypeAlias() {
3694 Source source = addSource(r''' 3427 Source source = addSource(r'''
3695 class A {} 3428 class A {}
3696 class B = Object with A; 3429 class B = Object with A;
3697 class C = Object with B;'''); 3430 class C = Object with B;''');
3698 computeLibrarySourceErrors(source);
3699 assertNoErrors(source); 3431 assertNoErrors(source);
3700 verify([source]); 3432 verify([source]);
3701 } 3433 }
3702 3434
3703 void test_mixinReferencesSuper() { 3435 void test_mixinReferencesSuper() {
3704 AnalysisOptionsImpl options = new AnalysisOptionsImpl(); 3436 AnalysisOptionsImpl options = new AnalysisOptionsImpl();
3705 options.enableSuperMixins = true; 3437 options.enableSuperMixins = true;
3706 resetWithOptions(options); 3438 resetWithOptions(options);
3707 Source source = addSource(r''' 3439 Source source = addSource(r'''
3708 class A { 3440 class A {
3709 toString() => super.toString(); 3441 toString() => super.toString();
3710 } 3442 }
3711 class B extends Object with A {}'''); 3443 class B extends Object with A {}''');
3712 computeLibrarySourceErrors(source);
3713 assertNoErrors(source); 3444 assertNoErrors(source);
3714 verify([source]); 3445 verify([source]);
3715 } 3446 }
3716 3447
3717 void test_multipleSuperInitializers_no() { 3448 void test_multipleSuperInitializers_no() {
3718 Source source = addSource(r''' 3449 Source source = addSource(r'''
3719 class A {} 3450 class A {}
3720 class B extends A { 3451 class B extends A {
3721 B() {} 3452 B() {}
3722 }'''); 3453 }''');
3723 computeLibrarySourceErrors(source);
3724 assertNoErrors(source); 3454 assertNoErrors(source);
3725 verify([source]); 3455 verify([source]);
3726 } 3456 }
3727 3457
3728 void test_multipleSuperInitializers_single() { 3458 void test_multipleSuperInitializers_single() {
3729 Source source = addSource(r''' 3459 Source source = addSource(r'''
3730 class A {} 3460 class A {}
3731 class B extends A { 3461 class B extends A {
3732 B() : super() {} 3462 B() : super() {}
3733 }'''); 3463 }''');
3734 computeLibrarySourceErrors(source);
3735 assertNoErrors(source); 3464 assertNoErrors(source);
3736 verify([source]); 3465 verify([source]);
3737 } 3466 }
3738 3467
3739 void test_nativeConstConstructor() { 3468 void test_nativeConstConstructor() {
3740 Source source = addSource(r''' 3469 Source source = addSource(r'''
3741 import 'dart-ext:x'; 3470 import 'dart-ext:x';
3742 class Foo { 3471 class Foo {
3743 const Foo() native 'Foo_Foo'; 3472 const Foo() native 'Foo_Foo';
3744 const factory Foo.foo() native 'Foo_Foo_foo'; 3473 const factory Foo.foo() native 'Foo_Foo_foo';
3745 }'''); 3474 }''');
3746 computeLibrarySourceErrors(source);
3747 assertNoErrors(source); 3475 assertNoErrors(source);
3748 // Cannot verify the AST because the import's URI cannot be resolved. 3476 // Cannot verify the AST because the import's URI cannot be resolved.
3749 } 3477 }
3750 3478
3751 void test_nativeFunctionBodyInNonSDKCode_function() { 3479 void test_nativeFunctionBodyInNonSDKCode_function() {
3752 Source source = addSource(r''' 3480 Source source = addSource(r'''
3753 import 'dart-ext:x'; 3481 import 'dart-ext:x';
3754 int m(a) native 'string';'''); 3482 int m(a) native 'string';''');
3755 computeLibrarySourceErrors(source);
3756 assertNoErrors(source); 3483 assertNoErrors(source);
3757 // Cannot verify the AST because the import's URI cannot be resolved. 3484 // Cannot verify the AST because the import's URI cannot be resolved.
3758 } 3485 }
3759 3486
3760 void test_newWithAbstractClass_factory() { 3487 void test_newWithAbstractClass_factory() {
3761 Source source = addSource(r''' 3488 Source source = addSource(r'''
3762 abstract class A { 3489 abstract class A {
3763 factory A() { return new B(); } 3490 factory A() { return new B(); }
3764 } 3491 }
3765 class B implements A { 3492 class B implements A {
3766 B() {} 3493 B() {}
3767 } 3494 }
3768 A f() { 3495 A f() {
3769 return new A(); 3496 return new A();
3770 }'''); 3497 }''');
3771 computeLibrarySourceErrors(source);
3772 assertNoErrors(source); 3498 assertNoErrors(source);
3773 verify([source]); 3499 verify([source]);
3774 } 3500 }
3775 3501
3776 void test_newWithUndefinedConstructor() { 3502 void test_newWithUndefinedConstructor() {
3777 Source source = addSource(r''' 3503 Source source = addSource(r'''
3778 class A { 3504 class A {
3779 A.name() {} 3505 A.name() {}
3780 } 3506 }
3781 f() { 3507 f() {
3782 new A.name(); 3508 new A.name();
3783 }'''); 3509 }''');
3784 computeLibrarySourceErrors(source);
3785 assertNoErrors(source); 3510 assertNoErrors(source);
3786 verify([source]); 3511 verify([source]);
3787 } 3512 }
3788 3513
3789 void test_newWithUndefinedConstructorDefault() { 3514 void test_newWithUndefinedConstructorDefault() {
3790 Source source = addSource(r''' 3515 Source source = addSource(r'''
3791 class A { 3516 class A {
3792 A() {} 3517 A() {}
3793 } 3518 }
3794 f() { 3519 f() {
3795 new A(); 3520 new A();
3796 }'''); 3521 }''');
3797 computeLibrarySourceErrors(source);
3798 assertNoErrors(source); 3522 assertNoErrors(source);
3799 verify([source]); 3523 verify([source]);
3800 } 3524 }
3801 3525
3802 void 3526 void
3803 test_nonAbstractClassInheritsAbstractMemberOne_abstractsDontOverrideConcre tes_getter() { 3527 test_nonAbstractClassInheritsAbstractMemberOne_abstractsDontOverrideConcre tes_getter() {
3804 Source source = addSource(r''' 3528 Source source = addSource(r'''
3805 class A { 3529 class A {
3806 int get g => 0; 3530 int get g => 0;
3807 } 3531 }
3808 abstract class B extends A { 3532 abstract class B extends A {
3809 int get g; 3533 int get g;
3810 } 3534 }
3811 class C extends B {}'''); 3535 class C extends B {}''');
3812 computeLibrarySourceErrors(source);
3813 assertNoErrors(source); 3536 assertNoErrors(source);
3814 verify([source]); 3537 verify([source]);
3815 } 3538 }
3816 3539
3817 void 3540 void
3818 test_nonAbstractClassInheritsAbstractMemberOne_abstractsDontOverrideConcre tes_method() { 3541 test_nonAbstractClassInheritsAbstractMemberOne_abstractsDontOverrideConcre tes_method() {
3819 Source source = addSource(r''' 3542 Source source = addSource(r'''
3820 class A { 3543 class A {
3821 m(p) {} 3544 m(p) {}
3822 } 3545 }
3823 abstract class B extends A { 3546 abstract class B extends A {
3824 m(p); 3547 m(p);
3825 } 3548 }
3826 class C extends B {}'''); 3549 class C extends B {}''');
3827 computeLibrarySourceErrors(source);
3828 assertNoErrors(source); 3550 assertNoErrors(source);
3829 verify([source]); 3551 verify([source]);
3830 } 3552 }
3831 3553
3832 void 3554 void
3833 test_nonAbstractClassInheritsAbstractMemberOne_abstractsDontOverrideConcre tes_setter() { 3555 test_nonAbstractClassInheritsAbstractMemberOne_abstractsDontOverrideConcre tes_setter() {
3834 Source source = addSource(r''' 3556 Source source = addSource(r'''
3835 class A { 3557 class A {
3836 set s(v) {} 3558 set s(v) {}
3837 } 3559 }
3838 abstract class B extends A { 3560 abstract class B extends A {
3839 set s(v); 3561 set s(v);
3840 } 3562 }
3841 class C extends B {}'''); 3563 class C extends B {}''');
3842 computeLibrarySourceErrors(source);
3843 assertNoErrors(source); 3564 assertNoErrors(source);
3844 verify([source]); 3565 verify([source]);
3845 } 3566 }
3846 3567
3847 void 3568 void
3848 test_nonAbstractClassInheritsAbstractMemberOne_classTypeAlias_interface() { 3569 test_nonAbstractClassInheritsAbstractMemberOne_classTypeAlias_interface() {
3849 // 15979 3570 // 15979
3850 Source source = addSource(r''' 3571 Source source = addSource(r'''
3851 abstract class M {} 3572 abstract class M {}
3852 abstract class A {} 3573 abstract class A {}
3853 abstract class I { 3574 abstract class I {
3854 m(); 3575 m();
3855 } 3576 }
3856 abstract class B = A with M implements I;'''); 3577 abstract class B = A with M implements I;''');
3857 computeLibrarySourceErrors(source);
3858 assertNoErrors(source); 3578 assertNoErrors(source);
3859 verify([source]); 3579 verify([source]);
3860 } 3580 }
3861 3581
3862 void test_nonAbstractClassInheritsAbstractMemberOne_classTypeAlias_mixin() { 3582 void test_nonAbstractClassInheritsAbstractMemberOne_classTypeAlias_mixin() {
3863 // 15979 3583 // 15979
3864 Source source = addSource(r''' 3584 Source source = addSource(r'''
3865 abstract class M { 3585 abstract class M {
3866 m(); 3586 m();
3867 } 3587 }
3868 abstract class A {} 3588 abstract class A {}
3869 abstract class B = A with M;'''); 3589 abstract class B = A with M;''');
3870 computeLibrarySourceErrors(source);
3871 assertNoErrors(source); 3590 assertNoErrors(source);
3872 verify([source]); 3591 verify([source]);
3873 } 3592 }
3874 3593
3875 void 3594 void
3876 test_nonAbstractClassInheritsAbstractMemberOne_classTypeAlias_superclass() { 3595 test_nonAbstractClassInheritsAbstractMemberOne_classTypeAlias_superclass() {
3877 // 15979 3596 // 15979
3878 Source source = addSource(r''' 3597 Source source = addSource(r'''
3879 class M {} 3598 class M {}
3880 abstract class A { 3599 abstract class A {
3881 m(); 3600 m();
3882 } 3601 }
3883 abstract class B = A with M;'''); 3602 abstract class B = A with M;''');
3884 computeLibrarySourceErrors(source);
3885 assertNoErrors(source); 3603 assertNoErrors(source);
3886 verify([source]); 3604 verify([source]);
3887 } 3605 }
3888 3606
3889 void test_nonAbstractClassInheritsAbstractMemberOne_mixin_getter() { 3607 void test_nonAbstractClassInheritsAbstractMemberOne_mixin_getter() {
3890 // 17034 3608 // 17034
3891 Source source = addSource(r''' 3609 Source source = addSource(r'''
3892 class A { 3610 class A {
3893 var a; 3611 var a;
3894 } 3612 }
3895 abstract class M { 3613 abstract class M {
3896 get a; 3614 get a;
3897 } 3615 }
3898 class B extends A with M {} 3616 class B extends A with M {}
3899 class C extends B {}'''); 3617 class C extends B {}''');
3900 computeLibrarySourceErrors(source);
3901 assertNoErrors(source); 3618 assertNoErrors(source);
3902 verify([source]); 3619 verify([source]);
3903 } 3620 }
3904 3621
3905 void test_nonAbstractClassInheritsAbstractMemberOne_mixin_method() { 3622 void test_nonAbstractClassInheritsAbstractMemberOne_mixin_method() {
3906 Source source = addSource(r''' 3623 Source source = addSource(r'''
3907 class A { 3624 class A {
3908 m() {} 3625 m() {}
3909 } 3626 }
3910 abstract class M { 3627 abstract class M {
3911 m(); 3628 m();
3912 } 3629 }
3913 class B extends A with M {} 3630 class B extends A with M {}
3914 class C extends B {}'''); 3631 class C extends B {}''');
3915 computeLibrarySourceErrors(source);
3916 assertNoErrors(source); 3632 assertNoErrors(source);
3917 verify([source]); 3633 verify([source]);
3918 } 3634 }
3919 3635
3920 void test_nonAbstractClassInheritsAbstractMemberOne_mixin_setter() { 3636 void test_nonAbstractClassInheritsAbstractMemberOne_mixin_setter() {
3921 Source source = addSource(r''' 3637 Source source = addSource(r'''
3922 class A { 3638 class A {
3923 var a; 3639 var a;
3924 } 3640 }
3925 abstract class M { 3641 abstract class M {
3926 set a(dynamic v); 3642 set a(dynamic v);
3927 } 3643 }
3928 class B extends A with M {} 3644 class B extends A with M {}
3929 class C extends B {}'''); 3645 class C extends B {}''');
3930 computeLibrarySourceErrors(source);
3931 assertNoErrors(source); 3646 assertNoErrors(source);
3932 verify([source]); 3647 verify([source]);
3933 } 3648 }
3934 3649
3935 void test_nonAbstractClassInheritsAbstractMemberOne_noSuchMethod_accessor() { 3650 void test_nonAbstractClassInheritsAbstractMemberOne_noSuchMethod_accessor() {
3936 Source source = addSource(r''' 3651 Source source = addSource(r'''
3937 abstract class A { 3652 abstract class A {
3938 int get g; 3653 int get g;
3939 } 3654 }
3940 class B extends A { 3655 class B extends A {
3941 noSuchMethod(v) => ''; 3656 noSuchMethod(v) => '';
3942 }'''); 3657 }''');
3943 computeLibrarySourceErrors(source);
3944 assertNoErrors(source); 3658 assertNoErrors(source);
3945 verify([source]); 3659 verify([source]);
3946 } 3660 }
3947 3661
3948 void test_nonAbstractClassInheritsAbstractMemberOne_noSuchMethod_method() { 3662 void test_nonAbstractClassInheritsAbstractMemberOne_noSuchMethod_method() {
3949 Source source = addSource(r''' 3663 Source source = addSource(r'''
3950 abstract class A { 3664 abstract class A {
3951 m(p); 3665 m(p);
3952 } 3666 }
3953 class B extends A { 3667 class B extends A {
3954 noSuchMethod(v) => ''; 3668 noSuchMethod(v) => '';
3955 }'''); 3669 }''');
3956 computeLibrarySourceErrors(source);
3957 assertNoErrors(source); 3670 assertNoErrors(source);
3958 verify([source]); 3671 verify([source]);
3959 } 3672 }
3960 3673
3961 void test_nonAbstractClassInheritsAbstractMemberOne_noSuchMethod_mixin() { 3674 void test_nonAbstractClassInheritsAbstractMemberOne_noSuchMethod_mixin() {
3962 Source source = addSource(r''' 3675 Source source = addSource(r'''
3963 class A { 3676 class A {
3964 noSuchMethod(v) => ''; 3677 noSuchMethod(v) => '';
3965 } 3678 }
3966 class B extends Object with A { 3679 class B extends Object with A {
3967 m(p); 3680 m(p);
3968 }'''); 3681 }''');
3969 computeLibrarySourceErrors(source);
3970 assertNoErrors(source); 3682 assertNoErrors(source);
3971 verify([source]); 3683 verify([source]);
3972 } 3684 }
3973 3685
3974 void 3686 void
3975 test_nonAbstractClassInheritsAbstractMemberOne_noSuchMethod_superclass() { 3687 test_nonAbstractClassInheritsAbstractMemberOne_noSuchMethod_superclass() {
3976 Source source = addSource(r''' 3688 Source source = addSource(r'''
3977 class A { 3689 class A {
3978 noSuchMethod(v) => ''; 3690 noSuchMethod(v) => '';
3979 } 3691 }
3980 class B extends A { 3692 class B extends A {
3981 m(p); 3693 m(p);
3982 }'''); 3694 }''');
3983 computeLibrarySourceErrors(source);
3984 assertNoErrors(source); 3695 assertNoErrors(source);
3985 verify([source]); 3696 verify([source]);
3986 } 3697 }
3987 3698
3988 void 3699 void
3989 test_nonAbstractClassInheritsAbstractMemberOne_overridesMethodInObject() { 3700 test_nonAbstractClassInheritsAbstractMemberOne_overridesMethodInObject() {
3990 Source source = addSource(r''' 3701 Source source = addSource(r'''
3991 class A { 3702 class A {
3992 String toString([String prefix = '']) => '${prefix}Hello'; 3703 String toString([String prefix = '']) => '${prefix}Hello';
3993 } 3704 }
3994 class C {} 3705 class C {}
3995 class B extends A with C {}'''); 3706 class B extends A with C {}''');
3996 computeLibrarySourceErrors(source);
3997 assertNoErrors(source); 3707 assertNoErrors(source);
3998 verify([source]); 3708 verify([source]);
3999 } 3709 }
4000 3710
4001 void test_nonBoolExpression_functionType() { 3711 void test_nonBoolExpression_functionType() {
4002 Source source = addSource(r''' 3712 Source source = addSource(r'''
4003 bool makeAssertion() => true; 3713 bool makeAssertion() => true;
4004 f() { 3714 f() {
4005 assert(makeAssertion); 3715 assert(makeAssertion);
4006 }'''); 3716 }''');
4007 computeLibrarySourceErrors(source);
4008 assertNoErrors(source); 3717 assertNoErrors(source);
4009 verify([source]); 3718 verify([source]);
4010 } 3719 }
4011 3720
4012 void test_nonBoolExpression_interfaceType() { 3721 void test_nonBoolExpression_interfaceType() {
4013 Source source = addSource(r''' 3722 Source source = addSource(r'''
4014 f() { 3723 f() {
4015 assert(true); 3724 assert(true);
4016 }'''); 3725 }''');
4017 computeLibrarySourceErrors(source);
4018 assertNoErrors(source); 3726 assertNoErrors(source);
4019 verify([source]); 3727 verify([source]);
4020 } 3728 }
4021 3729
4022 void test_nonBoolNegationExpression() { 3730 void test_nonBoolNegationExpression() {
4023 Source source = addSource(r''' 3731 Source source = addSource(r'''
4024 f(bool pb, pd) { 3732 f(bool pb, pd) {
4025 !true; 3733 !true;
4026 !false; 3734 !false;
4027 !pb; 3735 !pb;
4028 !pd; 3736 !pd;
4029 }'''); 3737 }''');
4030 computeLibrarySourceErrors(source);
4031 assertNoErrors(source); 3738 assertNoErrors(source);
4032 verify([source]); 3739 verify([source]);
4033 } 3740 }
4034 3741
4035 void test_nonBoolNegationExpression_dynamic() { 3742 void test_nonBoolNegationExpression_dynamic() {
4036 Source source = addSource(r''' 3743 Source source = addSource(r'''
4037 f1(bool dynamic) { 3744 f1(bool dynamic) {
4038 !dynamic; 3745 !dynamic;
4039 } 3746 }
4040 f2() { 3747 f2() {
4041 bool dynamic = true; 3748 bool dynamic = true;
4042 !dynamic; 3749 !dynamic;
4043 } 3750 }
4044 '''); 3751 ''');
4045 computeLibrarySourceErrors(source);
4046 assertNoErrors(source); 3752 assertNoErrors(source);
4047 verify([source]); 3753 verify([source]);
4048 } 3754 }
4049 3755
4050 void test_nonBoolOperand_and_bool() { 3756 void test_nonBoolOperand_and_bool() {
4051 Source source = addSource(r''' 3757 Source source = addSource(r'''
4052 bool f(bool left, bool right) { 3758 bool f(bool left, bool right) {
4053 return left && right; 3759 return left && right;
4054 }'''); 3760 }''');
4055 computeLibrarySourceErrors(source);
4056 assertNoErrors(source); 3761 assertNoErrors(source);
4057 verify([source]); 3762 verify([source]);
4058 } 3763 }
4059 3764
4060 void test_nonBoolOperand_and_dynamic() { 3765 void test_nonBoolOperand_and_dynamic() {
4061 Source source = addSource(r''' 3766 Source source = addSource(r'''
4062 bool f(left, dynamic right) { 3767 bool f(left, dynamic right) {
4063 return left && right; 3768 return left && right;
4064 }'''); 3769 }''');
4065 computeLibrarySourceErrors(source);
4066 assertNoErrors(source); 3770 assertNoErrors(source);
4067 verify([source]); 3771 verify([source]);
4068 } 3772 }
4069 3773
4070 void test_nonBoolOperand_or_bool() { 3774 void test_nonBoolOperand_or_bool() {
4071 Source source = addSource(r''' 3775 Source source = addSource(r'''
4072 bool f(bool left, bool right) { 3776 bool f(bool left, bool right) {
4073 return left || right; 3777 return left || right;
4074 }'''); 3778 }''');
4075 computeLibrarySourceErrors(source);
4076 assertNoErrors(source); 3779 assertNoErrors(source);
4077 verify([source]); 3780 verify([source]);
4078 } 3781 }
4079 3782
4080 void test_nonBoolOperand_or_dynamic() { 3783 void test_nonBoolOperand_or_dynamic() {
4081 Source source = addSource(r''' 3784 Source source = addSource(r'''
4082 bool f(dynamic left, right) { 3785 bool f(dynamic left, right) {
4083 return left || right; 3786 return left || right;
4084 }'''); 3787 }''');
4085 computeLibrarySourceErrors(source);
4086 assertNoErrors(source); 3788 assertNoErrors(source);
4087 verify([source]); 3789 verify([source]);
4088 } 3790 }
4089 3791
4090 void test_nonConstantDefaultValue_constField() { 3792 void test_nonConstantDefaultValue_constField() {
4091 Source source = addSource(r''' 3793 Source source = addSource(r'''
4092 f([a = double.INFINITY]) { 3794 f([a = double.INFINITY]) {
4093 }'''); 3795 }''');
4094 computeLibrarySourceErrors(source);
4095 assertNoErrors(source); 3796 assertNoErrors(source);
4096 verify([source]); 3797 verify([source]);
4097 } 3798 }
4098 3799
4099 void test_nonConstantDefaultValue_function_named() { 3800 void test_nonConstantDefaultValue_function_named() {
4100 Source source = addSource("f({x : 2 + 3}) {}"); 3801 Source source = addSource("f({x : 2 + 3}) {}");
4101 computeLibrarySourceErrors(source);
4102 assertNoErrors(source); 3802 assertNoErrors(source);
4103 verify([source]); 3803 verify([source]);
4104 } 3804 }
4105 3805
4106 void test_nonConstantDefaultValue_function_positional() { 3806 void test_nonConstantDefaultValue_function_positional() {
4107 Source source = addSource("f([x = 2 + 3]) {}"); 3807 Source source = addSource("f([x = 2 + 3]) {}");
4108 computeLibrarySourceErrors(source);
4109 assertNoErrors(source); 3808 assertNoErrors(source);
4110 verify([source]); 3809 verify([source]);
4111 } 3810 }
4112 3811
4113 void test_nonConstantDefaultValue_inConstructor_named() { 3812 void test_nonConstantDefaultValue_inConstructor_named() {
4114 Source source = addSource(r''' 3813 Source source = addSource(r'''
4115 class A { 3814 class A {
4116 A({x : 2 + 3}) {} 3815 A({x : 2 + 3}) {}
4117 }'''); 3816 }''');
4118 computeLibrarySourceErrors(source);
4119 assertNoErrors(source); 3817 assertNoErrors(source);
4120 verify([source]); 3818 verify([source]);
4121 } 3819 }
4122 3820
4123 void test_nonConstantDefaultValue_inConstructor_positional() { 3821 void test_nonConstantDefaultValue_inConstructor_positional() {
4124 Source source = addSource(r''' 3822 Source source = addSource(r'''
4125 class A { 3823 class A {
4126 A([x = 2 + 3]) {} 3824 A([x = 2 + 3]) {}
4127 }'''); 3825 }''');
4128 computeLibrarySourceErrors(source);
4129 assertNoErrors(source); 3826 assertNoErrors(source);
4130 verify([source]); 3827 verify([source]);
4131 } 3828 }
4132 3829
4133 void test_nonConstantDefaultValue_method_named() { 3830 void test_nonConstantDefaultValue_method_named() {
4134 Source source = addSource(r''' 3831 Source source = addSource(r'''
4135 class A { 3832 class A {
4136 m({x : 2 + 3}) {} 3833 m({x : 2 + 3}) {}
4137 }'''); 3834 }''');
4138 computeLibrarySourceErrors(source);
4139 assertNoErrors(source); 3835 assertNoErrors(source);
4140 verify([source]); 3836 verify([source]);
4141 } 3837 }
4142 3838
4143 void test_nonConstantDefaultValue_method_positional() { 3839 void test_nonConstantDefaultValue_method_positional() {
4144 Source source = addSource(r''' 3840 Source source = addSource(r'''
4145 class A { 3841 class A {
4146 m([x = 2 + 3]) {} 3842 m([x = 2 + 3]) {}
4147 }'''); 3843 }''');
4148 computeLibrarySourceErrors(source);
4149 assertNoErrors(source); 3844 assertNoErrors(source);
4150 verify([source]); 3845 verify([source]);
4151 } 3846 }
4152 3847
4153 void test_nonConstantDefaultValue_typedConstList() { 3848 void test_nonConstantDefaultValue_typedConstList() {
4154 Source source = addSource(r''' 3849 Source source = addSource(r'''
4155 class A { 3850 class A {
4156 m([p111 = const <String>[]]) {} 3851 m([p111 = const <String>[]]) {}
4157 } 3852 }
4158 class B extends A { 3853 class B extends A {
4159 m([p222 = const <String>[]]) {} 3854 m([p222 = const <String>[]]) {}
4160 }'''); 3855 }''');
4161 computeLibrarySourceErrors(source);
4162 assertNoErrors(source); 3856 assertNoErrors(source);
4163 verify([source]); 3857 verify([source]);
4164 } 3858 }
4165 3859
4166 void test_nonConstantValueInInitializer_namedArgument() { 3860 void test_nonConstantValueInInitializer_namedArgument() {
4167 Source source = addSource(r''' 3861 Source source = addSource(r'''
4168 class A { 3862 class A {
4169 final a; 3863 final a;
4170 const A({this.a}); 3864 const A({this.a});
4171 } 3865 }
4172 class B extends A { 3866 class B extends A {
4173 const B({b}) : super(a: b); 3867 const B({b}) : super(a: b);
4174 }'''); 3868 }''');
4175 computeLibrarySourceErrors(source);
4176 assertNoErrors(source); 3869 assertNoErrors(source);
4177 verify([source]); 3870 verify([source]);
4178 } 3871 }
4179 3872
4180 void test_nonConstCaseExpression_constField() { 3873 void test_nonConstCaseExpression_constField() {
4181 Source source = addSource(r''' 3874 Source source = addSource(r'''
4182 f(double p) { 3875 f(double p) {
4183 switch (p) { 3876 switch (p) {
4184 case double.INFINITY: 3877 case double.INFINITY:
4185 return true; 3878 return true;
4186 default: 3879 default:
4187 return false; 3880 return false;
4188 } 3881 }
4189 }'''); 3882 }''');
4190 computeLibrarySourceErrors(source);
4191 assertErrors( 3883 assertErrors(
4192 source, [CompileTimeErrorCode.CASE_EXPRESSION_TYPE_IMPLEMENTS_EQUALS]); 3884 source, [CompileTimeErrorCode.CASE_EXPRESSION_TYPE_IMPLEMENTS_EQUALS]);
4193 verify([source]); 3885 verify([source]);
4194 } 3886 }
4195 3887
4196 void test_nonConstCaseExpression_typeLiteral() { 3888 void test_nonConstCaseExpression_typeLiteral() {
4197 Source source = addSource(r''' 3889 Source source = addSource(r'''
4198 f(Type t) { 3890 f(Type t) {
4199 switch (t) { 3891 switch (t) {
4200 case bool: 3892 case bool:
4201 case int: 3893 case int:
4202 return true; 3894 return true;
4203 default: 3895 default:
4204 return false; 3896 return false;
4205 } 3897 }
4206 }'''); 3898 }''');
4207 computeLibrarySourceErrors(source);
4208 assertNoErrors(source); 3899 assertNoErrors(source);
4209 verify([source]); 3900 verify([source]);
4210 } 3901 }
4211 3902
4212 void test_nonConstListElement_constField() { 3903 void test_nonConstListElement_constField() {
4213 Source source = addSource(r''' 3904 Source source = addSource(r'''
4214 main() { 3905 main() {
4215 const [double.INFINITY]; 3906 const [double.INFINITY];
4216 }'''); 3907 }''');
4217 computeLibrarySourceErrors(source);
4218 assertNoErrors(source); 3908 assertNoErrors(source);
4219 verify([source]); 3909 verify([source]);
4220 } 3910 }
4221 3911
4222 void test_nonConstMapAsExpressionStatement_const() { 3912 void test_nonConstMapAsExpressionStatement_const() {
4223 Source source = addSource(r''' 3913 Source source = addSource(r'''
4224 f() { 3914 f() {
4225 const {'a' : 0, 'b' : 1}; 3915 const {'a' : 0, 'b' : 1};
4226 }'''); 3916 }''');
4227 computeLibrarySourceErrors(source);
4228 assertNoErrors(source); 3917 assertNoErrors(source);
4229 verify([source]); 3918 verify([source]);
4230 } 3919 }
4231 3920
4232 void test_nonConstMapAsExpressionStatement_notExpressionStatement() { 3921 void test_nonConstMapAsExpressionStatement_notExpressionStatement() {
4233 Source source = addSource(r''' 3922 Source source = addSource(r'''
4234 f() { 3923 f() {
4235 var m = {'a' : 0, 'b' : 1}; 3924 var m = {'a' : 0, 'b' : 1};
4236 }'''); 3925 }''');
4237 computeLibrarySourceErrors(source);
4238 assertNoErrors(source); 3926 assertNoErrors(source);
4239 verify([source]); 3927 verify([source]);
4240 } 3928 }
4241 3929
4242 void test_nonConstMapAsExpressionStatement_typeArguments() { 3930 void test_nonConstMapAsExpressionStatement_typeArguments() {
4243 Source source = addSource(r''' 3931 Source source = addSource(r'''
4244 f() { 3932 f() {
4245 <String, int> {'a' : 0, 'b' : 1}; 3933 <String, int> {'a' : 0, 'b' : 1};
4246 }'''); 3934 }''');
4247 computeLibrarySourceErrors(source);
4248 assertNoErrors(source); 3935 assertNoErrors(source);
4249 verify([source]); 3936 verify([source]);
4250 } 3937 }
4251 3938
4252 void test_nonConstMapKey_constField() { 3939 void test_nonConstMapKey_constField() {
4253 Source source = addSource(r''' 3940 Source source = addSource(r'''
4254 main() { 3941 main() {
4255 const {double.INFINITY: 0}; 3942 const {double.INFINITY: 0};
4256 }'''); 3943 }''');
4257 computeLibrarySourceErrors(source);
4258 assertErrors(source, 3944 assertErrors(source,
4259 [CompileTimeErrorCode.CONST_MAP_KEY_EXPRESSION_TYPE_IMPLEMENTS_EQUALS]); 3945 [CompileTimeErrorCode.CONST_MAP_KEY_EXPRESSION_TYPE_IMPLEMENTS_EQUALS]);
4260 verify([source]); 3946 verify([source]);
4261 } 3947 }
4262 3948
4263 void test_nonConstMapValue_constField() { 3949 void test_nonConstMapValue_constField() {
4264 Source source = addSource(r''' 3950 Source source = addSource(r'''
4265 main() { 3951 main() {
4266 const {0: double.INFINITY}; 3952 const {0: double.INFINITY};
4267 }'''); 3953 }''');
4268 computeLibrarySourceErrors(source);
4269 assertNoErrors(source); 3954 assertNoErrors(source);
4270 verify([source]); 3955 verify([source]);
4271 } 3956 }
4272 3957
4273 void test_nonConstValueInInitializer_binary_bool() { 3958 void test_nonConstValueInInitializer_binary_bool() {
4274 Source source = addSource(r''' 3959 Source source = addSource(r'''
4275 class A { 3960 class A {
4276 final v; 3961 final v;
4277 const A.a1(bool p) : v = p && true; 3962 const A.a1(bool p) : v = p && true;
4278 const A.a2(bool p) : v = true && p; 3963 const A.a2(bool p) : v = true && p;
4279 const A.b1(bool p) : v = p || true; 3964 const A.b1(bool p) : v = p || true;
4280 const A.b2(bool p) : v = true || p; 3965 const A.b2(bool p) : v = true || p;
4281 }'''); 3966 }''');
4282 computeLibrarySourceErrors(source);
4283 assertErrors(source, [HintCode.DEAD_CODE]); 3967 assertErrors(source, [HintCode.DEAD_CODE]);
4284 verify([source]); 3968 verify([source]);
4285 } 3969 }
4286 3970
4287 void test_nonConstValueInInitializer_binary_dynamic() { 3971 void test_nonConstValueInInitializer_binary_dynamic() {
4288 Source source = addSource(r''' 3972 Source source = addSource(r'''
4289 class A { 3973 class A {
4290 final v; 3974 final v;
4291 const A.a1(p) : v = p + 5; 3975 const A.a1(p) : v = p + 5;
4292 const A.a2(p) : v = 5 + p; 3976 const A.a2(p) : v = 5 + p;
4293 const A.b1(p) : v = p - 5; 3977 const A.b1(p) : v = p - 5;
4294 const A.b2(p) : v = 5 - p; 3978 const A.b2(p) : v = 5 - p;
4295 const A.c1(p) : v = p * 5; 3979 const A.c1(p) : v = p * 5;
4296 const A.c2(p) : v = 5 * p; 3980 const A.c2(p) : v = 5 * p;
4297 const A.d1(p) : v = p / 5; 3981 const A.d1(p) : v = p / 5;
4298 const A.d2(p) : v = 5 / p; 3982 const A.d2(p) : v = 5 / p;
4299 const A.e1(p) : v = p ~/ 5; 3983 const A.e1(p) : v = p ~/ 5;
4300 const A.e2(p) : v = 5 ~/ p; 3984 const A.e2(p) : v = 5 ~/ p;
4301 const A.f1(p) : v = p > 5; 3985 const A.f1(p) : v = p > 5;
4302 const A.f2(p) : v = 5 > p; 3986 const A.f2(p) : v = 5 > p;
4303 const A.g1(p) : v = p < 5; 3987 const A.g1(p) : v = p < 5;
4304 const A.g2(p) : v = 5 < p; 3988 const A.g2(p) : v = 5 < p;
4305 const A.h1(p) : v = p >= 5; 3989 const A.h1(p) : v = p >= 5;
4306 const A.h2(p) : v = 5 >= p; 3990 const A.h2(p) : v = 5 >= p;
4307 const A.i1(p) : v = p <= 5; 3991 const A.i1(p) : v = p <= 5;
4308 const A.i2(p) : v = 5 <= p; 3992 const A.i2(p) : v = 5 <= p;
4309 const A.j1(p) : v = p % 5; 3993 const A.j1(p) : v = p % 5;
4310 const A.j2(p) : v = 5 % p; 3994 const A.j2(p) : v = 5 % p;
4311 }'''); 3995 }''');
4312 computeLibrarySourceErrors(source);
4313 assertNoErrors(source); 3996 assertNoErrors(source);
4314 // operations on "p" are not resolved 3997 // operations on "p" are not resolved
4315 } 3998 }
4316 3999
4317 void test_nonConstValueInInitializer_binary_int() { 4000 void test_nonConstValueInInitializer_binary_int() {
4318 Source source = addSource(r''' 4001 Source source = addSource(r'''
4319 class A { 4002 class A {
4320 final v; 4003 final v;
4321 const A.a1(int p) : v = p ^ 5; 4004 const A.a1(int p) : v = p ^ 5;
4322 const A.a2(int p) : v = 5 ^ p; 4005 const A.a2(int p) : v = 5 ^ p;
4323 const A.b1(int p) : v = p & 5; 4006 const A.b1(int p) : v = p & 5;
4324 const A.b2(int p) : v = 5 & p; 4007 const A.b2(int p) : v = 5 & p;
4325 const A.c1(int p) : v = p | 5; 4008 const A.c1(int p) : v = p | 5;
4326 const A.c2(int p) : v = 5 | p; 4009 const A.c2(int p) : v = 5 | p;
4327 const A.d1(int p) : v = p >> 5; 4010 const A.d1(int p) : v = p >> 5;
4328 const A.d2(int p) : v = 5 >> p; 4011 const A.d2(int p) : v = 5 >> p;
4329 const A.e1(int p) : v = p << 5; 4012 const A.e1(int p) : v = p << 5;
4330 const A.e2(int p) : v = 5 << p; 4013 const A.e2(int p) : v = 5 << p;
4331 }'''); 4014 }''');
4332 computeLibrarySourceErrors(source);
4333 assertNoErrors(source); 4015 assertNoErrors(source);
4334 verify([source]); 4016 verify([source]);
4335 } 4017 }
4336 4018
4337 void test_nonConstValueInInitializer_binary_num() { 4019 void test_nonConstValueInInitializer_binary_num() {
4338 Source source = addSource(r''' 4020 Source source = addSource(r'''
4339 class A { 4021 class A {
4340 final v; 4022 final v;
4341 const A.a1(num p) : v = p + 5; 4023 const A.a1(num p) : v = p + 5;
4342 const A.a2(num p) : v = 5 + p; 4024 const A.a2(num p) : v = 5 + p;
4343 const A.b1(num p) : v = p - 5; 4025 const A.b1(num p) : v = p - 5;
4344 const A.b2(num p) : v = 5 - p; 4026 const A.b2(num p) : v = 5 - p;
4345 const A.c1(num p) : v = p * 5; 4027 const A.c1(num p) : v = p * 5;
4346 const A.c2(num p) : v = 5 * p; 4028 const A.c2(num p) : v = 5 * p;
4347 const A.d1(num p) : v = p / 5; 4029 const A.d1(num p) : v = p / 5;
4348 const A.d2(num p) : v = 5 / p; 4030 const A.d2(num p) : v = 5 / p;
4349 const A.e1(num p) : v = p ~/ 5; 4031 const A.e1(num p) : v = p ~/ 5;
4350 const A.e2(num p) : v = 5 ~/ p; 4032 const A.e2(num p) : v = 5 ~/ p;
4351 const A.f1(num p) : v = p > 5; 4033 const A.f1(num p) : v = p > 5;
4352 const A.f2(num p) : v = 5 > p; 4034 const A.f2(num p) : v = 5 > p;
4353 const A.g1(num p) : v = p < 5; 4035 const A.g1(num p) : v = p < 5;
4354 const A.g2(num p) : v = 5 < p; 4036 const A.g2(num p) : v = 5 < p;
4355 const A.h1(num p) : v = p >= 5; 4037 const A.h1(num p) : v = p >= 5;
4356 const A.h2(num p) : v = 5 >= p; 4038 const A.h2(num p) : v = 5 >= p;
4357 const A.i1(num p) : v = p <= 5; 4039 const A.i1(num p) : v = p <= 5;
4358 const A.i2(num p) : v = 5 <= p; 4040 const A.i2(num p) : v = 5 <= p;
4359 const A.j1(num p) : v = p % 5; 4041 const A.j1(num p) : v = p % 5;
4360 const A.j2(num p) : v = 5 % p; 4042 const A.j2(num p) : v = 5 % p;
4361 }'''); 4043 }''');
4362 computeLibrarySourceErrors(source);
4363 assertNoErrors(source); 4044 assertNoErrors(source);
4364 verify([source]); 4045 verify([source]);
4365 } 4046 }
4366 4047
4367 void test_nonConstValueInInitializer_field() { 4048 void test_nonConstValueInInitializer_field() {
4368 Source source = addSource(r''' 4049 Source source = addSource(r'''
4369 class A { 4050 class A {
4370 final int a; 4051 final int a;
4371 const A() : a = 5; 4052 const A() : a = 5;
4372 }'''); 4053 }''');
4373 computeLibrarySourceErrors(source);
4374 assertNoErrors(source); 4054 assertNoErrors(source);
4375 verify([source]); 4055 verify([source]);
4376 } 4056 }
4377 4057
4378 void test_nonConstValueInInitializer_redirecting() { 4058 void test_nonConstValueInInitializer_redirecting() {
4379 Source source = addSource(r''' 4059 Source source = addSource(r'''
4380 class A { 4060 class A {
4381 const A.named(p); 4061 const A.named(p);
4382 const A() : this.named(42); 4062 const A() : this.named(42);
4383 }'''); 4063 }''');
4384 computeLibrarySourceErrors(source);
4385 assertNoErrors(source); 4064 assertNoErrors(source);
4386 verify([source]); 4065 verify([source]);
4387 } 4066 }
4388 4067
4389 void test_nonConstValueInInitializer_super() { 4068 void test_nonConstValueInInitializer_super() {
4390 Source source = addSource(r''' 4069 Source source = addSource(r'''
4391 class A { 4070 class A {
4392 const A(p); 4071 const A(p);
4393 } 4072 }
4394 class B extends A { 4073 class B extends A {
4395 const B() : super(42); 4074 const B() : super(42);
4396 }'''); 4075 }''');
4397 computeLibrarySourceErrors(source);
4398 assertNoErrors(source); 4076 assertNoErrors(source);
4399 verify([source]); 4077 verify([source]);
4400 } 4078 }
4401 4079
4402 void test_nonConstValueInInitializer_unary() { 4080 void test_nonConstValueInInitializer_unary() {
4403 Source source = addSource(r''' 4081 Source source = addSource(r'''
4404 class A { 4082 class A {
4405 final v; 4083 final v;
4406 const A.a(bool p) : v = !p; 4084 const A.a(bool p) : v = !p;
4407 const A.b(int p) : v = ~p; 4085 const A.b(int p) : v = ~p;
4408 const A.c(num p) : v = -p; 4086 const A.c(num p) : v = -p;
4409 }'''); 4087 }''');
4410 computeLibrarySourceErrors(source);
4411 assertNoErrors(source); 4088 assertNoErrors(source);
4412 verify([source]); 4089 verify([source]);
4413 } 4090 }
4414 4091
4415 void test_nonGenerativeConstructor() { 4092 void test_nonGenerativeConstructor() {
4416 Source source = addSource(r''' 4093 Source source = addSource(r'''
4417 class A { 4094 class A {
4418 A.named() {} 4095 A.named() {}
4419 factory A() => null; 4096 factory A() => null;
4420 } 4097 }
4421 class B extends A { 4098 class B extends A {
4422 B() : super.named(); 4099 B() : super.named();
4423 }'''); 4100 }''');
4424 computeLibrarySourceErrors(source);
4425 assertNoErrors(source); 4101 assertNoErrors(source);
4426 verify([source]); 4102 verify([source]);
4427 } 4103 }
4428 4104
4429 void test_nonTypeInCatchClause_isClass() { 4105 void test_nonTypeInCatchClause_isClass() {
4430 Source source = addSource(r''' 4106 Source source = addSource(r'''
4431 f() { 4107 f() {
4432 try { 4108 try {
4433 } on String catch (e) { 4109 } on String catch (e) {
4434 } 4110 }
4435 }'''); 4111 }''');
4436 computeLibrarySourceErrors(source);
4437 assertNoErrors(source); 4112 assertNoErrors(source);
4438 verify([source]); 4113 verify([source]);
4439 } 4114 }
4440 4115
4441 void test_nonTypeInCatchClause_isFunctionTypeAlias() { 4116 void test_nonTypeInCatchClause_isFunctionTypeAlias() {
4442 Source source = addSource(r''' 4117 Source source = addSource(r'''
4443 typedef F(); 4118 typedef F();
4444 f() { 4119 f() {
4445 try { 4120 try {
4446 } on F catch (e) { 4121 } on F catch (e) {
4447 } 4122 }
4448 }'''); 4123 }''');
4449 computeLibrarySourceErrors(source);
4450 assertNoErrors(source); 4124 assertNoErrors(source);
4451 verify([source]); 4125 verify([source]);
4452 } 4126 }
4453 4127
4454 void test_nonTypeInCatchClause_isTypeParameter() { 4128 void test_nonTypeInCatchClause_isTypeParameter() {
4455 Source source = addSource(r''' 4129 Source source = addSource(r'''
4456 class A<T> { 4130 class A<T> {
4457 f() { 4131 f() {
4458 try { 4132 try {
4459 } on T catch (e) { 4133 } on T catch (e) {
4460 } 4134 }
4461 } 4135 }
4462 }'''); 4136 }''');
4463 computeLibrarySourceErrors(source);
4464 assertNoErrors(source); 4137 assertNoErrors(source);
4465 verify([source]); 4138 verify([source]);
4466 } 4139 }
4467 4140
4468 void test_nonTypeInCatchClause_noType() { 4141 void test_nonTypeInCatchClause_noType() {
4469 Source source = addSource(r''' 4142 Source source = addSource(r'''
4470 f() { 4143 f() {
4471 try { 4144 try {
4472 } catch (e) { 4145 } catch (e) {
4473 } 4146 }
4474 }'''); 4147 }''');
4475 computeLibrarySourceErrors(source);
4476 assertNoErrors(source); 4148 assertNoErrors(source);
4477 verify([source]); 4149 verify([source]);
4478 } 4150 }
4479 4151
4480 void test_nonVoidReturnForOperator_no() { 4152 void test_nonVoidReturnForOperator_no() {
4481 Source source = addSource(r''' 4153 Source source = addSource(r'''
4482 class A { 4154 class A {
4483 operator []=(a, b) {} 4155 operator []=(a, b) {}
4484 }'''); 4156 }''');
4485 computeLibrarySourceErrors(source);
4486 assertNoErrors(source); 4157 assertNoErrors(source);
4487 verify([source]); 4158 verify([source]);
4488 } 4159 }
4489 4160
4490 void test_nonVoidReturnForOperator_void() { 4161 void test_nonVoidReturnForOperator_void() {
4491 Source source = addSource(r''' 4162 Source source = addSource(r'''
4492 class A { 4163 class A {
4493 void operator []=(a, b) {} 4164 void operator []=(a, b) {}
4494 }'''); 4165 }''');
4495 computeLibrarySourceErrors(source);
4496 assertNoErrors(source); 4166 assertNoErrors(source);
4497 verify([source]); 4167 verify([source]);
4498 } 4168 }
4499 4169
4500 void test_nonVoidReturnForSetter_function_no() { 4170 void test_nonVoidReturnForSetter_function_no() {
4501 Source source = addSource("set x(v) {}"); 4171 Source source = addSource("set x(v) {}");
4502 computeLibrarySourceErrors(source);
4503 assertNoErrors(source); 4172 assertNoErrors(source);
4504 verify([source]); 4173 verify([source]);
4505 } 4174 }
4506 4175
4507 void test_nonVoidReturnForSetter_function_void() { 4176 void test_nonVoidReturnForSetter_function_void() {
4508 Source source = addSource("void set x(v) {}"); 4177 Source source = addSource("void set x(v) {}");
4509 computeLibrarySourceErrors(source);
4510 assertNoErrors(source); 4178 assertNoErrors(source);
4511 verify([source]); 4179 verify([source]);
4512 } 4180 }
4513 4181
4514 void test_nonVoidReturnForSetter_method_no() { 4182 void test_nonVoidReturnForSetter_method_no() {
4515 Source source = addSource(r''' 4183 Source source = addSource(r'''
4516 class A { 4184 class A {
4517 set x(v) {} 4185 set x(v) {}
4518 }'''); 4186 }''');
4519 computeLibrarySourceErrors(source);
4520 assertNoErrors(source); 4187 assertNoErrors(source);
4521 verify([source]); 4188 verify([source]);
4522 } 4189 }
4523 4190
4524 void test_nonVoidReturnForSetter_method_void() { 4191 void test_nonVoidReturnForSetter_method_void() {
4525 Source source = addSource(r''' 4192 Source source = addSource(r'''
4526 class A { 4193 class A {
4527 void set x(v) {} 4194 void set x(v) {}
4528 }'''); 4195 }''');
4529 computeLibrarySourceErrors(source);
4530 assertNoErrors(source); 4196 assertNoErrors(source);
4531 verify([source]); 4197 verify([source]);
4532 } 4198 }
4533 4199
4534 void test_null_callMethod() { 4200 void test_null_callMethod() {
4535 Source source = addSource(r''' 4201 Source source = addSource(r'''
4536 main() { 4202 main() {
4537 null.m(); 4203 null.m();
4538 }'''); 4204 }''');
4539 computeLibrarySourceErrors(source);
4540 assertNoErrors(source); 4205 assertNoErrors(source);
4541 } 4206 }
4542 4207
4543 void test_null_callOperator() { 4208 void test_null_callOperator() {
4544 Source source = addSource(r''' 4209 Source source = addSource(r'''
4545 main() { 4210 main() {
4546 null + 5; 4211 null + 5;
4547 null == 5; 4212 null == 5;
4548 null[0]; 4213 null[0];
4549 }'''); 4214 }''');
4550 computeLibrarySourceErrors(source);
4551 assertNoErrors(source); 4215 assertNoErrors(source);
4552 } 4216 }
4553 4217
4554 void test_optionalParameterInOperator_required() { 4218 void test_optionalParameterInOperator_required() {
4555 Source source = addSource(r''' 4219 Source source = addSource(r'''
4556 class A { 4220 class A {
4557 operator +(p) {} 4221 operator +(p) {}
4558 }'''); 4222 }''');
4559 computeLibrarySourceErrors(source);
4560 assertNoErrors(source); 4223 assertNoErrors(source);
4561 verify([source]); 4224 verify([source]);
4562 } 4225 }
4563 4226
4564 void test_parameterDefaultDoesNotReferToParameterName() { 4227 void test_parameterDefaultDoesNotReferToParameterName() {
4565 // The final "f" should refer to the toplevel function "f", not to the 4228 // The final "f" should refer to the toplevel function "f", not to the
4566 // parameter called "f". See dartbug.com/13179. 4229 // parameter called "f". See dartbug.com/13179.
4567 Source source = addSource('void f([void f([x]) = f]) {}'); 4230 Source source = addSource('void f([void f([x]) = f]) {}');
4568 computeLibrarySourceErrors(source);
4569 assertNoErrors(source); 4231 assertNoErrors(source);
4570 verify([source]); 4232 verify([source]);
4571 } 4233 }
4572 4234
4573 void test_parameterScope_local() { 4235 void test_parameterScope_local() {
4574 // Parameter names shouldn't conflict with the name of the function they 4236 // Parameter names shouldn't conflict with the name of the function they
4575 // are enclosed in. 4237 // are enclosed in.
4576 Source source = addSource(r''' 4238 Source source = addSource(r'''
4577 f() { 4239 f() {
4578 g(g) { 4240 g(g) {
4579 h(g); 4241 h(g);
4580 } 4242 }
4581 } 4243 }
4582 h(x) {} 4244 h(x) {}
4583 '''); 4245 ''');
4584 computeLibrarySourceErrors(source);
4585 assertNoErrors(source); 4246 assertNoErrors(source);
4586 verify([source]); 4247 verify([source]);
4587 } 4248 }
4588 4249
4589 void test_parameterScope_method() { 4250 void test_parameterScope_method() {
4590 // Parameter names shouldn't conflict with the name of the function they 4251 // Parameter names shouldn't conflict with the name of the function they
4591 // are enclosed in. 4252 // are enclosed in.
4592 Source source = addSource(r''' 4253 Source source = addSource(r'''
4593 class C { 4254 class C {
4594 g(g) { 4255 g(g) {
4595 h(g); 4256 h(g);
4596 } 4257 }
4597 } 4258 }
4598 h(x) {} 4259 h(x) {}
4599 '''); 4260 ''');
4600 computeLibrarySourceErrors(source);
4601 assertNoErrors(source); 4261 assertNoErrors(source);
4602 verify([source]); 4262 verify([source]);
4603 } 4263 }
4604 4264
4605 void test_parameterScope_toplevel() { 4265 void test_parameterScope_toplevel() {
4606 // Parameter names shouldn't conflict with the name of the function they 4266 // Parameter names shouldn't conflict with the name of the function they
4607 // are enclosed in. 4267 // are enclosed in.
4608 Source source = addSource(r''' 4268 Source source = addSource(r'''
4609 g(g) { 4269 g(g) {
4610 h(g); 4270 h(g);
4611 } 4271 }
4612 h(x) {} 4272 h(x) {}
4613 '''); 4273 ''');
4614 computeLibrarySourceErrors(source);
4615 assertNoErrors(source); 4274 assertNoErrors(source);
4616 verify([source]); 4275 verify([source]);
4617 } 4276 }
4618 4277
4619 void test_prefixCollidesWithTopLevelMembers() { 4278 void test_prefixCollidesWithTopLevelMembers() {
4620 addNamedSource( 4279 addNamedSource(
4621 "/lib.dart", 4280 "/lib.dart",
4622 r''' 4281 r'''
4623 library lib; 4282 library lib;
4624 class A {}'''); 4283 class A {}''');
4625 Source source = addSource(r''' 4284 Source source = addSource(r'''
4626 import 'lib.dart' as p; 4285 import 'lib.dart' as p;
4627 typedef P(); 4286 typedef P();
4628 p2() {} 4287 p2() {}
4629 var p3; 4288 var p3;
4630 class p4 {} 4289 class p4 {}
4631 p.A a;'''); 4290 p.A a;''');
4632 computeLibrarySourceErrors(source);
4633 assertNoErrors(source); 4291 assertNoErrors(source);
4634 verify([source]); 4292 verify([source]);
4635 } 4293 }
4636 4294
4637 void test_propagateTypeArgs_intoBounds() { 4295 void test_propagateTypeArgs_intoBounds() {
4638 Source source = addSource(r''' 4296 Source source = addSource(r'''
4639 abstract class A<E> {} 4297 abstract class A<E> {}
4640 abstract class B<F> implements A<F>{} 4298 abstract class B<F> implements A<F>{}
4641 abstract class C<G, H extends A<G>> {} 4299 abstract class C<G, H extends A<G>> {}
4642 class D<I> extends C<I, B<I>> {}'''); 4300 class D<I> extends C<I, B<I>> {}''');
4643 computeLibrarySourceErrors(source);
4644 assertNoErrors(source); 4301 assertNoErrors(source);
4645 verify([source]); 4302 verify([source]);
4646 } 4303 }
4647 4304
4648 void test_propagateTypeArgs_intoSupertype() { 4305 void test_propagateTypeArgs_intoSupertype() {
4649 Source source = addSource(r''' 4306 Source source = addSource(r'''
4650 class A<T> { 4307 class A<T> {
4651 A(T p); 4308 A(T p);
4652 A.named(T p); 4309 A.named(T p);
4653 } 4310 }
4654 class B<S> extends A<S> { 4311 class B<S> extends A<S> {
4655 B(S p) : super(p); 4312 B(S p) : super(p);
4656 B.named(S p) : super.named(p); 4313 B.named(S p) : super.named(p);
4657 }'''); 4314 }''');
4658 computeLibrarySourceErrors(source);
4659 assertNoErrors(source); 4315 assertNoErrors(source);
4660 verify([source]); 4316 verify([source]);
4661 } 4317 }
4662 4318
4663 void test_proxy_annotation_prefixed() { 4319 void test_proxy_annotation_prefixed() {
4664 Source source = addSource(r''' 4320 Source source = addSource(r'''
4665 library L; 4321 library L;
4666 @proxy 4322 @proxy
4667 class A {} 4323 class A {}
4668 f(A a) { 4324 f(A a) {
4669 a.m(); 4325 a.m();
4670 var x = a.g; 4326 var x = a.g;
4671 a.s = 1; 4327 a.s = 1;
4672 var y = a + a; 4328 var y = a + a;
4673 a++; 4329 a++;
4674 ++a; 4330 ++a;
4675 }'''); 4331 }''');
4676 computeLibrarySourceErrors(source);
4677 assertNoErrors(source); 4332 assertNoErrors(source);
4678 } 4333 }
4679 4334
4680 void test_proxy_annotation_prefixed2() { 4335 void test_proxy_annotation_prefixed2() {
4681 Source source = addSource(r''' 4336 Source source = addSource(r'''
4682 library L; 4337 library L;
4683 @proxy 4338 @proxy
4684 class A {} 4339 class A {}
4685 class B { 4340 class B {
4686 f(A a) { 4341 f(A a) {
4687 a.m(); 4342 a.m();
4688 var x = a.g; 4343 var x = a.g;
4689 a.s = 1; 4344 a.s = 1;
4690 var y = a + a; 4345 var y = a + a;
4691 a++; 4346 a++;
4692 ++a; 4347 ++a;
4693 } 4348 }
4694 }'''); 4349 }''');
4695 computeLibrarySourceErrors(source);
4696 assertNoErrors(source); 4350 assertNoErrors(source);
4697 } 4351 }
4698 4352
4699 void test_proxy_annotation_prefixed3() { 4353 void test_proxy_annotation_prefixed3() {
4700 Source source = addSource(r''' 4354 Source source = addSource(r'''
4701 library L; 4355 library L;
4702 class B { 4356 class B {
4703 f(A a) { 4357 f(A a) {
4704 a.m(); 4358 a.m();
4705 var x = a.g; 4359 var x = a.g;
4706 a.s = 1; 4360 a.s = 1;
4707 var y = a + a; 4361 var y = a + a;
4708 a++; 4362 a++;
4709 ++a; 4363 ++a;
4710 } 4364 }
4711 } 4365 }
4712 @proxy 4366 @proxy
4713 class A {}'''); 4367 class A {}''');
4714 computeLibrarySourceErrors(source);
4715 assertNoErrors(source); 4368 assertNoErrors(source);
4716 } 4369 }
4717 4370
4718 void test_proxy_annotation_proxyHasPrefixedIdentifier() { 4371 void test_proxy_annotation_proxyHasPrefixedIdentifier() {
4719 Source source = addSource(r''' 4372 Source source = addSource(r'''
4720 library L; 4373 library L;
4721 import 'dart:core' as core; 4374 import 'dart:core' as core;
4722 @core.proxy class PrefixProxy {} 4375 @core.proxy class PrefixProxy {}
4723 main() { 4376 main() {
4724 new PrefixProxy().foo; 4377 new PrefixProxy().foo;
4725 new PrefixProxy().foo(); 4378 new PrefixProxy().foo();
4726 }'''); 4379 }''');
4727 computeLibrarySourceErrors(source);
4728 assertNoErrors(source); 4380 assertNoErrors(source);
4729 } 4381 }
4730 4382
4731 void test_proxy_annotation_simple() { 4383 void test_proxy_annotation_simple() {
4732 Source source = addSource(r''' 4384 Source source = addSource(r'''
4733 library L; 4385 library L;
4734 @proxy 4386 @proxy
4735 class B { 4387 class B {
4736 m() { 4388 m() {
4737 n(); 4389 n();
4738 var x = g; 4390 var x = g;
4739 s = 1; 4391 s = 1;
4740 var y = this + this; 4392 var y = this + this;
4741 } 4393 }
4742 }'''); 4394 }''');
4743 computeLibrarySourceErrors(source);
4744 assertNoErrors(source); 4395 assertNoErrors(source);
4745 } 4396 }
4746 4397
4747 void test_proxy_annotation_superclass() { 4398 void test_proxy_annotation_superclass() {
4748 Source source = addSource(r''' 4399 Source source = addSource(r'''
4749 library L; 4400 library L;
4750 class B extends A { 4401 class B extends A {
4751 m() { 4402 m() {
4752 n(); 4403 n();
4753 var x = g; 4404 var x = g;
4754 s = 1; 4405 s = 1;
4755 var y = this + this; 4406 var y = this + this;
4756 } 4407 }
4757 } 4408 }
4758 @proxy 4409 @proxy
4759 class A {}'''); 4410 class A {}''');
4760 computeLibrarySourceErrors(source);
4761 assertNoErrors(source); 4411 assertNoErrors(source);
4762 } 4412 }
4763 4413
4764 void test_proxy_annotation_superclass_mixin() { 4414 void test_proxy_annotation_superclass_mixin() {
4765 Source source = addSource(r''' 4415 Source source = addSource(r'''
4766 library L; 4416 library L;
4767 class B extends Object with A { 4417 class B extends Object with A {
4768 m() { 4418 m() {
4769 n(); 4419 n();
4770 var x = g; 4420 var x = g;
4771 s = 1; 4421 s = 1;
4772 var y = this + this; 4422 var y = this + this;
4773 } 4423 }
4774 } 4424 }
4775 @proxy 4425 @proxy
4776 class A {}'''); 4426 class A {}''');
4777 computeLibrarySourceErrors(source);
4778 assertNoErrors(source); 4427 assertNoErrors(source);
4779 } 4428 }
4780 4429
4781 void test_proxy_annotation_superinterface() { 4430 void test_proxy_annotation_superinterface() {
4782 Source source = addSource(r''' 4431 Source source = addSource(r'''
4783 library L; 4432 library L;
4784 class B implements A { 4433 class B implements A {
4785 m() { 4434 m() {
4786 n(); 4435 n();
4787 var x = g; 4436 var x = g;
4788 s = 1; 4437 s = 1;
4789 var y = this + this; 4438 var y = this + this;
4790 } 4439 }
4791 } 4440 }
4792 @proxy 4441 @proxy
4793 class A {}'''); 4442 class A {}''');
4794 computeLibrarySourceErrors(source);
4795 assertNoErrors(source); 4443 assertNoErrors(source);
4796 } 4444 }
4797 4445
4798 void test_proxy_annotation_superinterface_infiniteLoop() { 4446 void test_proxy_annotation_superinterface_infiniteLoop() {
4799 Source source = addSource(r''' 4447 addSource(r'''
4800 library L; 4448 library L;
4801 class C implements A { 4449 class C implements A {
4802 m() { 4450 m() {
4803 n(); 4451 n();
4804 var x = g; 4452 var x = g;
4805 s = 1; 4453 s = 1;
4806 var y = this + this; 4454 var y = this + this;
4807 } 4455 }
4808 } 4456 }
4809 class B implements A{} 4457 class B implements A{}
4810 class A implements B{}'''); 4458 class A implements B{}''');
4811 computeLibrarySourceErrors(source);
4812 // Test is that a stack overflow isn't reached in resolution 4459 // Test is that a stack overflow isn't reached in resolution
4813 // (previous line), no need to assert error set. 4460 // (previous line), no need to assert error set.
4814 } 4461 }
4815 4462
4816 void test_recursiveConstructorRedirect() { 4463 void test_recursiveConstructorRedirect() {
4817 Source source = addSource(r''' 4464 Source source = addSource(r'''
4818 class A { 4465 class A {
4819 A.a() : this.b(); 4466 A.a() : this.b();
4820 A.b() : this.c(); 4467 A.b() : this.c();
4821 A.c() {} 4468 A.c() {}
4822 }'''); 4469 }''');
4823 computeLibrarySourceErrors(source);
4824 assertNoErrors(source); 4470 assertNoErrors(source);
4825 verify([source]); 4471 verify([source]);
4826 } 4472 }
4827 4473
4828 void test_recursiveFactoryRedirect() { 4474 void test_recursiveFactoryRedirect() {
4829 Source source = addSource(r''' 4475 Source source = addSource(r'''
4830 class A { 4476 class A {
4831 factory A() = B; 4477 factory A() = B;
4832 } 4478 }
4833 class B implements A { 4479 class B implements A {
4834 factory B() = C; 4480 factory B() = C;
4835 } 4481 }
4836 class C implements B { 4482 class C implements B {
4837 factory C() => null; 4483 factory C() => null;
4838 }'''); 4484 }''');
4839 computeLibrarySourceErrors(source);
4840 assertNoErrors(source); 4485 assertNoErrors(source);
4841 verify([source]); 4486 verify([source]);
4842 } 4487 }
4843 4488
4844 void test_redirectToInvalidFunctionType() { 4489 void test_redirectToInvalidFunctionType() {
4845 Source source = addSource(r''' 4490 Source source = addSource(r'''
4846 class A implements B { 4491 class A implements B {
4847 A(int p) {} 4492 A(int p) {}
4848 } 4493 }
4849 class B { 4494 class B {
4850 factory B(int p) = A; 4495 factory B(int p) = A;
4851 }'''); 4496 }''');
4852 computeLibrarySourceErrors(source);
4853 assertNoErrors(source); 4497 assertNoErrors(source);
4854 verify([source]); 4498 verify([source]);
4855 } 4499 }
4856 4500
4857 void test_redirectToInvalidReturnType() { 4501 void test_redirectToInvalidReturnType() {
4858 Source source = addSource(r''' 4502 Source source = addSource(r'''
4859 class A { 4503 class A {
4860 A() {} 4504 A() {}
4861 } 4505 }
4862 class B extends A { 4506 class B extends A {
4863 factory B() = A; 4507 factory B() = A;
4864 }'''); 4508 }''');
4865 computeLibrarySourceErrors(source);
4866 assertNoErrors(source); 4509 assertNoErrors(source);
4867 verify([source]); 4510 verify([source]);
4868 } 4511 }
4869 4512
4870 void test_redirectToNonConstConstructor() { 4513 void test_redirectToNonConstConstructor() {
4871 Source source = addSource(r''' 4514 Source source = addSource(r'''
4872 class A { 4515 class A {
4873 const A.a(); 4516 const A.a();
4874 const factory A.b() = A.a; 4517 const factory A.b() = A.a;
4875 }'''); 4518 }''');
4876 computeLibrarySourceErrors(source);
4877 assertNoErrors(source); 4519 assertNoErrors(source);
4878 verify([source]); 4520 verify([source]);
4879 } 4521 }
4880 4522
4881 void test_referencedBeforeDeclaration_cascade() { 4523 void test_referencedBeforeDeclaration_cascade() {
4882 Source source = addSource(r''' 4524 Source source = addSource(r'''
4883 testRequestHandler() {} 4525 testRequestHandler() {}
4884 4526
4885 main() { 4527 main() {
4886 var s1 = null; 4528 var s1 = null;
4887 testRequestHandler() 4529 testRequestHandler()
4888 ..stream(s1); 4530 ..stream(s1);
4889 var stream = 123; 4531 var stream = 123;
4890 print(stream); 4532 print(stream);
4891 }'''); 4533 }''');
4892 computeLibrarySourceErrors(source);
4893 assertNoErrors(source); 4534 assertNoErrors(source);
4894 verify([source]); 4535 verify([source]);
4895 } 4536 }
4896 4537
4897 void test_referenceToDeclaredVariableInInitializer_constructorName() { 4538 void test_referenceToDeclaredVariableInInitializer_constructorName() {
4898 Source source = addSource(r''' 4539 Source source = addSource(r'''
4899 class A { 4540 class A {
4900 A.x() {} 4541 A.x() {}
4901 } 4542 }
4902 f() { 4543 f() {
4903 var x = new A.x(); 4544 var x = new A.x();
4904 }'''); 4545 }''');
4905 computeLibrarySourceErrors(source);
4906 assertNoErrors(source); 4546 assertNoErrors(source);
4907 verify([source]); 4547 verify([source]);
4908 } 4548 }
4909 4549
4910 void test_referenceToDeclaredVariableInInitializer_methodName() { 4550 void test_referenceToDeclaredVariableInInitializer_methodName() {
4911 Source source = addSource(r''' 4551 Source source = addSource(r'''
4912 class A { 4552 class A {
4913 x() {} 4553 x() {}
4914 } 4554 }
4915 f(A a) { 4555 f(A a) {
4916 var x = a.x(); 4556 var x = a.x();
4917 }'''); 4557 }''');
4918 computeLibrarySourceErrors(source);
4919 assertNoErrors(source); 4558 assertNoErrors(source);
4920 verify([source]); 4559 verify([source]);
4921 } 4560 }
4922 4561
4923 void test_referenceToDeclaredVariableInInitializer_propertyName() { 4562 void test_referenceToDeclaredVariableInInitializer_propertyName() {
4924 Source source = addSource(r''' 4563 Source source = addSource(r'''
4925 class A { 4564 class A {
4926 var x; 4565 var x;
4927 } 4566 }
4928 f(A a) { 4567 f(A a) {
4929 var x = a.x; 4568 var x = a.x;
4930 }'''); 4569 }''');
4931 computeLibrarySourceErrors(source);
4932 assertNoErrors(source); 4570 assertNoErrors(source);
4933 verify([source]); 4571 verify([source]);
4934 } 4572 }
4935 4573
4936 void test_rethrowOutsideCatch() { 4574 void test_rethrowOutsideCatch() {
4937 Source source = addSource(r''' 4575 Source source = addSource(r'''
4938 class A { 4576 class A {
4939 void m() { 4577 void m() {
4940 try {} catch (e) {rethrow;} 4578 try {} catch (e) {rethrow;}
4941 } 4579 }
4942 }'''); 4580 }''');
4943 computeLibrarySourceErrors(source);
4944 assertNoErrors(source); 4581 assertNoErrors(source);
4945 verify([source]); 4582 verify([source]);
4946 } 4583 }
4947 4584
4948 void test_return_in_generator_async() { 4585 void test_return_in_generator_async() {
4949 Source source = addSource(''' 4586 Source source = addSource('''
4950 import 'dart:async'; 4587 import 'dart:async';
4951 Stream<int> f() async* { 4588 Stream<int> f() async* {
4952 return; 4589 return;
4953 } 4590 }
4954 '''); 4591 ''');
4955 computeLibrarySourceErrors(source);
4956 assertNoErrors(source); 4592 assertNoErrors(source);
4957 verify([source]); 4593 verify([source]);
4958 } 4594 }
4959 4595
4960 void test_return_in_generator_sync() { 4596 void test_return_in_generator_sync() {
4961 Source source = addSource(''' 4597 Source source = addSource('''
4962 Iterable<int> f() sync* { 4598 Iterable<int> f() sync* {
4963 return; 4599 return;
4964 } 4600 }
4965 '''); 4601 ''');
4966 computeLibrarySourceErrors(source);
4967 assertNoErrors(source); 4602 assertNoErrors(source);
4968 verify([source]); 4603 verify([source]);
4969 } 4604 }
4970 4605
4971 void test_returnInGenerativeConstructor() { 4606 void test_returnInGenerativeConstructor() {
4972 Source source = addSource(r''' 4607 Source source = addSource(r'''
4973 class A { 4608 class A {
4974 A() { return; } 4609 A() { return; }
4975 }'''); 4610 }''');
4976 computeLibrarySourceErrors(source);
4977 assertNoErrors(source); 4611 assertNoErrors(source);
4978 verify([source]); 4612 verify([source]);
4979 } 4613 }
4980 4614
4981 void test_returnInGenerator_async() { 4615 void test_returnInGenerator_async() {
4982 Source source = addSource(r''' 4616 Source source = addSource(r'''
4983 f() async { 4617 f() async {
4984 return 0; 4618 return 0;
4985 }'''); 4619 }''');
4986 computeLibrarySourceErrors(source);
4987 assertNoErrors(source); 4620 assertNoErrors(source);
4988 verify([source]); 4621 verify([source]);
4989 } 4622 }
4990 4623
4991 void test_returnInGenerator_sync() { 4624 void test_returnInGenerator_sync() {
4992 Source source = addSource(r''' 4625 Source source = addSource(r'''
4993 f() { 4626 f() {
4994 return 0; 4627 return 0;
4995 }'''); 4628 }''');
4996 computeLibrarySourceErrors(source);
4997 assertNoErrors(source); 4629 assertNoErrors(source);
4998 verify([source]); 4630 verify([source]);
4999 } 4631 }
5000 4632
5001 void test_returnOfInvalidType_async() { 4633 void test_returnOfInvalidType_async() {
5002 Source source = addSource(r''' 4634 Source source = addSource(r'''
5003 import 'dart:async'; 4635 import 'dart:async';
5004 class A { 4636 class A {
5005 Future<int> m() async { 4637 Future<int> m() async {
5006 return 0; 4638 return 0;
5007 } 4639 }
5008 }'''); 4640 }''');
5009 computeLibrarySourceErrors(source);
5010 assertNoErrors(source); 4641 assertNoErrors(source);
5011 verify([source]); 4642 verify([source]);
5012 } 4643 }
5013 4644
5014 void test_returnOfInvalidType_dynamic() { 4645 void test_returnOfInvalidType_dynamic() {
5015 Source source = addSource(r''' 4646 Source source = addSource(r'''
5016 class TypeError {} 4647 class TypeError {}
5017 class A { 4648 class A {
5018 static void testLogicalOp() { 4649 static void testLogicalOp() {
5019 testOr(a, b, onTypeError) { 4650 testOr(a, b, onTypeError) {
5020 try { 4651 try {
5021 return a || b; 4652 return a || b;
5022 } on TypeError catch (t) { 4653 } on TypeError catch (t) {
5023 return onTypeError; 4654 return onTypeError;
5024 } 4655 }
5025 } 4656 }
5026 } 4657 }
5027 }'''); 4658 }''');
5028 computeLibrarySourceErrors(source);
5029 assertNoErrors(source); 4659 assertNoErrors(source);
5030 verify([source]); 4660 verify([source]);
5031 } 4661 }
5032 4662
5033 void test_returnOfInvalidType_dynamicAsTypeArgument() { 4663 void test_returnOfInvalidType_dynamicAsTypeArgument() {
5034 Source source = addSource(r''' 4664 Source source = addSource(r'''
5035 class I<T> { 4665 class I<T> {
5036 factory I() => new A<T>(); 4666 factory I() => new A<T>();
5037 } 4667 }
5038 class A<T> implements I { 4668 class A<T> implements I {
5039 }'''); 4669 }''');
5040 computeLibrarySourceErrors(source);
5041 assertNoErrors(source); 4670 assertNoErrors(source);
5042 verify([source]); 4671 verify([source]);
5043 } 4672 }
5044 4673
5045 void test_returnOfInvalidType_subtype() { 4674 void test_returnOfInvalidType_subtype() {
5046 Source source = addSource(r''' 4675 Source source = addSource(r'''
5047 class A {} 4676 class A {}
5048 class B extends A {} 4677 class B extends A {}
5049 A f(B b) { return b; }'''); 4678 A f(B b) { return b; }''');
5050 computeLibrarySourceErrors(source);
5051 assertNoErrors(source); 4679 assertNoErrors(source);
5052 verify([source]); 4680 verify([source]);
5053 } 4681 }
5054 4682
5055 void test_returnOfInvalidType_supertype() { 4683 void test_returnOfInvalidType_supertype() {
5056 Source source = addSource(r''' 4684 Source source = addSource(r'''
5057 class A {} 4685 class A {}
5058 class B extends A {} 4686 class B extends A {}
5059 B f(A a) { return a; }'''); 4687 B f(A a) { return a; }''');
5060 computeLibrarySourceErrors(source);
5061 assertNoErrors(source); 4688 assertNoErrors(source);
5062 verify([source]); 4689 verify([source]);
5063 } 4690 }
5064 4691
5065 void test_returnOfInvalidType_typeParameter_18468() { 4692 void test_returnOfInvalidType_typeParameter_18468() {
5066 // https://code.google.com/p/dart/issues/detail?id=18468 4693 // https://code.google.com/p/dart/issues/detail?id=18468
5067 // 4694 //
5068 // This test verifies that the type of T is more specific than Type, 4695 // This test verifies that the type of T is more specific than Type,
5069 // where T is a type parameter and Type is the type Type from 4696 // where T is a type parameter and Type is the type Type from
5070 // core, this particular test case comes from issue 18468. 4697 // core, this particular test case comes from issue 18468.
5071 // 4698 //
5072 // A test cannot be added to TypeParameterTypeImplTest since the types 4699 // A test cannot be added to TypeParameterTypeImplTest since the types
5073 // returned out of the TestTypeProvider don't have a mock 'dart.core' 4700 // returned out of the TestTypeProvider don't have a mock 'dart.core'
5074 // enclosing library element. 4701 // enclosing library element.
5075 // See TypeParameterTypeImpl.isMoreSpecificThan(). 4702 // See TypeParameterTypeImpl.isMoreSpecificThan().
5076 Source source = addSource(r''' 4703 Source source = addSource(r'''
5077 class Foo<T> { 4704 class Foo<T> {
5078 Type get t => T; 4705 Type get t => T;
5079 }'''); 4706 }''');
5080 computeLibrarySourceErrors(source);
5081 assertErrors(source); 4707 assertErrors(source);
5082 verify([source]); 4708 verify([source]);
5083 } 4709 }
5084 4710
5085 void test_returnOfInvalidType_void() { 4711 void test_returnOfInvalidType_void() {
5086 Source source = addSource(r''' 4712 Source source = addSource(r'''
5087 void f1() {} 4713 void f1() {}
5088 void f2() { return; } 4714 void f2() { return; }
5089 void f3() { return null; } 4715 void f3() { return null; }
5090 void f4() { return g1(); } 4716 void f4() { return g1(); }
5091 void f5() { return g2(); } 4717 void f5() { return g2(); }
5092 g1() {} 4718 g1() {}
5093 void g2() {} 4719 void g2() {}
5094 '''); 4720 ''');
5095 computeLibrarySourceErrors(source);
5096 assertNoErrors(source); 4721 assertNoErrors(source);
5097 verify([source]); 4722 verify([source]);
5098 } 4723 }
5099 4724
5100 void test_returnWithoutValue_noReturnType() { 4725 void test_returnWithoutValue_noReturnType() {
5101 Source source = addSource("f() { return; }"); 4726 Source source = addSource("f() { return; }");
5102 computeLibrarySourceErrors(source);
5103 assertNoErrors(source); 4727 assertNoErrors(source);
5104 verify([source]); 4728 verify([source]);
5105 } 4729 }
5106 4730
5107 void test_returnWithoutValue_void() { 4731 void test_returnWithoutValue_void() {
5108 Source source = addSource("void f() { return; }"); 4732 Source source = addSource("void f() { return; }");
5109 computeLibrarySourceErrors(source);
5110 assertNoErrors(source); 4733 assertNoErrors(source);
5111 verify([source]); 4734 verify([source]);
5112 } 4735 }
5113 4736
5114 void test_reversedTypeArguments() { 4737 void test_reversedTypeArguments() {
5115 Source source = addSource(r''' 4738 Source source = addSource(r'''
5116 class Codec<S1, T1> { 4739 class Codec<S1, T1> {
5117 Codec<T1, S1> get inverted => new _InvertedCodec<T1, S1>(this); 4740 Codec<T1, S1> get inverted => new _InvertedCodec<T1, S1>(this);
5118 } 4741 }
5119 class _InvertedCodec<T2, S2> extends Codec<T2, S2> { 4742 class _InvertedCodec<T2, S2> extends Codec<T2, S2> {
5120 _InvertedCodec(Codec<S2, T2> codec); 4743 _InvertedCodec(Codec<S2, T2> codec);
5121 }'''); 4744 }''');
5122 computeLibrarySourceErrors(source);
5123 assertNoErrors(source); 4745 assertNoErrors(source);
5124 verify([source]); 4746 verify([source]);
5125 } 4747 }
5126 4748
5127 void test_sharedDeferredPrefix() { 4749 void test_sharedDeferredPrefix() {
5128 resolveWithErrors(<String>[ 4750 resolveWithErrors(<String>[
5129 r''' 4751 r'''
5130 library lib1; 4752 library lib1;
5131 f1() {}''', 4753 f1() {}''',
5132 r''' 4754 r'''
(...skipping 12 matching lines...) Expand all
5145 } 4767 }
5146 4768
5147 void test_staticAccessToInstanceMember_annotation() { 4769 void test_staticAccessToInstanceMember_annotation() {
5148 Source source = addSource(r''' 4770 Source source = addSource(r'''
5149 class A { 4771 class A {
5150 const A.name(); 4772 const A.name();
5151 } 4773 }
5152 @A.name() 4774 @A.name()
5153 main() { 4775 main() {
5154 }'''); 4776 }''');
5155 computeLibrarySourceErrors(source);
5156 assertNoErrors(source); 4777 assertNoErrors(source);
5157 verify([source]); 4778 verify([source]);
5158 } 4779 }
5159 4780
5160 void test_staticAccessToInstanceMember_method() { 4781 void test_staticAccessToInstanceMember_method() {
5161 Source source = addSource(r''' 4782 Source source = addSource(r'''
5162 class A { 4783 class A {
5163 static m() {} 4784 static m() {}
5164 } 4785 }
5165 main() { 4786 main() {
5166 A.m; 4787 A.m;
5167 A.m(); 4788 A.m();
5168 }'''); 4789 }''');
5169 computeLibrarySourceErrors(source);
5170 assertNoErrors(source); 4790 assertNoErrors(source);
5171 verify([source]); 4791 verify([source]);
5172 } 4792 }
5173 4793
5174 void test_staticAccessToInstanceMember_propertyAccess_field() { 4794 void test_staticAccessToInstanceMember_propertyAccess_field() {
5175 Source source = addSource(r''' 4795 Source source = addSource(r'''
5176 class A { 4796 class A {
5177 static var f; 4797 static var f;
5178 } 4798 }
5179 main() { 4799 main() {
5180 A.f; 4800 A.f;
5181 A.f = 1; 4801 A.f = 1;
5182 }'''); 4802 }''');
5183 computeLibrarySourceErrors(source);
5184 assertNoErrors(source); 4803 assertNoErrors(source);
5185 verify([source]); 4804 verify([source]);
5186 } 4805 }
5187 4806
5188 void test_staticAccessToInstanceMember_propertyAccess_propertyAccessor() { 4807 void test_staticAccessToInstanceMember_propertyAccess_propertyAccessor() {
5189 Source source = addSource(r''' 4808 Source source = addSource(r'''
5190 class A { 4809 class A {
5191 static get f => 42; 4810 static get f => 42;
5192 static set f(x) {} 4811 static set f(x) {}
5193 } 4812 }
5194 main() { 4813 main() {
5195 A.f; 4814 A.f;
5196 A.f = 1; 4815 A.f = 1;
5197 }'''); 4816 }''');
5198 computeLibrarySourceErrors(source);
5199 assertNoErrors(source); 4817 assertNoErrors(source);
5200 verify([source]); 4818 verify([source]);
5201 } 4819 }
5202 4820
5203 void test_superInInvalidContext() { 4821 void test_superInInvalidContext() {
5204 Source source = addSource(r''' 4822 Source source = addSource(r'''
5205 class A { 4823 class A {
5206 m() {} 4824 m() {}
5207 } 4825 }
5208 class B extends A { 4826 class B extends A {
5209 B() { 4827 B() {
5210 var v = super.m(); 4828 var v = super.m();
5211 } 4829 }
5212 n() { 4830 n() {
5213 var v = super.m(); 4831 var v = super.m();
5214 } 4832 }
5215 }'''); 4833 }''');
5216 computeLibrarySourceErrors(source);
5217 assertNoErrors(source); 4834 assertNoErrors(source);
5218 verify([source]); 4835 verify([source]);
5219 } 4836 }
5220 4837
5221 void test_typeAliasCannotReferenceItself_returnClass_withTypeAlias() { 4838 void test_typeAliasCannotReferenceItself_returnClass_withTypeAlias() {
5222 Source source = addSource(r''' 4839 Source source = addSource(r'''
5223 typedef B A(); 4840 typedef B A();
5224 class B { 4841 class B {
5225 A a; 4842 A a;
5226 }'''); 4843 }''');
5227 computeLibrarySourceErrors(source);
5228 assertNoErrors(source); 4844 assertNoErrors(source);
5229 verify([source]); 4845 verify([source]);
5230 } 4846 }
5231 4847
5232 void test_typeArgumentNotMatchingBounds_const() { 4848 void test_typeArgumentNotMatchingBounds_const() {
5233 Source source = addSource(r''' 4849 Source source = addSource(r'''
5234 class A {} 4850 class A {}
5235 class B extends A {} 4851 class B extends A {}
5236 class G<E extends A> { 4852 class G<E extends A> {
5237 const G(); 4853 const G();
5238 } 4854 }
5239 f() { return const G<B>(); }'''); 4855 f() { return const G<B>(); }''');
5240 computeLibrarySourceErrors(source);
5241 assertNoErrors(source); 4856 assertNoErrors(source);
5242 verify([source]); 4857 verify([source]);
5243 } 4858 }
5244 4859
5245 void test_typeArgumentNotMatchingBounds_new() { 4860 void test_typeArgumentNotMatchingBounds_new() {
5246 Source source = addSource(r''' 4861 Source source = addSource(r'''
5247 class A {} 4862 class A {}
5248 class B extends A {} 4863 class B extends A {}
5249 class G<E extends A> {} 4864 class G<E extends A> {}
5250 f() { return new G<B>(); }'''); 4865 f() { return new G<B>(); }''');
5251 computeLibrarySourceErrors(source);
5252 assertNoErrors(source); 4866 assertNoErrors(source);
5253 verify([source]); 4867 verify([source]);
5254 } 4868 }
5255 4869
5256 void test_typeArgumentNotMatchingBounds_ofFunctionTypeAlias_hasBound() { 4870 void test_typeArgumentNotMatchingBounds_ofFunctionTypeAlias_hasBound() {
5257 Source source = addSource(r''' 4871 Source source = addSource(r'''
5258 class A {} 4872 class A {}
5259 class B extends A {} 4873 class B extends A {}
5260 typedef F<T extends A>(); 4874 typedef F<T extends A>();
5261 F<A> fa; 4875 F<A> fa;
5262 F<B> fb; 4876 F<B> fb;
5263 '''); 4877 ''');
5264 computeLibrarySourceErrors(source);
5265 assertNoErrors(source); 4878 assertNoErrors(source);
5266 verify([source]); 4879 verify([source]);
5267 } 4880 }
5268 4881
5269 void test_typeArgumentNotMatchingBounds_ofFunctionTypeAlias_hasBound2() { 4882 void test_typeArgumentNotMatchingBounds_ofFunctionTypeAlias_hasBound2() {
5270 Source source = addSource(r''' 4883 Source source = addSource(r'''
5271 class MyClass<T> {} 4884 class MyClass<T> {}
5272 typedef MyFunction<T, P extends MyClass<T>>(); 4885 typedef MyFunction<T, P extends MyClass<T>>();
5273 class A<T, P extends MyClass<T>> { 4886 class A<T, P extends MyClass<T>> {
5274 MyFunction<T, P> f; 4887 MyFunction<T, P> f;
5275 } 4888 }
5276 '''); 4889 ''');
5277 computeLibrarySourceErrors(source);
5278 assertNoErrors(source); 4890 assertNoErrors(source);
5279 verify([source]); 4891 verify([source]);
5280 } 4892 }
5281 4893
5282 void test_typeArgumentNotMatchingBounds_ofFunctionTypeAlias_noBound() { 4894 void test_typeArgumentNotMatchingBounds_ofFunctionTypeAlias_noBound() {
5283 Source source = addSource(r''' 4895 Source source = addSource(r'''
5284 typedef F<T>(); 4896 typedef F<T>();
5285 F<int> f1; 4897 F<int> f1;
5286 F<String> f2; 4898 F<String> f2;
5287 '''); 4899 ''');
5288 computeLibrarySourceErrors(source);
5289 assertNoErrors(source); 4900 assertNoErrors(source);
5290 verify([source]); 4901 verify([source]);
5291 } 4902 }
5292 4903
5293 void test_typeArgumentNotMatchingBounds_typeArgumentList_0() { 4904 void test_typeArgumentNotMatchingBounds_typeArgumentList_0() {
5294 Source source = addSource("abstract class A<T extends A>{}"); 4905 Source source = addSource("abstract class A<T extends A>{}");
5295 computeLibrarySourceErrors(source);
5296 assertNoErrors(source); 4906 assertNoErrors(source);
5297 verify([source]); 4907 verify([source]);
5298 } 4908 }
5299 4909
5300 void test_typeArgumentNotMatchingBounds_typeArgumentList_1() { 4910 void test_typeArgumentNotMatchingBounds_typeArgumentList_1() {
5301 Source source = addSource("abstract class A<T extends A<A>>{}"); 4911 Source source = addSource("abstract class A<T extends A<A>>{}");
5302 computeLibrarySourceErrors(source);
5303 assertNoErrors(source); 4912 assertNoErrors(source);
5304 verify([source]); 4913 verify([source]);
5305 } 4914 }
5306 4915
5307 void test_typeArgumentNotMatchingBounds_typeArgumentList_20() { 4916 void test_typeArgumentNotMatchingBounds_typeArgumentList_20() {
5308 Source source = addSource( 4917 Source source = addSource(
5309 "abstract class A<T extends A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A>>> >>>>>>>>>>>>>>>>>>{}"); 4918 "abstract class A<T extends A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A>>> >>>>>>>>>>>>>>>>>>{}");
5310 computeLibrarySourceErrors(source);
5311 assertNoErrors(source); 4919 assertNoErrors(source);
5312 verify([source]); 4920 verify([source]);
5313 } 4921 }
5314 4922
5315 void test_typePromotion_booleanAnd_useInRight() { 4923 void test_typePromotion_booleanAnd_useInRight() {
5316 Source source = addSource(r''' 4924 Source source = addSource(r'''
5317 main(Object p) { 4925 main(Object p) {
5318 p is String && p.length != 0; 4926 p is String && p.length != 0;
5319 }'''); 4927 }''');
5320 computeLibrarySourceErrors(source);
5321 assertNoErrors(source); 4928 assertNoErrors(source);
5322 verify([source]); 4929 verify([source]);
5323 } 4930 }
5324 4931
5325 void 4932 void
5326 test_typePromotion_booleanAnd_useInRight_accessedInClosureRight_noAssignme nt() { 4933 test_typePromotion_booleanAnd_useInRight_accessedInClosureRight_noAssignme nt() {
5327 Source source = addSource(r''' 4934 Source source = addSource(r'''
5328 callMe(f()) { f(); } 4935 callMe(f()) { f(); }
5329 main(Object p) { 4936 main(Object p) {
5330 (p is String) && callMe(() { p.length; }); 4937 (p is String) && callMe(() { p.length; });
5331 }'''); 4938 }''');
5332 computeLibrarySourceErrors(source);
5333 assertNoErrors(source); 4939 assertNoErrors(source);
5334 verify([source]); 4940 verify([source]);
5335 } 4941 }
5336 4942
5337 void test_typePromotion_conditional_issue14655() { 4943 void test_typePromotion_conditional_issue14655() {
5338 Source source = addSource(r''' 4944 Source source = addSource(r'''
5339 class A {} 4945 class A {}
5340 class B extends A {} 4946 class B extends A {}
5341 class C extends B { 4947 class C extends B {
5342 mc() {} 4948 mc() {}
5343 } 4949 }
5344 print(_) {} 4950 print(_) {}
5345 main(A p) { 4951 main(A p) {
5346 (p is C) && (print(() => p) && (p is B)) ? p.mc() : p = null; 4952 (p is C) && (print(() => p) && (p is B)) ? p.mc() : p = null;
5347 }'''); 4953 }''');
5348 computeLibrarySourceErrors(source);
5349 assertNoErrors(source); 4954 assertNoErrors(source);
5350 verify([source]); 4955 verify([source]);
5351 } 4956 }
5352 4957
5353 void test_typePromotion_conditional_useInThen() { 4958 void test_typePromotion_conditional_useInThen() {
5354 Source source = addSource(r''' 4959 Source source = addSource(r'''
5355 main(Object p) { 4960 main(Object p) {
5356 p is String ? p.length : 0; 4961 p is String ? p.length : 0;
5357 }'''); 4962 }''');
5358 computeLibrarySourceErrors(source);
5359 assertNoErrors(source); 4963 assertNoErrors(source);
5360 verify([source]); 4964 verify([source]);
5361 } 4965 }
5362 4966
5363 void 4967 void
5364 test_typePromotion_conditional_useInThen_accessedInClosure_noAssignment() { 4968 test_typePromotion_conditional_useInThen_accessedInClosure_noAssignment() {
5365 Source source = addSource(r''' 4969 Source source = addSource(r'''
5366 callMe(f()) { f(); } 4970 callMe(f()) { f(); }
5367 main(Object p) { 4971 main(Object p) {
5368 p is String ? callMe(() { p.length; }) : 0; 4972 p is String ? callMe(() { p.length; }) : 0;
5369 }'''); 4973 }''');
5370 computeLibrarySourceErrors(source);
5371 assertNoErrors(source); 4974 assertNoErrors(source);
5372 verify([source]); 4975 verify([source]);
5373 } 4976 }
5374 4977
5375 void test_typePromotion_functionType_arg_ignoreIfNotMoreSpecific() { 4978 void test_typePromotion_functionType_arg_ignoreIfNotMoreSpecific() {
5376 Source source = addSource(r''' 4979 Source source = addSource(r'''
5377 typedef FuncB(B b); 4980 typedef FuncB(B b);
5378 typedef FuncA(A a); 4981 typedef FuncA(A a);
5379 class A {} 4982 class A {}
5380 class B {} 4983 class B {}
5381 main(FuncA f) { 4984 main(FuncA f) {
5382 if (f is FuncB) { 4985 if (f is FuncB) {
5383 f(new A()); 4986 f(new A());
5384 } 4987 }
5385 }'''); 4988 }''');
5386 computeLibrarySourceErrors(source);
5387 assertNoErrors(source); 4989 assertNoErrors(source);
5388 verify([source]); 4990 verify([source]);
5389 } 4991 }
5390 4992
5391 void test_typePromotion_functionType_return_ignoreIfNotMoreSpecific() { 4993 void test_typePromotion_functionType_return_ignoreIfNotMoreSpecific() {
5392 Source source = addSource(r''' 4994 Source source = addSource(r'''
5393 class A {} 4995 class A {}
5394 typedef FuncAtoDyn(A a); 4996 typedef FuncAtoDyn(A a);
5395 typedef FuncDynToDyn(x); 4997 typedef FuncDynToDyn(x);
5396 main(FuncAtoDyn f) { 4998 main(FuncAtoDyn f) {
5397 if (f is FuncDynToDyn) { 4999 if (f is FuncDynToDyn) {
5398 A a = f(new A()); 5000 A a = f(new A());
5399 } 5001 }
5400 }'''); 5002 }''');
5401 computeLibrarySourceErrors(source);
5402 assertNoErrors(source); 5003 assertNoErrors(source);
5403 verify([source]); 5004 verify([source]);
5404 } 5005 }
5405 5006
5406 void test_typePromotion_functionType_return_voidToDynamic() { 5007 void test_typePromotion_functionType_return_voidToDynamic() {
5407 Source source = addSource(r''' 5008 Source source = addSource(r'''
5408 typedef FuncDynToDyn(x); 5009 typedef FuncDynToDyn(x);
5409 typedef void FuncDynToVoid(x); 5010 typedef void FuncDynToVoid(x);
5410 class A {} 5011 class A {}
5411 main(FuncDynToVoid f) { 5012 main(FuncDynToVoid f) {
5412 if (f is FuncDynToDyn) { 5013 if (f is FuncDynToDyn) {
5413 A a = f(null); 5014 A a = f(null);
5414 } 5015 }
5415 }'''); 5016 }''');
5416 computeLibrarySourceErrors(source);
5417 assertNoErrors(source); 5017 assertNoErrors(source);
5418 verify([source]); 5018 verify([source]);
5419 } 5019 }
5420 5020
5421 void test_typePromotion_if_accessedInClosure_noAssignment() { 5021 void test_typePromotion_if_accessedInClosure_noAssignment() {
5422 Source source = addSource(r''' 5022 Source source = addSource(r'''
5423 callMe(f()) { f(); } 5023 callMe(f()) { f(); }
5424 main(Object p) { 5024 main(Object p) {
5425 if (p is String) { 5025 if (p is String) {
5426 callMe(() { 5026 callMe(() {
5427 p.length; 5027 p.length;
5428 }); 5028 });
5429 } 5029 }
5430 }'''); 5030 }''');
5431 computeLibrarySourceErrors(source);
5432 assertNoErrors(source); 5031 assertNoErrors(source);
5433 verify([source]); 5032 verify([source]);
5434 } 5033 }
5435 5034
5436 void test_typePromotion_if_extends_moreSpecific() { 5035 void test_typePromotion_if_extends_moreSpecific() {
5437 Source source = addSource(r''' 5036 Source source = addSource(r'''
5438 class V {} 5037 class V {}
5439 class VP extends V {} 5038 class VP extends V {}
5440 class A<T> {} 5039 class A<T> {}
5441 class B<S> extends A<S> { 5040 class B<S> extends A<S> {
5442 var b; 5041 var b;
5443 } 5042 }
5444 5043
5445 main(A<V> p) { 5044 main(A<V> p) {
5446 if (p is B<VP>) { 5045 if (p is B<VP>) {
5447 p.b; 5046 p.b;
5448 } 5047 }
5449 }'''); 5048 }''');
5450 computeLibrarySourceErrors(source);
5451 assertNoErrors(source); 5049 assertNoErrors(source);
5452 verify([source]); 5050 verify([source]);
5453 } 5051 }
5454 5052
5455 void test_typePromotion_if_hasAssignment_outsideAfter() { 5053 void test_typePromotion_if_hasAssignment_outsideAfter() {
5456 Source source = addSource(r''' 5054 Source source = addSource(r'''
5457 main(Object p) { 5055 main(Object p) {
5458 if (p is String) { 5056 if (p is String) {
5459 p.length; 5057 p.length;
5460 } 5058 }
5461 p = 0; 5059 p = 0;
5462 }'''); 5060 }''');
5463 computeLibrarySourceErrors(source);
5464 assertNoErrors(source); 5061 assertNoErrors(source);
5465 verify([source]); 5062 verify([source]);
5466 } 5063 }
5467 5064
5468 void test_typePromotion_if_hasAssignment_outsideBefore() { 5065 void test_typePromotion_if_hasAssignment_outsideBefore() {
5469 Source source = addSource(r''' 5066 Source source = addSource(r'''
5470 main(Object p, Object p2) { 5067 main(Object p, Object p2) {
5471 p = p2; 5068 p = p2;
5472 if (p is String) { 5069 if (p is String) {
5473 p.length; 5070 p.length;
5474 } 5071 }
5475 }'''); 5072 }''');
5476 computeLibrarySourceErrors(source);
5477 assertNoErrors(source); 5073 assertNoErrors(source);
5478 verify([source]); 5074 verify([source]);
5479 } 5075 }
5480 5076
5481 void test_typePromotion_if_implements_moreSpecific() { 5077 void test_typePromotion_if_implements_moreSpecific() {
5482 Source source = addSource(r''' 5078 Source source = addSource(r'''
5483 class V {} 5079 class V {}
5484 class VP extends V {} 5080 class VP extends V {}
5485 class A<T> {} 5081 class A<T> {}
5486 class B<S> implements A<S> { 5082 class B<S> implements A<S> {
5487 var b; 5083 var b;
5488 } 5084 }
5489 5085
5490 main(A<V> p) { 5086 main(A<V> p) {
5491 if (p is B<VP>) { 5087 if (p is B<VP>) {
5492 p.b; 5088 p.b;
5493 } 5089 }
5494 }'''); 5090 }''');
5495 computeLibrarySourceErrors(source);
5496 assertNoErrors(source); 5091 assertNoErrors(source);
5497 verify([source]); 5092 verify([source]);
5498 } 5093 }
5499 5094
5500 void test_typePromotion_if_inClosure_assignedAfter_inSameFunction() { 5095 void test_typePromotion_if_inClosure_assignedAfter_inSameFunction() {
5501 Source source = addSource(r''' 5096 Source source = addSource(r'''
5502 main() { 5097 main() {
5503 f(Object p) { 5098 f(Object p) {
5504 if (p is String) { 5099 if (p is String) {
5505 p.length; 5100 p.length;
5506 } 5101 }
5507 p = 0; 5102 p = 0;
5508 }; 5103 };
5509 }'''); 5104 }''');
5510 computeLibrarySourceErrors(source);
5511 assertNoErrors(source); 5105 assertNoErrors(source);
5512 verify([source]); 5106 verify([source]);
5513 } 5107 }
5514 5108
5515 void test_typePromotion_if_is_and_left() { 5109 void test_typePromotion_if_is_and_left() {
5516 Source source = addSource(r''' 5110 Source source = addSource(r'''
5517 bool tt() => true; 5111 bool tt() => true;
5518 main(Object p) { 5112 main(Object p) {
5519 if (p is String && tt()) { 5113 if (p is String && tt()) {
5520 p.length; 5114 p.length;
5521 } 5115 }
5522 }'''); 5116 }''');
5523 computeLibrarySourceErrors(source);
5524 assertNoErrors(source); 5117 assertNoErrors(source);
5525 verify([source]); 5118 verify([source]);
5526 } 5119 }
5527 5120
5528 void test_typePromotion_if_is_and_right() { 5121 void test_typePromotion_if_is_and_right() {
5529 Source source = addSource(r''' 5122 Source source = addSource(r'''
5530 bool tt() => true; 5123 bool tt() => true;
5531 main(Object p) { 5124 main(Object p) {
5532 if (tt() && p is String) { 5125 if (tt() && p is String) {
5533 p.length; 5126 p.length;
5534 } 5127 }
5535 }'''); 5128 }''');
5536 computeLibrarySourceErrors(source);
5537 assertNoErrors(source); 5129 assertNoErrors(source);
5538 verify([source]); 5130 verify([source]);
5539 } 5131 }
5540 5132
5541 void test_typePromotion_if_is_and_subThenSuper() { 5133 void test_typePromotion_if_is_and_subThenSuper() {
5542 Source source = addSource(r''' 5134 Source source = addSource(r'''
5543 class A { 5135 class A {
5544 var a; 5136 var a;
5545 } 5137 }
5546 class B extends A { 5138 class B extends A {
5547 var b; 5139 var b;
5548 } 5140 }
5549 main(Object p) { 5141 main(Object p) {
5550 if (p is B && p is A) { 5142 if (p is B && p is A) {
5551 p.a; 5143 p.a;
5552 p.b; 5144 p.b;
5553 } 5145 }
5554 }'''); 5146 }''');
5555 computeLibrarySourceErrors(source);
5556 assertNoErrors(source); 5147 assertNoErrors(source);
5557 verify([source]); 5148 verify([source]);
5558 } 5149 }
5559 5150
5560 void test_typePromotion_if_is_parenthesized() { 5151 void test_typePromotion_if_is_parenthesized() {
5561 Source source = addSource(r''' 5152 Source source = addSource(r'''
5562 main(Object p) { 5153 main(Object p) {
5563 if ((p is String)) { 5154 if ((p is String)) {
5564 p.length; 5155 p.length;
5565 } 5156 }
5566 }'''); 5157 }''');
5567 computeLibrarySourceErrors(source);
5568 assertNoErrors(source); 5158 assertNoErrors(source);
5569 verify([source]); 5159 verify([source]);
5570 } 5160 }
5571 5161
5572 void test_typePromotion_if_is_single() { 5162 void test_typePromotion_if_is_single() {
5573 Source source = addSource(r''' 5163 Source source = addSource(r'''
5574 main(Object p) { 5164 main(Object p) {
5575 if (p is String) { 5165 if (p is String) {
5576 p.length; 5166 p.length;
5577 } 5167 }
5578 }'''); 5168 }''');
5579 computeLibrarySourceErrors(source);
5580 assertNoErrors(source); 5169 assertNoErrors(source);
5581 verify([source]); 5170 verify([source]);
5582 } 5171 }
5583 5172
5584 void test_typePromotion_parentheses() { 5173 void test_typePromotion_parentheses() {
5585 Source source = addSource(r''' 5174 Source source = addSource(r'''
5586 main(Object p) { 5175 main(Object p) {
5587 (p is String) ? p.length : 0; 5176 (p is String) ? p.length : 0;
5588 (p) is String ? p.length : 0; 5177 (p) is String ? p.length : 0;
5589 ((p)) is String ? p.length : 0; 5178 ((p)) is String ? p.length : 0;
5590 ((p) is String) ? p.length : 0; 5179 ((p) is String) ? p.length : 0;
5591 }'''); 5180 }''');
5592 computeLibrarySourceErrors(source);
5593 assertNoErrors(source); 5181 assertNoErrors(source);
5594 verify([source]); 5182 verify([source]);
5595 } 5183 }
5596 5184
5597 void test_typeType_class() { 5185 void test_typeType_class() {
5598 Source source = addSource(r''' 5186 Source source = addSource(r'''
5599 class C {} 5187 class C {}
5600 f(Type t) {} 5188 f(Type t) {}
5601 main() { 5189 main() {
5602 f(C); 5190 f(C);
5603 }'''); 5191 }''');
5604 computeLibrarySourceErrors(source);
5605 assertNoErrors(source); 5192 assertNoErrors(source);
5606 verify([source]); 5193 verify([source]);
5607 } 5194 }
5608 5195
5609 void test_typeType_class_prefixed() { 5196 void test_typeType_class_prefixed() {
5610 addNamedSource( 5197 addNamedSource(
5611 "/lib.dart", 5198 "/lib.dart",
5612 r''' 5199 r'''
5613 library lib; 5200 library lib;
5614 class C {}'''); 5201 class C {}''');
5615 Source source = addSource(r''' 5202 Source source = addSource(r'''
5616 import 'lib.dart' as p; 5203 import 'lib.dart' as p;
5617 f(Type t) {} 5204 f(Type t) {}
5618 main() { 5205 main() {
5619 f(p.C); 5206 f(p.C);
5620 }'''); 5207 }''');
5621 computeLibrarySourceErrors(source);
5622 assertNoErrors(source); 5208 assertNoErrors(source);
5623 verify([source]); 5209 verify([source]);
5624 } 5210 }
5625 5211
5626 void test_typeType_functionTypeAlias() { 5212 void test_typeType_functionTypeAlias() {
5627 Source source = addSource(r''' 5213 Source source = addSource(r'''
5628 typedef F(); 5214 typedef F();
5629 f(Type t) {} 5215 f(Type t) {}
5630 main() { 5216 main() {
5631 f(F); 5217 f(F);
5632 }'''); 5218 }''');
5633 computeLibrarySourceErrors(source);
5634 assertNoErrors(source); 5219 assertNoErrors(source);
5635 verify([source]); 5220 verify([source]);
5636 } 5221 }
5637 5222
5638 void test_typeType_functionTypeAlias_prefixed() { 5223 void test_typeType_functionTypeAlias_prefixed() {
5639 addNamedSource( 5224 addNamedSource(
5640 "/lib.dart", 5225 "/lib.dart",
5641 r''' 5226 r'''
5642 library lib; 5227 library lib;
5643 typedef F();'''); 5228 typedef F();''');
5644 Source source = addSource(r''' 5229 Source source = addSource(r'''
5645 import 'lib.dart' as p; 5230 import 'lib.dart' as p;
5646 f(Type t) {} 5231 f(Type t) {}
5647 main() { 5232 main() {
5648 f(p.F); 5233 f(p.F);
5649 }'''); 5234 }''');
5650 computeLibrarySourceErrors(source);
5651 assertNoErrors(source); 5235 assertNoErrors(source);
5652 verify([source]); 5236 verify([source]);
5653 } 5237 }
5654 5238
5655 void test_undefinedConstructorInInitializer_explicit_named() { 5239 void test_undefinedConstructorInInitializer_explicit_named() {
5656 Source source = addSource(r''' 5240 Source source = addSource(r'''
5657 class A { 5241 class A {
5658 A.named() {} 5242 A.named() {}
5659 } 5243 }
5660 class B extends A { 5244 class B extends A {
5661 B() : super.named(); 5245 B() : super.named();
5662 }'''); 5246 }''');
5663 computeLibrarySourceErrors(source);
5664 assertNoErrors(source); 5247 assertNoErrors(source);
5665 verify([source]); 5248 verify([source]);
5666 } 5249 }
5667 5250
5668 void test_undefinedConstructorInInitializer_explicit_unnamed() { 5251 void test_undefinedConstructorInInitializer_explicit_unnamed() {
5669 Source source = addSource(r''' 5252 Source source = addSource(r'''
5670 class A { 5253 class A {
5671 A() {} 5254 A() {}
5672 } 5255 }
5673 class B extends A { 5256 class B extends A {
5674 B() : super(); 5257 B() : super();
5675 }'''); 5258 }''');
5676 computeLibrarySourceErrors(source);
5677 assertNoErrors(source); 5259 assertNoErrors(source);
5678 verify([source]); 5260 verify([source]);
5679 } 5261 }
5680 5262
5681 void test_undefinedConstructorInInitializer_hasOptionalParameters() { 5263 void test_undefinedConstructorInInitializer_hasOptionalParameters() {
5682 Source source = addSource(r''' 5264 Source source = addSource(r'''
5683 class A { 5265 class A {
5684 A([p]) {} 5266 A([p]) {}
5685 } 5267 }
5686 class B extends A { 5268 class B extends A {
5687 B(); 5269 B();
5688 }'''); 5270 }''');
5689 computeLibrarySourceErrors(source);
5690 assertNoErrors(source); 5271 assertNoErrors(source);
5691 verify([source]); 5272 verify([source]);
5692 } 5273 }
5693 5274
5694 void test_undefinedConstructorInInitializer_implicit() { 5275 void test_undefinedConstructorInInitializer_implicit() {
5695 Source source = addSource(r''' 5276 Source source = addSource(r'''
5696 class A { 5277 class A {
5697 A() {} 5278 A() {}
5698 } 5279 }
5699 class B extends A { 5280 class B extends A {
5700 B(); 5281 B();
5701 }'''); 5282 }''');
5702 computeLibrarySourceErrors(source);
5703 assertNoErrors(source); 5283 assertNoErrors(source);
5704 verify([source]); 5284 verify([source]);
5705 } 5285 }
5706 5286
5707 void test_undefinedConstructorInInitializer_implicit_typeAlias() { 5287 void test_undefinedConstructorInInitializer_implicit_typeAlias() {
5708 Source source = addSource(r''' 5288 Source source = addSource(r'''
5709 class M {} 5289 class M {}
5710 class A = Object with M; 5290 class A = Object with M;
5711 class B extends A { 5291 class B extends A {
5712 B(); 5292 B();
5713 }'''); 5293 }''');
5714 computeLibrarySourceErrors(source);
5715 assertNoErrors(source); 5294 assertNoErrors(source);
5716 verify([source]); 5295 verify([source]);
5717 } 5296 }
5718 5297
5719 void test_undefinedConstructorInInitializer_redirecting() { 5298 void test_undefinedConstructorInInitializer_redirecting() {
5720 Source source = addSource(r''' 5299 Source source = addSource(r'''
5721 class Foo { 5300 class Foo {
5722 Foo.ctor(); 5301 Foo.ctor();
5723 } 5302 }
5724 class Bar extends Foo { 5303 class Bar extends Foo {
5725 Bar() : this.ctor(); 5304 Bar() : this.ctor();
5726 Bar.ctor() : super.ctor(); 5305 Bar.ctor() : super.ctor();
5727 }'''); 5306 }''');
5728 computeLibrarySourceErrors(source);
5729 assertNoErrors(source); 5307 assertNoErrors(source);
5730 verify([source]); 5308 verify([source]);
5731 } 5309 }
5732 5310
5733 void test_undefinedGetter_static_conditionalAccess() { 5311 void test_undefinedGetter_static_conditionalAccess() {
5734 // The conditional access operator '?.' can be used to access static 5312 // The conditional access operator '?.' can be used to access static
5735 // fields. 5313 // fields.
5736 Source source = addSource(''' 5314 Source source = addSource('''
5737 class A { 5315 class A {
5738 static var x; 5316 static var x;
5739 } 5317 }
5740 var a = A?.x; 5318 var a = A?.x;
5741 '''); 5319 ''');
5742 computeLibrarySourceErrors(source);
5743 assertNoErrors(source); 5320 assertNoErrors(source);
5744 verify([source]); 5321 verify([source]);
5745 } 5322 }
5746 5323
5747 void test_undefinedGetter_typeSubstitution() { 5324 void test_undefinedGetter_typeSubstitution() {
5748 Source source = addSource(r''' 5325 Source source = addSource(r'''
5749 class A<E> { 5326 class A<E> {
5750 E element; 5327 E element;
5751 } 5328 }
5752 class B extends A<List> { 5329 class B extends A<List> {
5753 m() { 5330 m() {
5754 element.last; 5331 element.last;
5755 } 5332 }
5756 }'''); 5333 }''');
5757 computeLibrarySourceErrors(source);
5758 assertNoErrors(source); 5334 assertNoErrors(source);
5759 verify([source]); 5335 verify([source]);
5760 } 5336 }
5761 5337
5762 void test_undefinedIdentifier_synthetic_whenExpression() { 5338 void test_undefinedIdentifier_synthetic_whenExpression() {
5763 Source source = addSource(r''' 5339 Source source = addSource(r'''
5764 print(x) {} 5340 print(x) {}
5765 main() { 5341 main() {
5766 print(is String); 5342 print(is String);
5767 }'''); 5343 }''');
5768 computeLibrarySourceErrors(source);
5769 assertErrors(source, [ParserErrorCode.MISSING_IDENTIFIER]); 5344 assertErrors(source, [ParserErrorCode.MISSING_IDENTIFIER]);
5770 } 5345 }
5771 5346
5772 void test_undefinedIdentifier_synthetic_whenMethodName() { 5347 void test_undefinedIdentifier_synthetic_whenMethodName() {
5773 Source source = addSource(r''' 5348 Source source = addSource(r'''
5774 print(x) {} 5349 print(x) {}
5775 main(int p) { 5350 main(int p) {
5776 p.(); 5351 p.();
5777 }'''); 5352 }''');
5778 computeLibrarySourceErrors(source);
5779 assertErrors(source, [ParserErrorCode.MISSING_IDENTIFIER]); 5353 assertErrors(source, [ParserErrorCode.MISSING_IDENTIFIER]);
5780 } 5354 }
5781 5355
5782 void test_undefinedMethod_functionExpression_callMethod() { 5356 void test_undefinedMethod_functionExpression_callMethod() {
5783 Source source = addSource(r''' 5357 Source source = addSource(r'''
5784 main() { 5358 main() {
5785 (() => null).call(); 5359 (() => null).call();
5786 }'''); 5360 }''');
5787 computeLibrarySourceErrors(source);
5788 assertNoErrors(source); 5361 assertNoErrors(source);
5789 // A call to verify(source) fails as '.call()' isn't resolved. 5362 // A call to verify(source) fails as '.call()' isn't resolved.
5790 } 5363 }
5791 5364
5792 void test_undefinedMethod_functionExpression_directCall() { 5365 void test_undefinedMethod_functionExpression_directCall() {
5793 Source source = addSource(r''' 5366 Source source = addSource(r'''
5794 main() { 5367 main() {
5795 (() => null)(); 5368 (() => null)();
5796 }'''); 5369 }''');
5797 computeLibrarySourceErrors(source);
5798 assertNoErrors(source); 5370 assertNoErrors(source);
5799 // A call to verify(source) fails as '(() => null)()' isn't resolved. 5371 // A call to verify(source) fails as '(() => null)()' isn't resolved.
5800 } 5372 }
5801 5373
5802 void test_undefinedMethod_static_conditionalAccess() { 5374 void test_undefinedMethod_static_conditionalAccess() {
5803 // The conditional access operator '?.' can be used to access static 5375 // The conditional access operator '?.' can be used to access static
5804 // methods. 5376 // methods.
5805 Source source = addSource(''' 5377 Source source = addSource('''
5806 class A { 5378 class A {
5807 static void m() {} 5379 static void m() {}
5808 } 5380 }
5809 f() { A?.m(); } 5381 f() { A?.m(); }
5810 '''); 5382 ''');
5811 computeLibrarySourceErrors(source);
5812 assertNoErrors(source); 5383 assertNoErrors(source);
5813 verify([source]); 5384 verify([source]);
5814 } 5385 }
5815 5386
5816 void test_undefinedOperator_index() { 5387 void test_undefinedOperator_index() {
5817 Source source = addSource(r''' 5388 Source source = addSource(r'''
5818 class A { 5389 class A {
5819 operator [](a) {} 5390 operator [](a) {}
5820 operator []=(a, b) {} 5391 operator []=(a, b) {}
5821 } 5392 }
5822 f(A a) { 5393 f(A a) {
5823 a[0]; 5394 a[0];
5824 a[0] = 1; 5395 a[0] = 1;
5825 }'''); 5396 }''');
5826 computeLibrarySourceErrors(source);
5827 assertNoErrors(source); 5397 assertNoErrors(source);
5828 verify([source]); 5398 verify([source]);
5829 } 5399 }
5830 5400
5831 void test_undefinedOperator_tilde() { 5401 void test_undefinedOperator_tilde() {
5832 Source source = addSource(r''' 5402 Source source = addSource(r'''
5833 const A = 3; 5403 const A = 3;
5834 const B = ~((1 << A) - 1);'''); 5404 const B = ~((1 << A) - 1);''');
5835 computeLibrarySourceErrors(source);
5836 assertNoErrors(source); 5405 assertNoErrors(source);
5837 verify([source]); 5406 verify([source]);
5838 } 5407 }
5839 5408
5840 void test_undefinedSetter_importWithPrefix() { 5409 void test_undefinedSetter_importWithPrefix() {
5841 addNamedSource( 5410 addNamedSource(
5842 "/lib.dart", 5411 "/lib.dart",
5843 r''' 5412 r'''
5844 library lib; 5413 library lib;
5845 set y(int value) {}'''); 5414 set y(int value) {}''');
5846 Source source = addSource(r''' 5415 Source source = addSource(r'''
5847 import 'lib.dart' as x; 5416 import 'lib.dart' as x;
5848 main() { 5417 main() {
5849 x.y = 0; 5418 x.y = 0;
5850 }'''); 5419 }''');
5851 computeLibrarySourceErrors(source);
5852 assertNoErrors(source); 5420 assertNoErrors(source);
5853 verify([source]); 5421 verify([source]);
5854 } 5422 }
5855 5423
5856 void test_undefinedSetter_static_conditionalAccess() { 5424 void test_undefinedSetter_static_conditionalAccess() {
5857 // The conditional access operator '?.' can be used to access static 5425 // The conditional access operator '?.' can be used to access static
5858 // fields. 5426 // fields.
5859 Source source = addSource(''' 5427 Source source = addSource('''
5860 class A { 5428 class A {
5861 static var x; 5429 static var x;
5862 } 5430 }
5863 f() { A?.x = 1; } 5431 f() { A?.x = 1; }
5864 '''); 5432 ''');
5865 computeLibrarySourceErrors(source);
5866 assertNoErrors(source); 5433 assertNoErrors(source);
5867 verify([source]); 5434 verify([source]);
5868 } 5435 }
5869 5436
5870 void test_undefinedSuperMethod_field() { 5437 void test_undefinedSuperMethod_field() {
5871 Source source = addSource(r''' 5438 Source source = addSource(r'''
5872 class A { 5439 class A {
5873 var m; 5440 var m;
5874 } 5441 }
5875 class B extends A { 5442 class B extends A {
5876 f() { 5443 f() {
5877 super.m(); 5444 super.m();
5878 } 5445 }
5879 }'''); 5446 }''');
5880 computeLibrarySourceErrors(source);
5881 assertNoErrors(source); 5447 assertNoErrors(source);
5882 verify([source]); 5448 verify([source]);
5883 } 5449 }
5884 5450
5885 void test_undefinedSuperMethod_method() { 5451 void test_undefinedSuperMethod_method() {
5886 Source source = addSource(r''' 5452 Source source = addSource(r'''
5887 class A { 5453 class A {
5888 m() {} 5454 m() {}
5889 } 5455 }
5890 class B extends A { 5456 class B extends A {
5891 f() { 5457 f() {
5892 super.m(); 5458 super.m();
5893 } 5459 }
5894 }'''); 5460 }''');
5895 computeLibrarySourceErrors(source);
5896 assertNoErrors(source); 5461 assertNoErrors(source);
5897 verify([source]); 5462 verify([source]);
5898 } 5463 }
5899 5464
5900 void test_unqualifiedReferenceToNonLocalStaticMember_fromComment_new() { 5465 void test_unqualifiedReferenceToNonLocalStaticMember_fromComment_new() {
5901 Source source = addSource(r''' 5466 Source source = addSource(r'''
5902 class A { 5467 class A {
5903 A() {} 5468 A() {}
5904 A.named() {} 5469 A.named() {}
5905 } 5470 }
5906 /// [new A] or [new A.named] 5471 /// [new A] or [new A.named]
5907 main() { 5472 main() {
5908 }'''); 5473 }''');
5909 computeLibrarySourceErrors(source);
5910 assertNoErrors(source); 5474 assertNoErrors(source);
5911 verify([source]); 5475 verify([source]);
5912 } 5476 }
5913 5477
5914 void test_unusedShownName_unresolved() { 5478 void test_unusedShownName_unresolved() {
5915 Source source = addSource(r''' 5479 Source source = addSource(r'''
5916 import 'dart:math' show max, FooBar; 5480 import 'dart:math' show max, FooBar;
5917 main() { 5481 main() {
5918 print(max(1, 2)); 5482 print(max(1, 2));
5919 } 5483 }
5920 '''); 5484 ''');
5921 computeLibrarySourceErrors(source);
5922 assertErrors(source, [HintCode.UNDEFINED_SHOWN_NAME]); 5485 assertErrors(source, [HintCode.UNDEFINED_SHOWN_NAME]);
5923 } 5486 }
5924 5487
5925 void test_uriDoesNotExist_dll() { 5488 void test_uriDoesNotExist_dll() {
5926 addNamedSource("/lib.dll", ""); 5489 addNamedSource("/lib.dll", "");
5927 Source source = addSource("import 'dart-ext:lib';"); 5490 Source source = addSource("import 'dart-ext:lib';");
5928 computeLibrarySourceErrors(source);
5929 assertNoErrors(source); 5491 assertNoErrors(source);
5930 } 5492 }
5931 5493
5932 void test_uriDoesNotExist_dylib() { 5494 void test_uriDoesNotExist_dylib() {
5933 addNamedSource("/lib.dylib", ""); 5495 addNamedSource("/lib.dylib", "");
5934 Source source = addSource("import 'dart-ext:lib';"); 5496 Source source = addSource("import 'dart-ext:lib';");
5935 computeLibrarySourceErrors(source);
5936 assertNoErrors(source); 5497 assertNoErrors(source);
5937 } 5498 }
5938 5499
5939 void test_uriDoesNotExist_so() { 5500 void test_uriDoesNotExist_so() {
5940 addNamedSource("/lib.so", ""); 5501 addNamedSource("/lib.so", "");
5941 Source source = addSource("import 'dart-ext:lib';"); 5502 Source source = addSource("import 'dart-ext:lib';");
5942 computeLibrarySourceErrors(source);
5943 assertNoErrors(source); 5503 assertNoErrors(source);
5944 } 5504 }
5945 5505
5946 void test_wrongNumberOfParametersForOperator1() { 5506 void test_wrongNumberOfParametersForOperator1() {
5947 _check_wrongNumberOfParametersForOperator1("<"); 5507 _check_wrongNumberOfParametersForOperator1("<");
5948 _check_wrongNumberOfParametersForOperator1(">"); 5508 _check_wrongNumberOfParametersForOperator1(">");
5949 _check_wrongNumberOfParametersForOperator1("<="); 5509 _check_wrongNumberOfParametersForOperator1("<=");
5950 _check_wrongNumberOfParametersForOperator1(">="); 5510 _check_wrongNumberOfParametersForOperator1(">=");
5951 _check_wrongNumberOfParametersForOperator1("+"); 5511 _check_wrongNumberOfParametersForOperator1("+");
5952 _check_wrongNumberOfParametersForOperator1("/"); 5512 _check_wrongNumberOfParametersForOperator1("/");
5953 _check_wrongNumberOfParametersForOperator1("~/"); 5513 _check_wrongNumberOfParametersForOperator1("~/");
5954 _check_wrongNumberOfParametersForOperator1("*"); 5514 _check_wrongNumberOfParametersForOperator1("*");
5955 _check_wrongNumberOfParametersForOperator1("%"); 5515 _check_wrongNumberOfParametersForOperator1("%");
5956 _check_wrongNumberOfParametersForOperator1("|"); 5516 _check_wrongNumberOfParametersForOperator1("|");
5957 _check_wrongNumberOfParametersForOperator1("^"); 5517 _check_wrongNumberOfParametersForOperator1("^");
5958 _check_wrongNumberOfParametersForOperator1("&"); 5518 _check_wrongNumberOfParametersForOperator1("&");
5959 _check_wrongNumberOfParametersForOperator1("<<"); 5519 _check_wrongNumberOfParametersForOperator1("<<");
5960 _check_wrongNumberOfParametersForOperator1(">>"); 5520 _check_wrongNumberOfParametersForOperator1(">>");
5961 _check_wrongNumberOfParametersForOperator1("[]"); 5521 _check_wrongNumberOfParametersForOperator1("[]");
5962 } 5522 }
5963 5523
5964 void test_wrongNumberOfParametersForOperator_index() { 5524 void test_wrongNumberOfParametersForOperator_index() {
5965 Source source = addSource(r''' 5525 Source source = addSource(r'''
5966 class A { 5526 class A {
5967 operator []=(a, b) {} 5527 operator []=(a, b) {}
5968 }'''); 5528 }''');
5969 computeLibrarySourceErrors(source);
5970 assertNoErrors(source); 5529 assertNoErrors(source);
5971 verify([source]); 5530 verify([source]);
5972 } 5531 }
5973 5532
5974 void test_wrongNumberOfParametersForOperator_minus() { 5533 void test_wrongNumberOfParametersForOperator_minus() {
5975 _check_wrongNumberOfParametersForOperator("-", ""); 5534 _check_wrongNumberOfParametersForOperator("-", "");
5976 _check_wrongNumberOfParametersForOperator("-", "a"); 5535 _check_wrongNumberOfParametersForOperator("-", "a");
5977 } 5536 }
5978 5537
5979 void test_wrongNumberOfParametersForSetter() { 5538 void test_wrongNumberOfParametersForSetter() {
5980 Source source = addSource(r''' 5539 Source source = addSource(r'''
5981 class A { 5540 class A {
5982 set x(a) {} 5541 set x(a) {}
5983 }'''); 5542 }''');
5984 computeLibrarySourceErrors(source);
5985 assertNoErrors(source); 5543 assertNoErrors(source);
5986 verify([source]); 5544 verify([source]);
5987 } 5545 }
5988 5546
5989 void test_yield_async_to_dynamic_type() { 5547 void test_yield_async_to_dynamic_type() {
5990 Source source = addSource(''' 5548 Source source = addSource('''
5991 dynamic f() async* { 5549 dynamic f() async* {
5992 yield 3; 5550 yield 3;
5993 } 5551 }
5994 '''); 5552 ''');
5995 computeLibrarySourceErrors(source);
5996 assertNoErrors(source); 5553 assertNoErrors(source);
5997 verify([source]); 5554 verify([source]);
5998 } 5555 }
5999 5556
6000 void test_yield_async_to_generic_type() { 5557 void test_yield_async_to_generic_type() {
6001 Source source = addSource(''' 5558 Source source = addSource('''
6002 import 'dart:async'; 5559 import 'dart:async';
6003 Stream f() async* { 5560 Stream f() async* {
6004 yield 3; 5561 yield 3;
6005 } 5562 }
6006 '''); 5563 ''');
6007 computeLibrarySourceErrors(source);
6008 assertNoErrors(source); 5564 assertNoErrors(source);
6009 verify([source]); 5565 verify([source]);
6010 } 5566 }
6011 5567
6012 void test_yield_async_to_parameterized_type() { 5568 void test_yield_async_to_parameterized_type() {
6013 Source source = addSource(''' 5569 Source source = addSource('''
6014 import 'dart:async'; 5570 import 'dart:async';
6015 Stream<int> f() async* { 5571 Stream<int> f() async* {
6016 yield 3; 5572 yield 3;
6017 } 5573 }
6018 '''); 5574 ''');
6019 computeLibrarySourceErrors(source);
6020 assertNoErrors(source); 5575 assertNoErrors(source);
6021 verify([source]); 5576 verify([source]);
6022 } 5577 }
6023 5578
6024 void test_yield_async_to_untyped() { 5579 void test_yield_async_to_untyped() {
6025 Source source = addSource(''' 5580 Source source = addSource('''
6026 f() async* { 5581 f() async* {
6027 yield 3; 5582 yield 3;
6028 } 5583 }
6029 '''); 5584 ''');
6030 computeLibrarySourceErrors(source);
6031 assertNoErrors(source); 5585 assertNoErrors(source);
6032 verify([source]); 5586 verify([source]);
6033 } 5587 }
6034 5588
6035 void test_yield_each_async_dynamic_to_dynamic() { 5589 void test_yield_each_async_dynamic_to_dynamic() {
6036 Source source = addSource(''' 5590 Source source = addSource('''
6037 f() async* { 5591 f() async* {
6038 yield* g(); 5592 yield* g();
6039 } 5593 }
6040 g() => null; 5594 g() => null;
6041 '''); 5595 ''');
6042 computeLibrarySourceErrors(source);
6043 assertNoErrors(source); 5596 assertNoErrors(source);
6044 verify([source]); 5597 verify([source]);
6045 } 5598 }
6046 5599
6047 void test_yield_each_async_dynamic_to_stream() { 5600 void test_yield_each_async_dynamic_to_stream() {
6048 Source source = addSource(''' 5601 Source source = addSource('''
6049 import 'dart:async'; 5602 import 'dart:async';
6050 Stream f() async* { 5603 Stream f() async* {
6051 yield* g(); 5604 yield* g();
6052 } 5605 }
6053 g() => null; 5606 g() => null;
6054 '''); 5607 ''');
6055 computeLibrarySourceErrors(source);
6056 assertNoErrors(source); 5608 assertNoErrors(source);
6057 verify([source]); 5609 verify([source]);
6058 } 5610 }
6059 5611
6060 void test_yield_each_async_dynamic_to_typed_stream() { 5612 void test_yield_each_async_dynamic_to_typed_stream() {
6061 Source source = addSource(''' 5613 Source source = addSource('''
6062 import 'dart:async'; 5614 import 'dart:async';
6063 Stream<int> f() async* { 5615 Stream<int> f() async* {
6064 yield* g(); 5616 yield* g();
6065 } 5617 }
6066 g() => null; 5618 g() => null;
6067 '''); 5619 ''');
6068 computeLibrarySourceErrors(source);
6069 assertNoErrors(source); 5620 assertNoErrors(source);
6070 verify([source]); 5621 verify([source]);
6071 } 5622 }
6072 5623
6073 void test_yield_each_async_stream_to_dynamic() { 5624 void test_yield_each_async_stream_to_dynamic() {
6074 Source source = addSource(''' 5625 Source source = addSource('''
6075 import 'dart:async'; 5626 import 'dart:async';
6076 f() async* { 5627 f() async* {
6077 yield* g(); 5628 yield* g();
6078 } 5629 }
6079 Stream g() => null; 5630 Stream g() => null;
6080 '''); 5631 ''');
6081 computeLibrarySourceErrors(source);
6082 assertNoErrors(source); 5632 assertNoErrors(source);
6083 verify([source]); 5633 verify([source]);
6084 } 5634 }
6085 5635
6086 void test_yield_each_async_typed_stream_to_dynamic() { 5636 void test_yield_each_async_typed_stream_to_dynamic() {
6087 Source source = addSource(''' 5637 Source source = addSource('''
6088 import 'dart:async'; 5638 import 'dart:async';
6089 f() async* { 5639 f() async* {
6090 yield* g(); 5640 yield* g();
6091 } 5641 }
6092 Stream<int> g() => null; 5642 Stream<int> g() => null;
6093 '''); 5643 ''');
6094 computeLibrarySourceErrors(source);
6095 assertNoErrors(source); 5644 assertNoErrors(source);
6096 verify([source]); 5645 verify([source]);
6097 } 5646 }
6098 5647
6099 void test_yield_each_async_typed_stream_to_typed_stream() { 5648 void test_yield_each_async_typed_stream_to_typed_stream() {
6100 Source source = addSource(''' 5649 Source source = addSource('''
6101 import 'dart:async'; 5650 import 'dart:async';
6102 Stream<int> f() async* { 5651 Stream<int> f() async* {
6103 yield* g(); 5652 yield* g();
6104 } 5653 }
6105 Stream<int> g() => null; 5654 Stream<int> g() => null;
6106 '''); 5655 ''');
6107 computeLibrarySourceErrors(source);
6108 assertNoErrors(source); 5656 assertNoErrors(source);
6109 verify([source]); 5657 verify([source]);
6110 } 5658 }
6111 5659
6112 void test_yield_each_sync_dynamic_to_dynamic() { 5660 void test_yield_each_sync_dynamic_to_dynamic() {
6113 Source source = addSource(''' 5661 Source source = addSource('''
6114 f() sync* { 5662 f() sync* {
6115 yield* g(); 5663 yield* g();
6116 } 5664 }
6117 g() => null; 5665 g() => null;
6118 '''); 5666 ''');
6119 computeLibrarySourceErrors(source);
6120 assertNoErrors(source); 5667 assertNoErrors(source);
6121 verify([source]); 5668 verify([source]);
6122 } 5669 }
6123 5670
6124 void test_yield_each_sync_dynamic_to_iterable() { 5671 void test_yield_each_sync_dynamic_to_iterable() {
6125 Source source = addSource(''' 5672 Source source = addSource('''
6126 Iterable f() sync* { 5673 Iterable f() sync* {
6127 yield* g(); 5674 yield* g();
6128 } 5675 }
6129 g() => null; 5676 g() => null;
6130 '''); 5677 ''');
6131 computeLibrarySourceErrors(source);
6132 assertNoErrors(source); 5678 assertNoErrors(source);
6133 verify([source]); 5679 verify([source]);
6134 } 5680 }
6135 5681
6136 void test_yield_each_sync_dynamic_to_typed_iterable() { 5682 void test_yield_each_sync_dynamic_to_typed_iterable() {
6137 Source source = addSource(''' 5683 Source source = addSource('''
6138 Iterable<int> f() sync* { 5684 Iterable<int> f() sync* {
6139 yield* g(); 5685 yield* g();
6140 } 5686 }
6141 g() => null; 5687 g() => null;
6142 '''); 5688 ''');
6143 computeLibrarySourceErrors(source);
6144 assertNoErrors(source); 5689 assertNoErrors(source);
6145 verify([source]); 5690 verify([source]);
6146 } 5691 }
6147 5692
6148 void test_yield_each_sync_iterable_to_dynamic() { 5693 void test_yield_each_sync_iterable_to_dynamic() {
6149 Source source = addSource(''' 5694 Source source = addSource('''
6150 f() sync* { 5695 f() sync* {
6151 yield* g(); 5696 yield* g();
6152 } 5697 }
6153 Iterable g() => null; 5698 Iterable g() => null;
6154 '''); 5699 ''');
6155 computeLibrarySourceErrors(source);
6156 assertNoErrors(source); 5700 assertNoErrors(source);
6157 verify([source]); 5701 verify([source]);
6158 } 5702 }
6159 5703
6160 void test_yield_each_sync_typed_iterable_to_dynamic() { 5704 void test_yield_each_sync_typed_iterable_to_dynamic() {
6161 Source source = addSource(''' 5705 Source source = addSource('''
6162 f() sync* { 5706 f() sync* {
6163 yield* g(); 5707 yield* g();
6164 } 5708 }
6165 Iterable<int> g() => null; 5709 Iterable<int> g() => null;
6166 '''); 5710 ''');
6167 computeLibrarySourceErrors(source);
6168 assertNoErrors(source); 5711 assertNoErrors(source);
6169 verify([source]); 5712 verify([source]);
6170 } 5713 }
6171 5714
6172 void test_yield_each_sync_typed_iterable_to_typed_iterable() { 5715 void test_yield_each_sync_typed_iterable_to_typed_iterable() {
6173 Source source = addSource(''' 5716 Source source = addSource('''
6174 Iterable<int> f() sync* { 5717 Iterable<int> f() sync* {
6175 yield* g(); 5718 yield* g();
6176 } 5719 }
6177 Iterable<int> g() => null; 5720 Iterable<int> g() => null;
6178 '''); 5721 ''');
6179 computeLibrarySourceErrors(source);
6180 assertNoErrors(source); 5722 assertNoErrors(source);
6181 verify([source]); 5723 verify([source]);
6182 } 5724 }
6183 5725
6184 void test_yield_sync_to_dynamic_type() { 5726 void test_yield_sync_to_dynamic_type() {
6185 Source source = addSource(''' 5727 Source source = addSource('''
6186 dynamic f() sync* { 5728 dynamic f() sync* {
6187 yield 3; 5729 yield 3;
6188 } 5730 }
6189 '''); 5731 ''');
6190 computeLibrarySourceErrors(source);
6191 assertNoErrors(source); 5732 assertNoErrors(source);
6192 verify([source]); 5733 verify([source]);
6193 } 5734 }
6194 5735
6195 void test_yield_sync_to_generic_type() { 5736 void test_yield_sync_to_generic_type() {
6196 Source source = addSource(''' 5737 Source source = addSource('''
6197 Iterable f() sync* { 5738 Iterable f() sync* {
6198 yield 3; 5739 yield 3;
6199 } 5740 }
6200 '''); 5741 ''');
6201 computeLibrarySourceErrors(source);
6202 assertNoErrors(source); 5742 assertNoErrors(source);
6203 verify([source]); 5743 verify([source]);
6204 } 5744 }
6205 5745
6206 void test_yield_sync_to_parameterized_type() { 5746 void test_yield_sync_to_parameterized_type() {
6207 Source source = addSource(''' 5747 Source source = addSource('''
6208 Iterable<int> f() sync* { 5748 Iterable<int> f() sync* {
6209 yield 3; 5749 yield 3;
6210 } 5750 }
6211 '''); 5751 ''');
6212 computeLibrarySourceErrors(source);
6213 assertNoErrors(source); 5752 assertNoErrors(source);
6214 verify([source]); 5753 verify([source]);
6215 } 5754 }
6216 5755
6217 void test_yield_sync_to_untyped() { 5756 void test_yield_sync_to_untyped() {
6218 Source source = addSource(''' 5757 Source source = addSource('''
6219 f() sync* { 5758 f() sync* {
6220 yield 3; 5759 yield 3;
6221 } 5760 }
6222 '''); 5761 ''');
6223 computeLibrarySourceErrors(source);
6224 assertNoErrors(source); 5762 assertNoErrors(source);
6225 verify([source]); 5763 verify([source]);
6226 } 5764 }
6227 5765
6228 void test_yieldInNonGenerator_asyncStar() { 5766 void test_yieldInNonGenerator_asyncStar() {
6229 Source source = addSource(r''' 5767 Source source = addSource(r'''
6230 f() async* { 5768 f() async* {
6231 yield 0; 5769 yield 0;
6232 }'''); 5770 }''');
6233 computeLibrarySourceErrors(source);
6234 assertNoErrors(source); 5771 assertNoErrors(source);
6235 verify([source]); 5772 verify([source]);
6236 } 5773 }
6237 5774
6238 void test_yieldInNonGenerator_syncStar() { 5775 void test_yieldInNonGenerator_syncStar() {
6239 Source source = addSource(r''' 5776 Source source = addSource(r'''
6240 f() sync* { 5777 f() sync* {
6241 yield 0; 5778 yield 0;
6242 }'''); 5779 }''');
6243 computeLibrarySourceErrors(source);
6244 assertNoErrors(source); 5780 assertNoErrors(source);
6245 verify([source]); 5781 verify([source]);
6246 } 5782 }
6247 5783
6248 void _check_wrongNumberOfParametersForOperator( 5784 void _check_wrongNumberOfParametersForOperator(
6249 String name, String parameters) { 5785 String name, String parameters) {
6250 Source source = addSource(""" 5786 Source source = addSource("""
6251 class A { 5787 class A {
6252 operator $name($parameters) {} 5788 operator $name($parameters) {}
6253 }"""); 5789 }""");
6254 computeLibrarySourceErrors(source);
6255 assertNoErrors(source); 5790 assertNoErrors(source);
6256 verify([source]); 5791 verify([source]);
6257 reset(); 5792 reset();
6258 } 5793 }
6259 5794
6260 void _check_wrongNumberOfParametersForOperator1(String name) { 5795 void _check_wrongNumberOfParametersForOperator1(String name) {
6261 _check_wrongNumberOfParametersForOperator(name, "a"); 5796 _check_wrongNumberOfParametersForOperator(name, "a");
6262 } 5797 }
6263 5798
6264 CompilationUnit _getResolvedLibraryUnit(Source source) => 5799 CompilationUnit _getResolvedLibraryUnit(Source source) =>
6265 analysisContext.getResolvedCompilationUnit2(source, source); 5800 analysisContext.getResolvedCompilationUnit2(source, source);
6266 } 5801 }
OLDNEW
« no previous file with comments | « pkg/analyzer/test/generated/hint_code_test.dart ('k') | pkg/analyzer/test/generated/non_hint_code_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698