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

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

Issue 656543003: Split up large resolver_test.dart file. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Update pkg.status file Created 6 years, 2 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 | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 library engine.non_error_resolver_test;
6
7 import 'package:analyzer/src/generated/source_io.dart';
8 import 'package:analyzer/src/generated/error.dart';
9 import 'package:analyzer/src/generated/ast.dart';
10 import 'package:analyzer/src/generated/parser.dart' show ParserErrorCode;
11 import 'package:analyzer/src/generated/element.dart';
12 import 'package:analyzer/src/generated/engine.dart';
13 import 'package:unittest/unittest.dart' as _ut;
14 import 'resolver_test.dart';
15 import 'test_support.dart';
16 import '../reflective_tests.dart';
17
18
19 class NonErrorResolverTest extends ResolverTestCase {
20 void fail_undefinedEnumConstant() {
21 Source source = addSource(EngineTestCase.createSource(["enum E { ONE }", "E e() {", " return E.ONE;", "}"]));
22 resolve(source);
23 assertNoErrors(source);
24 verify([source]);
25 }
26
27 void test_ambiguousExport() {
28 Source source = addSource(EngineTestCase.createSource([
29 "library L;",
30 "export 'lib1.dart';",
31 "export 'lib2.dart';"]));
32 addNamedSource("/lib1.dart", EngineTestCase.createSource(["library lib1;", " class M {}"]));
33 addNamedSource("/lib2.dart", EngineTestCase.createSource(["library lib2;", " class N {}"]));
34 resolve(source);
35 assertNoErrors(source);
36 verify([source]);
37 }
38
39 void test_ambiguousExport_combinators_hide() {
40 Source source = addSource(EngineTestCase.createSource([
41 "library L;",
42 "export 'lib1.dart';",
43 "export 'lib2.dart' hide B;"]));
44 addNamedSource("/lib1.dart", EngineTestCase.createSource(["library L1;", "cl ass A {}", "class B {}"]));
45 addNamedSource("/lib2.dart", EngineTestCase.createSource(["library L2;", "cl ass B {}", "class C {}"]));
46 resolve(source);
47 assertNoErrors(source);
48 verify([source]);
49 }
50
51 void test_ambiguousExport_combinators_show() {
52 Source source = addSource(EngineTestCase.createSource([
53 "library L;",
54 "export 'lib1.dart';",
55 "export 'lib2.dart' show C;"]));
56 addNamedSource("/lib1.dart", EngineTestCase.createSource(["library L1;", "cl ass A {}", "class B {}"]));
57 addNamedSource("/lib2.dart", EngineTestCase.createSource(["library L2;", "cl ass B {}", "class C {}"]));
58 resolve(source);
59 assertNoErrors(source);
60 verify([source]);
61 }
62
63 void test_ambiguousExport_sameDeclaration() {
64 Source source = addSource(EngineTestCase.createSource(["library L;", "export 'lib.dart';", "export 'lib.dart';"]));
65 addNamedSource("/lib.dart", EngineTestCase.createSource(["library lib;", "cl ass N {}"]));
66 resolve(source);
67 assertNoErrors(source);
68 verify([source]);
69 }
70
71 void test_ambiguousImport_hideCombinator() {
72 Source source = addSource(EngineTestCase.createSource([
73 "import 'lib1.dart';",
74 "import 'lib2.dart';",
75 "import 'lib3.dart' hide N;",
76 "main() {",
77 " new N1();",
78 " new N2();",
79 " new N3();",
80 "}"]));
81 addNamedSource("/lib1.dart", EngineTestCase.createSource(["library lib1;", " class N {}", "class N1 {}"]));
82 addNamedSource("/lib2.dart", EngineTestCase.createSource(["library lib2;", " class N {}", "class N2 {}"]));
83 addNamedSource("/lib3.dart", EngineTestCase.createSource(["library lib3;", " class N {}", "class N3 {}"]));
84 resolve(source);
85 assertNoErrors(source);
86 }
87
88 void test_ambiguousImport_showCombinator() {
89 Source source = addSource(EngineTestCase.createSource([
90 "import 'lib1.dart';",
91 "import 'lib2.dart' show N, N2;",
92 "main() {",
93 " new N1();",
94 " new N2();",
95 "}"]));
96 addNamedSource("/lib1.dart", EngineTestCase.createSource(["library lib1;", " class N {}", "class N1 {}"]));
97 addNamedSource("/lib2.dart", EngineTestCase.createSource(["library lib2;", " class N {}", "class N2 {}"]));
98 resolve(source);
99 assertNoErrors(source);
100 }
101
102 void test_argumentTypeNotAssignable_classWithCall_Function() {
103 Source source = addSource(EngineTestCase.createSource([
104 " caller(Function callee) {",
105 " callee();",
106 " }",
107 "",
108 " class CallMeBack {",
109 " call() => 0;",
110 " }",
111 "",
112 " main() {",
113 " caller(new CallMeBack());",
114 " }"]));
115 resolve(source);
116 assertNoErrors(source);
117 verify([source]);
118 }
119
120 void test_argumentTypeNotAssignable_fieldFormalParameterElement_member() {
121 Source source = addSource(EngineTestCase.createSource([
122 "class ObjectSink<T> {",
123 " void sink(T object) {",
124 " new TimestampedObject<T>(object);",
125 " }",
126 "}",
127 "class TimestampedObject<E> {",
128 " E object2;",
129 " TimestampedObject(this.object2);",
130 "}"]));
131 resolve(source);
132 assertNoErrors(source);
133 verify([source]);
134 }
135
136 void test_argumentTypeNotAssignable_invocation_functionParameter_generic() {
137 Source source = addSource(EngineTestCase.createSource([
138 "class A<K> {",
139 " m(f(K k), K v) {",
140 " f(v);",
141 " }",
142 "}"]));
143 resolve(source);
144 assertNoErrors(source);
145 verify([source]);
146 }
147
148 void test_argumentTypeNotAssignable_invocation_typedef_generic() {
149 Source source = addSource(EngineTestCase.createSource(["typedef A<T>(T p);", "f(A<int> a) {", " a(1);", "}"]));
150 resolve(source);
151 assertNoErrors(source);
152 verify([source]);
153 }
154
155 void test_argumentTypeNotAssignable_Object_Function() {
156 Source source = addSource(EngineTestCase.createSource([
157 "main() {",
158 " process(() {});",
159 "}",
160 "process(Object x) {}"]));
161 resolve(source);
162 assertNoErrors(source);
163 verify([source]);
164 }
165
166 void test_argumentTypeNotAssignable_typedef_local() {
167 Source source = addSource(EngineTestCase.createSource([
168 "typedef A(int p1, String p2);",
169 "A getA() => null;",
170 "f() {",
171 " A a = getA();",
172 " a(1, '2');",
173 "}"]));
174 resolve(source);
175 assertNoErrors(source);
176 verify([source]);
177 }
178
179 void test_argumentTypeNotAssignable_typedef_parameter() {
180 Source source = addSource(EngineTestCase.createSource([
181 "typedef A(int p1, String p2);",
182 "f(A a) {",
183 " a(1, '2');",
184 "}"]));
185 resolve(source);
186 assertNoErrors(source);
187 verify([source]);
188 }
189
190 void test_assignmentToFinal_prefixNegate() {
191 Source source = addSource(EngineTestCase.createSource(["f() {", " final x = 0;", " -x;", "}"]));
192 resolve(source);
193 assertNoErrors(source);
194 verify([source]);
195 }
196
197 void test_assignmentToFinalNoSetter_prefixedIdentifier() {
198 Source source = addSource(EngineTestCase.createSource([
199 "class A {",
200 " int get x => 0;",
201 " set x(v) {}",
202 "}",
203 "main() {",
204 " A a = new A();",
205 " a.x = 0;",
206 "}"]));
207 resolve(source);
208 assertNoErrors(source);
209 verify([source]);
210 }
211
212 void test_assignmentToFinalNoSetter_propertyAccess() {
213 Source source = addSource(EngineTestCase.createSource([
214 "class A {",
215 " int get x => 0;",
216 " set x(v) {}",
217 "}",
218 "class B {",
219 " static A a;",
220 "}",
221 "main() {",
222 " B.a.x = 0;",
223 "}"]));
224 resolve(source);
225 assertNoErrors(source);
226 verify([source]);
227 }
228
229 void test_assignmentToFinals_importWithPrefix() {
230 Source source = addSource(EngineTestCase.createSource([
231 "library lib;",
232 "import 'lib1.dart' as foo;",
233 "main() {",
234 " foo.x = true;",
235 "}"]));
236 addNamedSource("/lib1.dart", EngineTestCase.createSource(["library lib1;", " bool x = false;"]));
237 resolve(source);
238 assertNoErrors(source);
239 verify([source]);
240 }
241
242 void test_asyncForInWrongContext_async() {
243 resetWithAsync();
244 Source source = addSource(EngineTestCase.createSource([
245 "f(list) async {",
246 " await for (var e in list) {",
247 " }",
248 "}"]));
249 resolve(source);
250 assertNoErrors(source);
251 verify([source]);
252 }
253
254 void test_asyncForInWrongContext_asyncStar() {
255 resetWithAsync();
256 Source source = addSource(EngineTestCase.createSource([
257 "f(list) async* {",
258 " await for (var e in list) {",
259 " }",
260 "}"]));
261 resolve(source);
262 assertNoErrors(source);
263 verify([source]);
264 }
265
266 void test_awaitInWrongContext_async() {
267 resetWithAsync();
268 Source source = addSource(EngineTestCase.createSource(["f(x, y) async {", " return await x + await y;", "}"]));
269 resolve(source);
270 assertNoErrors(source);
271 verify([source]);
272 }
273
274 void test_awaitInWrongContext_asyncStar() {
275 resetWithAsync();
276 Source source = addSource(EngineTestCase.createSource(["f(x, y) async* {", " yield await x + await y;", "}"]));
277 resolve(source);
278 assertNoErrors(source);
279 verify([source]);
280 }
281
282 void test_breakWithoutLabelInSwitch() {
283 Source source = addSource(EngineTestCase.createSource([
284 "class A {",
285 " void m(int i) {",
286 " switch (i) {",
287 " case 0:",
288 " break;",
289 " }",
290 " }",
291 "}"]));
292 resolve(source);
293 assertNoErrors(source);
294 verify([source]);
295 }
296
297 void test_builtInIdentifierAsType_dynamic() {
298 Source source = addSource(EngineTestCase.createSource(["f() {", " dynamic x ;", "}"]));
299 resolve(source);
300 assertNoErrors(source);
301 verify([source]);
302 }
303
304 void test_caseBlockNotTerminated() {
305 Source source = addSource(EngineTestCase.createSource([
306 "f(int p) {",
307 " for (int i = 0; i < 10; i++) {",
308 " switch (p) {",
309 " case 0:",
310 " break;",
311 " case 1:",
312 " continue;",
313 " case 2:",
314 " return;",
315 " case 3:",
316 " throw new Object();",
317 " case 4:",
318 " case 5:",
319 " return;",
320 " case 6:",
321 " default:",
322 " return;",
323 " }",
324 " }",
325 "}"]));
326 resolve(source);
327 assertNoErrors(source);
328 verify([source]);
329 }
330
331 void test_caseBlockNotTerminated_lastCase() {
332 Source source = addSource(EngineTestCase.createSource([
333 "f(int p) {",
334 " switch (p) {",
335 " case 0:",
336 " p = p + 1;",
337 " }",
338 "}"]));
339 resolve(source);
340 assertNoErrors(source);
341 verify([source]);
342 }
343
344 void test_caseExpressionTypeImplementsEquals() {
345 Source source = addSource(EngineTestCase.createSource([
346 "print(p) {}",
347 "",
348 "abstract class B {",
349 " final id;",
350 " const B(this.id);",
351 " String toString() => 'C(\$id)';",
352 " /** Equality is identity equality, the id isn't used. */",
353 " bool operator==(Object other);",
354 " }",
355 "",
356 "class C extends B {",
357 " const C(id) : super(id);",
358 "}",
359 "",
360 "void doSwitch(c) {",
361 " switch (c) {",
362 " case const C(0): print('Switch: 0'); break;",
363 " case const C(1): print('Switch: 1'); break;",
364 " }",
365 "}"]));
366 resolve(source);
367 assertNoErrors(source);
368 verify([source]);
369 }
370
371 void test_caseExpressionTypeImplementsEquals_int() {
372 Source source = addSource(EngineTestCase.createSource([
373 "f(int i) {",
374 " switch(i) {",
375 " case(1) : return 1;",
376 " default: return 0;",
377 " }",
378 "}"]));
379 resolve(source);
380 assertNoErrors(source);
381 verify([source]);
382 }
383
384 void test_caseExpressionTypeImplementsEquals_Object() {
385 Source source = addSource(EngineTestCase.createSource([
386 "class IntWrapper {",
387 " final int value;",
388 " const IntWrapper(this.value);",
389 "}",
390 "",
391 "f(IntWrapper intWrapper) {",
392 " switch(intWrapper) {",
393 " case(const IntWrapper(1)) : return 1;",
394 " default: return 0;",
395 " }",
396 "}"]));
397 resolve(source);
398 assertNoErrors(source);
399 verify([source]);
400 }
401
402 void test_caseExpressionTypeImplementsEquals_String() {
403 Source source = addSource(EngineTestCase.createSource([
404 "f(String s) {",
405 " switch(s) {",
406 " case('1') : return 1;",
407 " default: return 0;",
408 " }",
409 "}"]));
410 resolve(source);
411 assertNoErrors(source);
412 verify([source]);
413 }
414
415 void test_commentReference_beforeConstructor() {
416 String code = EngineTestCase.createSource(["abstract class A {", " /// [p]" , " A(int p) {}", "}"]);
417 Source source = addSource(code);
418 resolve(source);
419 assertNoErrors(source);
420 verify([source]);
421 CompilationUnit unit = analysisContext.parseCompilationUnit(source);
422 {
423 SimpleIdentifier ref = EngineTestCase.findNode(unit, code, "p]", (node) => node is SimpleIdentifier);
424 EngineTestCase.assertInstanceOf((obj) => obj is ParameterElement, Paramete rElement, ref.staticElement);
425 }
426 }
427
428 void test_commentReference_beforeFunction_blockBody() {
429 String code = EngineTestCase.createSource(["/// [p]", "foo(int p) {", "}"]);
430 Source source = addSource(code);
431 resolve(source);
432 assertNoErrors(source);
433 verify([source]);
434 CompilationUnit unit = analysisContext.parseCompilationUnit(source);
435 SimpleIdentifier ref = EngineTestCase.findNode(unit, code, "p]", (node) => n ode is SimpleIdentifier);
436 EngineTestCase.assertInstanceOf((obj) => obj is ParameterElement, ParameterE lement, ref.staticElement);
437 }
438
439 void test_commentReference_beforeFunction_expressionBody() {
440 String code = EngineTestCase.createSource(["/// [p]", "foo(int p) => null;"] );
441 Source source = addSource(code);
442 resolve(source);
443 assertNoErrors(source);
444 verify([source]);
445 CompilationUnit unit = analysisContext.parseCompilationUnit(source);
446 SimpleIdentifier ref = EngineTestCase.findNode(unit, code, "p]", (node) => n ode is SimpleIdentifier);
447 EngineTestCase.assertInstanceOf((obj) => obj is ParameterElement, ParameterE lement, ref.staticElement);
448 }
449
450 void test_commentReference_beforeMethod() {
451 String code = EngineTestCase.createSource([
452 "abstract class A {",
453 " /// [p1]",
454 " ma(int p1) {}",
455 " /// [p2]",
456 " mb(int p2);",
457 "}"]);
458 Source source = addSource(code);
459 resolve(source);
460 assertNoErrors(source);
461 verify([source]);
462 CompilationUnit unit = analysisContext.parseCompilationUnit(source);
463 {
464 SimpleIdentifier ref = EngineTestCase.findNode(unit, code, "p1]", (node) = > node is SimpleIdentifier);
465 EngineTestCase.assertInstanceOf((obj) => obj is ParameterElement, Paramete rElement, ref.staticElement);
466 }
467 {
468 SimpleIdentifier ref = EngineTestCase.findNode(unit, code, "p2]", (node) = > node is SimpleIdentifier);
469 EngineTestCase.assertInstanceOf((obj) => obj is ParameterElement, Paramete rElement, ref.staticElement);
470 }
471 }
472
473 void test_commentReference_class() {
474 String code = EngineTestCase.createSource(["/// [foo]", "class A {", " foo( ) {}", "}"]);
475 Source source = addSource(code);
476 resolve(source);
477 assertNoErrors(source);
478 verify([source]);
479 CompilationUnit unit = analysisContext.parseCompilationUnit(source);
480 SimpleIdentifier ref = EngineTestCase.findNode(unit, code, "foo]", (node) => node is SimpleIdentifier);
481 EngineTestCase.assertInstanceOf((obj) => obj is MethodElement, MethodElement , ref.staticElement);
482 }
483
484 void test_commentReference_setter() {
485 String code = EngineTestCase.createSource([
486 "class A {",
487 " /// [x] in A",
488 " mA() {}",
489 " set x(value) {}",
490 "}",
491 "class B extends A {",
492 " /// [x] in B",
493 " mB() {}",
494 "}",
495 ""]);
496 Source source = addSource(code);
497 resolve(source);
498 assertNoErrors(source);
499 verify([source]);
500 CompilationUnit unit = analysisContext.parseCompilationUnit(source);
501 {
502 SimpleIdentifier ref = EngineTestCase.findNode(unit, code, "x] in A", (nod e) => node is SimpleIdentifier);
503 EngineTestCase.assertInstanceOf((obj) => obj is PropertyAccessorElement, P ropertyAccessorElement, ref.staticElement);
504 }
505 {
506 SimpleIdentifier ref = EngineTestCase.findNode(unit, code, "x] in B", (nod e) => node is SimpleIdentifier);
507 EngineTestCase.assertInstanceOf((obj) => obj is PropertyAccessorElement, P ropertyAccessorElement, ref.staticElement);
508 }
509 }
510
511 void test_concreteClassWithAbstractMember() {
512 Source source = addSource(EngineTestCase.createSource(["abstract class A {", " m();", "}"]));
513 resolve(source);
514 assertNoErrors(source);
515 verify([source]);
516 }
517
518 void test_concreteClassWithAbstractMember_inherited() {
519 Source source = addSource(EngineTestCase.createSource([
520 "class A {",
521 " m() {}",
522 "}",
523 "class B extends A {",
524 " m();",
525 "}"]));
526 resolve(source);
527 assertNoErrors(source);
528 verify([source]);
529 }
530
531 void test_conflictingInstanceGetterAndSuperclassMember_instance() {
532 Source source = addSource(EngineTestCase.createSource([
533 "class A {",
534 " get v => 0;",
535 "}",
536 "class B extends A {",
537 " get v => 1;",
538 "}"]));
539 resolve(source);
540 assertNoErrors(source);
541 verify([source]);
542 }
543
544 void test_conflictingStaticGetterAndInstanceSetter_thisClass() {
545 Source source = addSource(EngineTestCase.createSource([
546 "class A {",
547 " static get x => 0;",
548 " static set x(int p) {}",
549 "}"]));
550 resolve(source);
551 assertNoErrors(source);
552 verify([source]);
553 }
554
555 void test_conflictingStaticSetterAndInstanceMember_thisClass_method() {
556 Source source = addSource(EngineTestCase.createSource([
557 "class A {",
558 " static x() {}",
559 " static set x(int p) {}",
560 "}"]));
561 resolve(source);
562 assertNoErrors(source);
563 verify([source]);
564 }
565
566 void test_constConstructorWithNonConstSuper_explicit() {
567 Source source = addSource(EngineTestCase.createSource([
568 "class A {",
569 " const A();",
570 "}",
571 "class B extends A {",
572 " const B(): super();",
573 "}"]));
574 resolve(source);
575 assertNoErrors(source);
576 verify([source]);
577 }
578
579 void test_constConstructorWithNonConstSuper_redirectingFactory() {
580 Source source = addSource(EngineTestCase.createSource([
581 "class A {",
582 " A();",
583 "}",
584 "class B implements C {",
585 " const B();",
586 "}",
587 "class C extends A {",
588 " const factory C() = B;",
589 "}"]));
590 resolve(source);
591 assertNoErrors(source);
592 verify([source]);
593 }
594
595 void test_constConstructorWithNonConstSuper_unresolved() {
596 Source source = addSource(EngineTestCase.createSource([
597 "class A {",
598 " A.a();",
599 "}",
600 "class B extends A {",
601 " const B(): super();",
602 "}"]));
603 resolve(source);
604 assertErrors(source, [CompileTimeErrorCode.UNDEFINED_CONSTRUCTOR_IN_INITIALI ZER_DEFAULT]);
605 verify([source]);
606 }
607
608 void test_constConstructorWithNonFinalField_finalInstanceVar() {
609 Source source = addSource(EngineTestCase.createSource(["class A {", " final int x = 0;", " const A();", "}"]));
610 resolve(source);
611 assertNoErrors(source);
612 verify([source]);
613 }
614
615 void test_constConstructorWithNonFinalField_mixin() {
616 Source source = addSource(EngineTestCase.createSource([
617 "class A {",
618 " a() {}",
619 "}",
620 "class B extends Object with A {",
621 " const B();",
622 "}"]));
623 resolve(source);
624 assertErrors(source, [CompileTimeErrorCode.CONST_CONSTRUCTOR_WITH_MIXIN]);
625 verify([source]);
626 }
627
628 void test_constConstructorWithNonFinalField_static() {
629 Source source = addSource(EngineTestCase.createSource(["class A {", " stati c int x;", " const A();", "}"]));
630 resolve(source);
631 assertNoErrors(source);
632 verify([source]);
633 }
634
635 void test_constConstructorWithNonFinalField_syntheticField() {
636 Source source = addSource(EngineTestCase.createSource([
637 "class A {",
638 " const A();",
639 " set x(value) {}",
640 " get x {return 0;}",
641 "}"]));
642 resolve(source);
643 assertNoErrors(source);
644 verify([source]);
645 }
646
647 void test_constDeferredClass_new() {
648 resolveWithAndWithoutExperimental(<String> [
649 EngineTestCase.createSource(["library lib1;", "class A {", " const A.b( );", "}"]),
650 EngineTestCase.createSource([
651 "library root;",
652 "import 'lib1.dart' deferred as a;",
653 "main() {",
654 " new a.A.b();",
655 "}"])], <ErrorCode> [ParserErrorCode.DEFERRED_IMPORTS_NOT_SUPPORTED], <E rrorCode> []);
656 }
657
658 void test_constEval_functionTypeLiteral() {
659 Source source = addSource(EngineTestCase.createSource(["typedef F();", "cons t C = F;"]));
660 resolve(source);
661 assertNoErrors(source);
662 verify([source]);
663 }
664
665 void test_constEval_propertyExtraction_fieldStatic_targetType() {
666 addNamedSource("/math.dart", EngineTestCase.createSource(["library math;", " const PI = 3.14;"]));
667 Source source = addSource(EngineTestCase.createSource(["import 'math.dart' a s math;", "const C = math.PI;"]));
668 resolve(source);
669 assertNoErrors(source);
670 verify([source]);
671 }
672
673 void test_constEval_propertyExtraction_methodStatic_targetType() {
674 Source source = addSource(EngineTestCase.createSource([
675 "class A {",
676 " const A();",
677 " static m() {}",
678 "}",
679 "const C = A.m;"]));
680 resolve(source);
681 assertNoErrors(source);
682 verify([source]);
683 }
684
685 void test_constEval_symbol() {
686 addNamedSource("/math.dart", EngineTestCase.createSource(["library math;", " const PI = 3.14;"]));
687 Source source = addSource(EngineTestCase.createSource(["const C = #foo;", "f oo() {}"]));
688 resolve(source);
689 assertNoErrors(source);
690 verify([source]);
691 }
692
693 void test_constEvalTypeBoolNumString_equal() {
694 Source source = addSource(EngineTestCase.createSource([
695 "class A {",
696 " const A();",
697 "}",
698 "class B {",
699 " final v;",
700 " const B.a1(bool p) : v = p == true;",
701 " const B.a2(bool p) : v = p == false;",
702 " const B.a3(bool p) : v = p == 0;",
703 " const B.a4(bool p) : v = p == 0.0;",
704 " const B.a5(bool p) : v = p == '';",
705 " const B.b1(int p) : v = p == true;",
706 " const B.b2(int p) : v = p == false;",
707 " const B.b3(int p) : v = p == 0;",
708 " const B.b4(int p) : v = p == 0.0;",
709 " const B.b5(int p) : v = p == '';",
710 " const B.c1(String p) : v = p == true;",
711 " const B.c2(String p) : v = p == false;",
712 " const B.c3(String p) : v = p == 0;",
713 " const B.c4(String p) : v = p == 0.0;",
714 " const B.c5(String p) : v = p == '';",
715 " const B.n1(num p) : v = p == null;",
716 " const B.n2(num p) : v = null == p;",
717 "}"]));
718 resolve(source);
719 assertNoErrors(source);
720 }
721
722 void test_constEvalTypeBoolNumString_notEqual() {
723 Source source = addSource(EngineTestCase.createSource([
724 "class A {",
725 " const A();",
726 "}",
727 "class B {",
728 " final v;",
729 " const B.a1(bool p) : v = p != true;",
730 " const B.a2(bool p) : v = p != false;",
731 " const B.a3(bool p) : v = p != 0;",
732 " const B.a4(bool p) : v = p != 0.0;",
733 " const B.a5(bool p) : v = p != '';",
734 " const B.b1(int p) : v = p != true;",
735 " const B.b2(int p) : v = p != false;",
736 " const B.b3(int p) : v = p != 0;",
737 " const B.b4(int p) : v = p != 0.0;",
738 " const B.b5(int p) : v = p != '';",
739 " const B.c1(String p) : v = p != true;",
740 " const B.c2(String p) : v = p != false;",
741 " const B.c3(String p) : v = p != 0;",
742 " const B.c4(String p) : v = p != 0.0;",
743 " const B.c5(String p) : v = p != '';",
744 " const B.n1(num p) : v = p != null;",
745 " const B.n2(num p) : v = null != p;",
746 "}"]));
747 resolve(source);
748 assertNoErrors(source);
749 verify([source]);
750 }
751
752 void test_constMapKeyExpressionTypeImplementsEquals_abstract() {
753 Source source = addSource(EngineTestCase.createSource([
754 "abstract class B {",
755 " final id;",
756 " const B(this.id);",
757 " String toString() => 'C(\$id)';",
758 " /** Equality is identity equality, the id isn't used. */",
759 " bool operator==(Object other);",
760 " }",
761 "",
762 "class C extends B {",
763 " const C(id) : super(id);",
764 "}",
765 "",
766 "Map getMap() {",
767 " return const { const C(0): 'Map: 0' };",
768 "}"]));
769 resolve(source);
770 assertNoErrors(source);
771 verify([source]);
772 }
773
774 void test_constNotInitialized_field() {
775 Source source = addSource(EngineTestCase.createSource(["class A {", " stati c const int x = 0;", "}"]));
776 resolve(source);
777 assertNoErrors(source);
778 verify([source]);
779 }
780
781 void test_constNotInitialized_local() {
782 Source source = addSource(EngineTestCase.createSource(["main() {", " const int x = 0;", "}"]));
783 resolve(source);
784 assertNoErrors(source);
785 verify([source]);
786 }
787
788 void test_constructorDeclaration_scope_signature() {
789 Source source = addSource(EngineTestCase.createSource([
790 "const app = 0;",
791 "class A {",
792 " A(@app int app) {}",
793 "}"]));
794 resolve(source);
795 assertNoErrors(source);
796 verify([source]);
797 }
798
799 void test_constWithNonConstantArgument_literals() {
800 Source source = addSource(EngineTestCase.createSource([
801 "class A {",
802 " const A(a, b, c, d);",
803 "}",
804 "f() { return const A(true, 0, 1.0, '2'); }"]));
805 resolve(source);
806 assertNoErrors(source);
807 verify([source]);
808 }
809
810 void test_constWithTypeParameters_direct() {
811 Source source = addSource(EngineTestCase.createSource([
812 "class A<T> {",
813 " static const V = const A<int>();",
814 " const A();",
815 "}"]));
816 resolve(source);
817 assertNoErrors(source);
818 verify([source]);
819 }
820
821 void test_constWithUndefinedConstructor() {
822 Source source = addSource(EngineTestCase.createSource([
823 "class A {",
824 " const A.name();",
825 "}",
826 "f() {",
827 " return const A.name();",
828 "}"]));
829 resolve(source);
830 assertNoErrors(source);
831 verify([source]);
832 }
833
834 void test_constWithUndefinedConstructorDefault() {
835 Source source = addSource(EngineTestCase.createSource([
836 "class A {",
837 " const A();",
838 "}",
839 "f() {",
840 " return const A();",
841 "}"]));
842 resolve(source);
843 assertNoErrors(source);
844 verify([source]);
845 }
846
847 void test_defaultValueInFunctionTypeAlias() {
848 Source source = addSource(EngineTestCase.createSource(["typedef F([x]);"]));
849 resolve(source);
850 assertNoErrors(source);
851 verify([source]);
852 }
853
854 void test_defaultValueInFunctionTypedParameter_named() {
855 Source source = addSource(EngineTestCase.createSource(["f(g({p})) {}"]));
856 resolve(source);
857 assertNoErrors(source);
858 verify([source]);
859 }
860
861 void test_defaultValueInFunctionTypedParameter_optional() {
862 Source source = addSource(EngineTestCase.createSource(["f(g([p])) {}"]));
863 resolve(source);
864 assertNoErrors(source);
865 verify([source]);
866 }
867
868 void test_deprecatedMemberUse_hide() {
869 Source source = addSource(EngineTestCase.createSource([
870 "library lib;",
871 "import 'lib1.dart' hide B;",
872 "A a = new A();"]));
873 addNamedSource("/lib1.dart", EngineTestCase.createSource([
874 "library lib1;",
875 "class A {}",
876 "@deprecated",
877 "class B {}"]));
878 resolve(source);
879 assertNoErrors(source);
880 verify([source]);
881 }
882
883 void test_duplicateDefinition_emptyName() {
884 // Note: This code has two FunctionElements '() {}' with an empty name, this tests that the
885 // empty string is not put into the scope (more than once).
886 Source source = addSource(EngineTestCase.createSource([
887 "Map _globalMap = {",
888 " 'a' : () {},",
889 " 'b' : () {}",
890 "};"]));
891 resolve(source);
892 assertNoErrors(source);
893 verify([source]);
894 }
895
896 void test_duplicateDefinition_getter() {
897 Source source = addSource(EngineTestCase.createSource(["bool get a => true;" ]));
898 resolve(source);
899 assertNoErrors(source);
900 verify([source]);
901 }
902
903 void test_dynamicIdentifier() {
904 Source source = addSource(EngineTestCase.createSource(["main() {", " var v = dynamic;", "}"]));
905 resolve(source);
906 assertNoErrors(source);
907 verify([source]);
908 }
909
910 void test_expectedOneListTypeArgument() {
911 Source source = addSource(EngineTestCase.createSource(["main() {", " <int> [];", "}"]));
912 resolve(source);
913 assertNoErrors(source);
914 verify([source]);
915 }
916
917 void test_expectedTwoMapTypeArguments() {
918 Source source = addSource(EngineTestCase.createSource(["main() {", " <int, int> {};", "}"]));
919 resolve(source);
920 assertNoErrors(source);
921 verify([source]);
922 }
923
924 void test_exportOfNonLibrary_libraryDeclared() {
925 Source source = addSource(EngineTestCase.createSource(["library L;", "export 'lib1.dart';"]));
926 addNamedSource("/lib1.dart", EngineTestCase.createSource(["library lib1;"])) ;
927 resolve(source);
928 assertNoErrors(source);
929 verify([source]);
930 }
931
932 void test_exportOfNonLibrary_libraryNotDeclared() {
933 Source source = addSource(EngineTestCase.createSource(["library L;", "export 'lib1.dart';"]));
934 addNamedSource("/lib1.dart", EngineTestCase.createSource([""]));
935 resolve(source);
936 assertNoErrors(source);
937 verify([source]);
938 }
939
940 void test_extraPositionalArguments_function() {
941 Source source = addSource(EngineTestCase.createSource(["f(p1, p2) {}", "main () {", " f(1, 2);", "}"]));
942 resolve(source);
943 assertNoErrors(source);
944 verify([source]);
945 }
946
947 void test_extraPositionalArguments_Function() {
948 Source source = addSource(EngineTestCase.createSource(["f(Function a) {", " a(1, 2);", "}"]));
949 resolve(source);
950 assertNoErrors(source);
951 verify([source]);
952 }
953
954 void test_extraPositionalArguments_implicitConstructor() {
955 Source source = addSource(EngineTestCase.createSource([
956 "class A<E extends num> {",
957 " A(E x, E y);",
958 "}",
959 "class M {}",
960 "class B<E extends num> = A<E> with M;",
961 "void main() {",
962 " B<int> x = new B<int>(0,0);",
963 "}"]));
964 resolve(source);
965 assertNoErrors(source);
966 verify([source]);
967 }
968
969 void test_extraPositionalArguments_typedef_local() {
970 Source source = addSource(EngineTestCase.createSource([
971 "typedef A(p1, p2);",
972 "A getA() => null;",
973 "f() {",
974 " A a = getA();",
975 " a(1, 2);",
976 "}"]));
977 resolve(source);
978 assertNoErrors(source);
979 verify([source]);
980 }
981
982 void test_extraPositionalArguments_typedef_parameter() {
983 Source source = addSource(EngineTestCase.createSource(["typedef A(p1, p2);", "f(A a) {", " a(1, 2);", "}"]));
984 resolve(source);
985 assertNoErrors(source);
986 verify([source]);
987 }
988
989 void test_fieldInitializedByMultipleInitializers() {
990 Source source = addSource(EngineTestCase.createSource([
991 "class A {",
992 " int x;",
993 " int y;",
994 " A() : x = 0, y = 0 {}",
995 "}"]));
996 resolve(source);
997 assertNoErrors(source);
998 verify([source]);
999 }
1000
1001 void test_fieldInitializedInInitializerAndDeclaration_fieldNotFinal() {
1002 Source source = addSource(EngineTestCase.createSource(["class A {", " int x = 0;", " A() : x = 1 {}", "}"]));
1003 resolve(source);
1004 assertNoErrors(source);
1005 verify([source]);
1006 }
1007
1008 void test_fieldInitializedInInitializerAndDeclaration_finalFieldNotSet() {
1009 Source source = addSource(EngineTestCase.createSource(["class A {", " final int x;", " A() : x = 1 {}", "}"]));
1010 resolve(source);
1011 assertNoErrors(source);
1012 verify([source]);
1013 }
1014
1015 void test_fieldInitializerOutsideConstructor() {
1016 Source source = addSource(EngineTestCase.createSource(["class A {", " int x ;", " A(this.x) {}", "}"]));
1017 resolve(source);
1018 assertNoErrors(source);
1019 verify([source]);
1020 }
1021
1022 void test_fieldInitializerOutsideConstructor_defaultParameters() {
1023 Source source = addSource(EngineTestCase.createSource(["class A {", " int x ;", " A([this.x]) {}", "}"]));
1024 resolve(source);
1025 assertNoErrors(source);
1026 verify([source]);
1027 }
1028
1029 void test_fieldInitializerRedirectingConstructor_super() {
1030 Source source = addSource(EngineTestCase.createSource([
1031 "class A {",
1032 " A() {}",
1033 "}",
1034 "class B extends A {",
1035 " int x;",
1036 " B(this.x) : super();",
1037 "}"]));
1038 resolve(source);
1039 assertNoErrors(source);
1040 verify([source]);
1041 }
1042
1043 void test_finalInitializedInDeclarationAndConstructor_initializer() {
1044 Source source = addSource(EngineTestCase.createSource(["class A {", " final x;", " A() : x = 1 {}", "}"]));
1045 resolve(source);
1046 assertNoErrors(source);
1047 verify([source]);
1048 }
1049
1050 void test_finalInitializedInDeclarationAndConstructor_initializingFormal() {
1051 Source source = addSource(EngineTestCase.createSource(["class A {", " final x;", " A(this.x) {}", "}"]));
1052 resolve(source);
1053 assertNoErrors(source);
1054 verify([source]);
1055 }
1056
1057 void test_finalNotInitialized_atDeclaration() {
1058 Source source = addSource(EngineTestCase.createSource(["class A {", " final int x = 0;", " A() {}", "}"]));
1059 resolve(source);
1060 assertNoErrors(source);
1061 verify([source]);
1062 }
1063
1064 void test_finalNotInitialized_fieldFormal() {
1065 Source source = addSource(EngineTestCase.createSource(["class A {", " final int x = 0;", " A() {}", "}"]));
1066 resolve(source);
1067 assertNoErrors(source);
1068 verify([source]);
1069 }
1070
1071 void test_finalNotInitialized_functionTypedFieldFormal() {
1072 Source source = addSource(EngineTestCase.createSource([
1073 "class A {",
1074 " final Function x;",
1075 " A(int this.x(int p)) {}",
1076 "}"]));
1077 resolve(source);
1078 assertNoErrors(source);
1079 verify([source]);
1080 }
1081
1082 void test_finalNotInitialized_hasNativeClause_hasConstructor() {
1083 Source source = addSource(EngineTestCase.createSource([
1084 "class A native 'something' {",
1085 " final int x;",
1086 " A() {}",
1087 "}"]));
1088 resolve(source);
1089 assertErrors(source, [ParserErrorCode.NATIVE_CLAUSE_IN_NON_SDK_CODE]);
1090 verify([source]);
1091 }
1092
1093 void test_finalNotInitialized_hasNativeClause_noConstructor() {
1094 Source source = addSource(EngineTestCase.createSource(["class A native 'some thing' {", " final int x;", "}"]));
1095 resolve(source);
1096 assertErrors(source, [ParserErrorCode.NATIVE_CLAUSE_IN_NON_SDK_CODE]);
1097 verify([source]);
1098 }
1099
1100 void test_finalNotInitialized_initializer() {
1101 Source source = addSource(EngineTestCase.createSource(["class A {", " final int x;", " A() : x = 0 {}", "}"]));
1102 resolve(source);
1103 assertNoErrors(source);
1104 verify([source]);
1105 }
1106
1107 void test_finalNotInitialized_redirectingConstructor() {
1108 Source source = addSource(EngineTestCase.createSource([
1109 "class A {",
1110 " final int x;",
1111 " A(this.x);",
1112 " A.named() : this (42);",
1113 "}"]));
1114 resolve(source);
1115 assertNoErrors(source);
1116 verify([source]);
1117 }
1118
1119 void test_functionDeclaration_scope_returnType() {
1120 Source source = addSource(EngineTestCase.createSource(["int f(int) { return 0; }"]));
1121 resolve(source);
1122 assertNoErrors(source);
1123 verify([source]);
1124 }
1125
1126 void test_functionDeclaration_scope_signature() {
1127 Source source = addSource(EngineTestCase.createSource(["const app = 0;", "f( @app int app) {}"]));
1128 resolve(source);
1129 assertNoErrors(source);
1130 verify([source]);
1131 }
1132
1133 void test_functionTypeAlias_scope_returnType() {
1134 Source source = addSource(EngineTestCase.createSource(["typedef int f(int);" ]));
1135 resolve(source);
1136 assertNoErrors(source);
1137 verify([source]);
1138 }
1139
1140 void test_functionTypeAlias_scope_signature() {
1141 Source source = addSource(EngineTestCase.createSource(["const app = 0;", "ty pedef int f(@app int app);"]));
1142 resolve(source);
1143 assertNoErrors(source);
1144 verify([source]);
1145 }
1146
1147 void test_functionWithoutCall() {
1148 Source source = addSource(EngineTestCase.createSource([
1149 "abstract class A implements Function {",
1150 "}",
1151 "class B implements A {",
1152 " void call() {}",
1153 "}",
1154 "class C extends A {",
1155 " void call() {}",
1156 "}",
1157 "class D extends C {",
1158 "}"]));
1159 resolve(source);
1160 assertNoErrors(source);
1161 verify([source]);
1162 }
1163
1164 void test_functionWithoutCall_doesNotImplementFunction() {
1165 Source source = addSource(EngineTestCase.createSource(["class A {}"]));
1166 resolve(source);
1167 assertNoErrors(source);
1168 verify([source]);
1169 }
1170
1171 void test_functionWithoutCall_withNoSuchMethod() {
1172 // 16078
1173 Source source = addSource(EngineTestCase.createSource([
1174 "class A implements Function {",
1175 " noSuchMethod(inv) {",
1176 " return 42;",
1177 " }",
1178 "}"]));
1179 resolve(source);
1180 assertNoErrors(source);
1181 verify([source]);
1182 }
1183
1184 void test_implicitThisReferenceInInitializer_constructorName() {
1185 Source source = addSource(EngineTestCase.createSource([
1186 "class A {",
1187 " A.named() {}",
1188 "}",
1189 "class B {",
1190 " var v;",
1191 " B() : v = new A.named();",
1192 "}"]));
1193 resolve(source);
1194 assertNoErrors(source);
1195 verify([source]);
1196 }
1197
1198 void test_implicitThisReferenceInInitializer_importPrefix() {
1199 Source source = addSource(EngineTestCase.createSource([
1200 "import 'dart:async' as abstract;",
1201 "class A {",
1202 " var v = new abstract.Completer();",
1203 "}"]));
1204 resolve(source);
1205 assertNoErrors(source);
1206 verify([source]);
1207 }
1208
1209 void test_implicitThisReferenceInInitializer_prefixedIdentifier() {
1210 Source source = addSource(EngineTestCase.createSource([
1211 "class A {",
1212 " var f;",
1213 "}",
1214 "class B {",
1215 " var v;",
1216 " B(A a) : v = a.f;",
1217 "}"]));
1218 resolve(source);
1219 assertNoErrors(source);
1220 verify([source]);
1221 }
1222
1223 void test_implicitThisReferenceInInitializer_qualifiedMethodInvocation() {
1224 Source source = addSource(EngineTestCase.createSource([
1225 "class A {",
1226 " f() {}",
1227 "}",
1228 "class B {",
1229 " var v;",
1230 " B() : v = new A().f();",
1231 "}"]));
1232 resolve(source);
1233 assertNoErrors(source);
1234 verify([source]);
1235 }
1236
1237 void test_implicitThisReferenceInInitializer_qualifiedPropertyAccess() {
1238 Source source = addSource(EngineTestCase.createSource([
1239 "class A {",
1240 " var f;",
1241 "}",
1242 "class B {",
1243 " var v;",
1244 " B() : v = new A().f;",
1245 "}"]));
1246 resolve(source);
1247 assertNoErrors(source);
1248 verify([source]);
1249 }
1250
1251 void test_implicitThisReferenceInInitializer_staticField_thisClass() {
1252 Source source = addSource(EngineTestCase.createSource([
1253 "class A {",
1254 " var v;",
1255 " A() : v = f;",
1256 " static var f;",
1257 "}"]));
1258 resolve(source);
1259 assertNoErrors(source);
1260 verify([source]);
1261 }
1262
1263 void test_implicitThisReferenceInInitializer_staticGetter() {
1264 Source source = addSource(EngineTestCase.createSource([
1265 "class A {",
1266 " var v;",
1267 " A() : v = f;",
1268 " static get f => 42;",
1269 "}"]));
1270 resolve(source);
1271 assertNoErrors(source);
1272 verify([source]);
1273 }
1274
1275 void test_implicitThisReferenceInInitializer_staticMethod() {
1276 Source source = addSource(EngineTestCase.createSource([
1277 "class A {",
1278 " var v;",
1279 " A() : v = f();",
1280 " static f() => 42;",
1281 "}"]));
1282 resolve(source);
1283 assertNoErrors(source);
1284 verify([source]);
1285 }
1286
1287 void test_implicitThisReferenceInInitializer_topLevelField() {
1288 Source source = addSource(EngineTestCase.createSource([
1289 "class A {",
1290 " var v;",
1291 " A() : v = f;",
1292 "}",
1293 "var f = 42;"]));
1294 resolve(source);
1295 assertNoErrors(source);
1296 verify([source]);
1297 }
1298
1299 void test_implicitThisReferenceInInitializer_topLevelFunction() {
1300 Source source = addSource(EngineTestCase.createSource([
1301 "class A {",
1302 " var v;",
1303 " A() : v = f();",
1304 "}",
1305 "f() => 42;"]));
1306 resolve(source);
1307 assertNoErrors(source);
1308 verify([source]);
1309 }
1310
1311 void test_implicitThisReferenceInInitializer_topLevelGetter() {
1312 Source source = addSource(EngineTestCase.createSource([
1313 "class A {",
1314 " var v;",
1315 " A() : v = f;",
1316 "}",
1317 "get f => 42;"]));
1318 resolve(source);
1319 assertNoErrors(source);
1320 verify([source]);
1321 }
1322
1323 void test_implicitThisReferenceInInitializer_typeParameter() {
1324 Source source = addSource(EngineTestCase.createSource(["class A<T> {", " va r v;", " A(p) : v = (p is T);", "}"]));
1325 resolve(source);
1326 assertNoErrors(source);
1327 verify([source]);
1328 }
1329
1330 void test_importDuplicatedLibraryName() {
1331 Source source = addSource(EngineTestCase.createSource([
1332 "library test;",
1333 "import 'lib.dart';",
1334 "import 'lib.dart';"]));
1335 addNamedSource("/lib.dart", "library lib;");
1336 resolve(source);
1337 assertErrors(source, [
1338 HintCode.UNUSED_IMPORT,
1339 HintCode.UNUSED_IMPORT,
1340 HintCode.DUPLICATE_IMPORT]);
1341 verify([source]);
1342 }
1343
1344 void test_importOfNonLibrary_libraryDeclared() {
1345 Source source = addSource(EngineTestCase.createSource(["library lib;", "impo rt 'part.dart';", "A a;"]));
1346 addNamedSource("/part.dart", EngineTestCase.createSource(["library lib1;", " class A {}"]));
1347 resolve(source);
1348 assertNoErrors(source);
1349 verify([source]);
1350 }
1351
1352 void test_importOfNonLibrary_libraryNotDeclared() {
1353 Source source = addSource(EngineTestCase.createSource(["library lib;", "impo rt 'part.dart';", "A a;"]));
1354 addNamedSource("/part.dart", EngineTestCase.createSource(["class A {}"]));
1355 resolve(source);
1356 assertNoErrors(source);
1357 verify([source]);
1358 }
1359
1360 void test_importPrefixes_withFirstLetterDifference() {
1361 Source source = addSource(EngineTestCase.createSource([
1362 "library L;",
1363 "import 'lib1.dart' as math;",
1364 "import 'lib2.dart' as path;",
1365 "main() {",
1366 " math.test1();",
1367 " path.test2();",
1368 "}"]));
1369 addNamedSource("/lib1.dart", EngineTestCase.createSource(["library lib1;", " test1() {}"]));
1370 addNamedSource("/lib2.dart", EngineTestCase.createSource(["library lib2;", " test2() {}"]));
1371 resolve(source);
1372 assertNoErrors(source);
1373 verify([source]);
1374 }
1375
1376 void test_inconsistentCaseExpressionTypes() {
1377 Source source = addSource(EngineTestCase.createSource([
1378 "f(var p) {",
1379 " switch (p) {",
1380 " case 1:",
1381 " break;",
1382 " case 2:",
1383 " break;",
1384 " }",
1385 "}"]));
1386 resolve(source);
1387 assertNoErrors(source);
1388 verify([source]);
1389 }
1390
1391 void test_inconsistentMethodInheritance_accessors_typeParameter2() {
1392 Source source = addSource(EngineTestCase.createSource([
1393 "abstract class A<E> {",
1394 " E get x {return null;}",
1395 "}",
1396 "class B<E> {",
1397 " E get x {return null;}",
1398 "}",
1399 "class C<E> extends A<E> implements B<E> {}"]));
1400 resolve(source);
1401 assertNoErrors(source);
1402 verify([source]);
1403 }
1404
1405 void test_inconsistentMethodInheritance_accessors_typeParameters_diamond() {
1406 Source source = addSource(EngineTestCase.createSource([
1407 "abstract class F<E> extends B<E> {}",
1408 "class D<E> extends F<E> {",
1409 " external E get g;",
1410 "}",
1411 "abstract class C<E> {",
1412 " E get g;",
1413 "}",
1414 "abstract class B<E> implements C<E> {",
1415 " E get g { return null; }",
1416 "}",
1417 "class A<E> extends B<E> implements D<E> {",
1418 "}"]));
1419 resolve(source);
1420 assertNoErrors(source);
1421 verify([source]);
1422 }
1423
1424 void test_inconsistentMethodInheritance_accessors_typeParameters1() {
1425 Source source = addSource(EngineTestCase.createSource([
1426 "abstract class A<E> {",
1427 " E get x;",
1428 "}",
1429 "abstract class B<E> {",
1430 " E get x;",
1431 "}",
1432 "class C<E> implements A<E>, B<E> {",
1433 " E get x => null;",
1434 "}"]));
1435 resolve(source);
1436 assertNoErrors(source);
1437 verify([source]);
1438 }
1439
1440 void test_inconsistentMethodInheritance_methods_typeParameter2() {
1441 Source source = addSource(EngineTestCase.createSource([
1442 "class A<E> {",
1443 " x(E e) {}",
1444 "}",
1445 "class B<E> {",
1446 " x(E e) {}",
1447 "}",
1448 "class C<E> extends A<E> implements B<E> {",
1449 " x(E e) {}",
1450 "}"]));
1451 resolve(source);
1452 assertNoErrors(source);
1453 verify([source]);
1454 }
1455
1456 void test_inconsistentMethodInheritance_methods_typeParameters1() {
1457 Source source = addSource(EngineTestCase.createSource([
1458 "class A<E> {",
1459 " x(E e) {}",
1460 "}",
1461 "class B<E> {",
1462 " x(E e) {}",
1463 "}",
1464 "class C<E> implements A<E>, B<E> {",
1465 " x(E e) {}",
1466 "}"]));
1467 resolve(source);
1468 assertNoErrors(source);
1469 verify([source]);
1470 }
1471
1472 void test_inconsistentMethodInheritance_overrideTrumpsInherits_getter() {
1473 // 16134
1474 Source source = addSource(EngineTestCase.createSource([
1475 "class B<S> {",
1476 " S get g => null;",
1477 "}",
1478 "abstract class I<U> {",
1479 " U get g => null;",
1480 "}",
1481 "class C extends B<double> implements I<int> {",
1482 " num get g => null;",
1483 "}"]));
1484 resolve(source);
1485 assertNoErrors(source);
1486 verify([source]);
1487 }
1488
1489 void test_inconsistentMethodInheritance_overrideTrumpsInherits_method() {
1490 // 16134
1491 Source source = addSource(EngineTestCase.createSource([
1492 "class B<S> {",
1493 " m(S s) => null;",
1494 "}",
1495 "abstract class I<U> {",
1496 " m(U u) => null;",
1497 "}",
1498 "class C extends B<double> implements I<int> {",
1499 " m(num n) => null;",
1500 "}"]));
1501 resolve(source);
1502 assertNoErrors(source);
1503 verify([source]);
1504 }
1505
1506 void test_inconsistentMethodInheritance_overrideTrumpsInherits_setter() {
1507 // 16134
1508 Source source = addSource(EngineTestCase.createSource([
1509 "class B<S> {",
1510 " set t(S s) {}",
1511 "}",
1512 "abstract class I<U> {",
1513 " set t(U u) {}",
1514 "}",
1515 "class C extends B<double> implements I<int> {",
1516 " set t(num n) {}",
1517 "}"]));
1518 resolve(source);
1519 assertNoErrors(source);
1520 verify([source]);
1521 }
1522
1523 void test_inconsistentMethodInheritance_simple() {
1524 Source source = addSource(EngineTestCase.createSource([
1525 "abstract class A {",
1526 " x();",
1527 "}",
1528 "abstract class B {",
1529 " x();",
1530 "}",
1531 "class C implements A, B {",
1532 " x() {}",
1533 "}"]));
1534 resolve(source);
1535 assertNoErrors(source);
1536 verify([source]);
1537 }
1538
1539 void test_initializingFormalForNonExistentField() {
1540 Source source = addSource(EngineTestCase.createSource(["class A {", " int x ;", " A(this.x) {}", "}"]));
1541 resolve(source);
1542 assertNoErrors(source);
1543 verify([source]);
1544 }
1545
1546 void test_instanceAccessToStaticMember_fromComment() {
1547 Source source = addSource(EngineTestCase.createSource([
1548 "class A {",
1549 " static m() {}",
1550 "}",
1551 "/// [A.m]",
1552 "main() {",
1553 "}"]));
1554 resolve(source);
1555 assertNoErrors(source);
1556 verify([source]);
1557 }
1558
1559 void test_instanceAccessToStaticMember_topLevel() {
1560 Source source = addSource(EngineTestCase.createSource(["m() {}", "main() {", " m();", "}"]));
1561 resolve(source);
1562 assertNoErrors(source);
1563 verify([source]);
1564 }
1565
1566 void test_instanceMemberAccessFromStatic_fromComment() {
1567 Source source = addSource(EngineTestCase.createSource([
1568 "class A {",
1569 " m() {}",
1570 " /// [m]",
1571 " static foo() {",
1572 " }",
1573 "}"]));
1574 resolve(source);
1575 assertNoErrors(source);
1576 verify([source]);
1577 }
1578
1579 void test_instanceMethodNameCollidesWithSuperclassStatic_field() {
1580 Source source = addSource(EngineTestCase.createSource([
1581 "import 'lib.dart';",
1582 "class B extends A {",
1583 " _m() {}",
1584 "}"]));
1585 addNamedSource("/lib.dart", EngineTestCase.createSource(["library L;", "clas s A {", " static var _m;", "}"]));
1586 resolve(source);
1587 assertNoErrors(source);
1588 verify([source]);
1589 }
1590
1591 void test_instanceMethodNameCollidesWithSuperclassStatic_method() {
1592 Source source = addSource(EngineTestCase.createSource([
1593 "import 'lib.dart';",
1594 "class B extends A {",
1595 " _m() {}",
1596 "}"]));
1597 addNamedSource("/lib.dart", EngineTestCase.createSource(["library L;", "clas s A {", " static _m() {}", "}"]));
1598 resolve(source);
1599 assertErrors(source, []);
1600 verify([source]);
1601 }
1602
1603 void test_invalidAnnotation_constantVariable_field() {
1604 Source source = addSource(EngineTestCase.createSource(["@A.C", "class A {", " static const C = 0;", "}"]));
1605 resolve(source);
1606 assertNoErrors(source);
1607 verify([source]);
1608 }
1609
1610 void test_invalidAnnotation_constantVariable_field_importWithPrefix() {
1611 addNamedSource("/lib.dart", EngineTestCase.createSource(["library lib;", "cl ass A {", " static const C = 0;", "}"]));
1612 Source source = addSource(EngineTestCase.createSource(["import 'lib.dart' as p;", "@p.A.C", "main() {", "}"]));
1613 resolve(source);
1614 assertNoErrors(source);
1615 verify([source]);
1616 }
1617
1618 void test_invalidAnnotation_constantVariable_topLevel() {
1619 Source source = addSource(EngineTestCase.createSource(["const C = 0;", "@C", "main() {", "}"]));
1620 resolve(source);
1621 assertNoErrors(source);
1622 verify([source]);
1623 }
1624
1625 void test_invalidAnnotation_constantVariable_topLevel_importWithPrefix() {
1626 addNamedSource("/lib.dart", EngineTestCase.createSource(["library lib;", "co nst C = 0;"]));
1627 Source source = addSource(EngineTestCase.createSource(["import 'lib.dart' as p;", "@p.C", "main() {", "}"]));
1628 resolve(source);
1629 assertNoErrors(source);
1630 verify([source]);
1631 }
1632
1633 void test_invalidAnnotation_constConstructor_importWithPrefix() {
1634 addNamedSource("/lib.dart", EngineTestCase.createSource(["library lib;", "cl ass A {", " const A(int p);", "}"]));
1635 Source source = addSource(EngineTestCase.createSource(["import 'lib.dart' as p;", "@p.A(42)", "main() {", "}"]));
1636 resolve(source);
1637 assertNoErrors(source);
1638 verify([source]);
1639 }
1640
1641 void test_invalidAnnotation_constConstructor_named_importWithPrefix() {
1642 addNamedSource("/lib.dart", EngineTestCase.createSource([
1643 "library lib;",
1644 "class A {",
1645 " const A.named(int p);",
1646 "}"]));
1647 Source source = addSource(EngineTestCase.createSource([
1648 "import 'lib.dart' as p;",
1649 "@p.A.named(42)",
1650 "main() {",
1651 "}"]));
1652 resolve(source);
1653 assertNoErrors(source);
1654 verify([source]);
1655 }
1656
1657 void test_invalidAssignment() {
1658 Source source = addSource(EngineTestCase.createSource(["f() {", " var x;", " var y;", " x = y;", "}"]));
1659 resolve(source);
1660 assertNoErrors(source);
1661 verify([source]);
1662 }
1663
1664 void test_invalidAssignment_compoundAssignment() {
1665 Source source = addSource(EngineTestCase.createSource([
1666 "class byte {",
1667 " int _value;",
1668 " byte(this._value);",
1669 " byte operator +(int val) { return this; }",
1670 "}",
1671 "",
1672 "void main() {",
1673 " byte b = new byte(52);",
1674 " b += 3;",
1675 "}"]));
1676 resolve(source);
1677 assertNoErrors(source);
1678 verify([source]);
1679 }
1680
1681 void test_invalidAssignment_defaultValue_named() {
1682 Source source = addSource(EngineTestCase.createSource(["f({String x: '0'}) { ", "}"]));
1683 resolve(source);
1684 assertNoErrors(source);
1685 verify([source]);
1686 }
1687
1688 void test_invalidAssignment_defaultValue_optional() {
1689 Source source = addSource(EngineTestCase.createSource(["f([String x = '0']) {", "}"]));
1690 resolve(source);
1691 assertNoErrors(source);
1692 verify([source]);
1693 }
1694
1695 void test_invalidAssignment_implicitlyImplementFunctionViaCall_1() {
1696 // 18341
1697 //
1698 // This test and 'test_invalidAssignment_implicitlyImplementFunctionViaCall_ 2()'
1699 // are closely related: here we see that 'I' checks as a subtype of 'IntToIn t'.
1700 Source source = addSource(EngineTestCase.createSource([
1701 "class I {",
1702 " int call(int x) => 0;",
1703 "}",
1704 "class C implements I {",
1705 " noSuchMethod(_) => null;",
1706 "}",
1707 "typedef int IntToInt(int x);",
1708 "IntToInt f = new I();"]));
1709 resolve(source);
1710 assertNoErrors(source);
1711 verify([source]);
1712 }
1713
1714 void test_invalidAssignment_implicitlyImplementFunctionViaCall_2() {
1715 // 18341
1716 //
1717 // Here 'C' checks as a subtype of 'I', but 'C' does not
1718 // check as a subtype of 'IntToInt'. Together with
1719 // 'test_invalidAssignment_implicitlyImplementFunctionViaCall_1()' we see
1720 // that subtyping is not transitive here.
1721 Source source = addSource(EngineTestCase.createSource([
1722 "class I {",
1723 " int call(int x) => 0;",
1724 "}",
1725 "class C implements I {",
1726 " noSuchMethod(_) => null;",
1727 "}",
1728 "typedef int IntToInt(int x);",
1729 "IntToInt f = new C();"]));
1730 resolve(source);
1731 assertNoErrors(source);
1732 verify([source]);
1733 }
1734
1735 void test_invalidAssignment_implicitlyImplementFunctionViaCall_3() {
1736 // 18341
1737 //
1738 // Like 'test_invalidAssignment_implicitlyImplementFunctionViaCall_2()',
1739 // but uses type 'Function' instead of more precise type 'IntToInt' for 'f'.
1740 Source source = addSource(EngineTestCase.createSource([
1741 "class I {",
1742 " int call(int x) => 0;",
1743 "}",
1744 "class C implements I {",
1745 " noSuchMethod(_) => null;",
1746 "}",
1747 "typedef int IntToInt(int x);",
1748 "Function f = new C();"]));
1749 resolve(source);
1750 assertNoErrors(source);
1751 verify([source]);
1752 }
1753
1754 void test_invalidAssignment_implicitlyImplementFunctionViaCall_4() {
1755 // 18341
1756 //
1757 // Like 'test_invalidAssignment_implicitlyImplementFunctionViaCall_2()',
1758 // but uses type 'VoidToInt' instead of more precise type 'IntToInt' for 'f' .
1759 //
1760 // Here 'C <: IntToInt <: VoidToInt', but the spec gives no transitivity rul e
1761 // for '<:'. However, many of the :/tools/test.py tests assume this transiti vity
1762 // for 'JsBuilder' objects, assigning them to '(String) -> dynamic'. The dec lared type of
1763 // 'JsBuilder.call' is '(String, [dynamic]) -> Expression'.
1764 Source source = addSource(EngineTestCase.createSource([
1765 "class I {",
1766 " int call([int x]) => 0;",
1767 "}",
1768 "class C implements I {",
1769 " noSuchMethod(_) => null;",
1770 "}",
1771 "typedef int VoidToInt();",
1772 "VoidToInt f = new C();"]));
1773 resolve(source);
1774 assertNoErrors(source);
1775 verify([source]);
1776 }
1777
1778 void test_invalidAssignment_toDynamic() {
1779 Source source = addSource(EngineTestCase.createSource(["f() {", " var g;", " g = () => 0;", "}"]));
1780 resolve(source);
1781 assertNoErrors(source);
1782 verify([source]);
1783 }
1784
1785 void test_invalidFactoryNameNotAClass() {
1786 Source source = addSource(EngineTestCase.createSource(["class A {", " facto ry A() {}", "}"]));
1787 resolve(source);
1788 assertNoErrors(source);
1789 verify([source]);
1790 }
1791
1792 void test_invalidIdentifierInAsync() {
1793 Source source = addSource(EngineTestCase.createSource([
1794 "class A {",
1795 " m() {",
1796 " int async;",
1797 " int await;",
1798 " int yield;",
1799 " }",
1800 "}"]));
1801 resolve(source);
1802 assertNoErrors(source);
1803 verify([source]);
1804 }
1805
1806 void test_invalidMethodOverrideNamedParamType() {
1807 Source source = addSource(EngineTestCase.createSource([
1808 "class A {",
1809 " m({int a}) {}",
1810 "}",
1811 "class B implements A {",
1812 " m({int a, int b}) {}",
1813 "}"]));
1814 resolve(source);
1815 assertNoErrors(source);
1816 verify([source]);
1817 }
1818
1819 void test_invalidOverrideDifferentDefaultValues_named() {
1820 Source source = addSource(EngineTestCase.createSource([
1821 "class A {",
1822 " m({int p : 0}) {}",
1823 "}",
1824 "class B extends A {",
1825 " m({int p : 0}) {}",
1826 "}"]));
1827 resolve(source);
1828 assertNoErrors(source);
1829 verify([source]);
1830 }
1831
1832 void test_invalidOverrideDifferentDefaultValues_named_function() {
1833 Source source = addSource(EngineTestCase.createSource([
1834 "nothing() => 'nothing';",
1835 "class A {",
1836 " thing(String a, {orElse : nothing}) {}",
1837 "}",
1838 "class B extends A {",
1839 " thing(String a, {orElse : nothing}) {}",
1840 "}"]));
1841 resolve(source);
1842 assertNoErrors(source);
1843 verify([source]);
1844 }
1845
1846 void test_invalidOverrideDifferentDefaultValues_positional() {
1847 Source source = addSource(EngineTestCase.createSource([
1848 "class A {",
1849 " m([int p = 0]) {}",
1850 "}",
1851 "class B extends A {",
1852 " m([int p = 0]) {}",
1853 "}"]));
1854 resolve(source);
1855 assertNoErrors(source);
1856 verify([source]);
1857 }
1858
1859 void test_invalidOverrideDifferentDefaultValues_positional_changedOrder() {
1860 Source source = addSource(EngineTestCase.createSource([
1861 "class A {",
1862 " m([int a = 0, String b = '0']) {}",
1863 "}",
1864 "class B extends A {",
1865 " m([int b = 0, String a = '0']) {}",
1866 "}"]));
1867 resolve(source);
1868 assertNoErrors(source);
1869 verify([source]);
1870 }
1871
1872 void test_invalidOverrideDifferentDefaultValues_positional_function() {
1873 Source source = addSource(EngineTestCase.createSource([
1874 "nothing() => 'nothing';",
1875 "class A {",
1876 " thing(String a, [orElse = nothing]) {}",
1877 "}",
1878 "class B extends A {",
1879 " thing(String a, [orElse = nothing]) {}",
1880 "}"]));
1881 resolve(source);
1882 assertNoErrors(source);
1883 verify([source]);
1884 }
1885
1886 void test_invalidOverrideNamed_unorderedNamedParameter() {
1887 Source source = addSource(EngineTestCase.createSource([
1888 "class A {",
1889 " m({a, b}) {}",
1890 "}",
1891 "class B extends A {",
1892 " m({b, a}) {}",
1893 "}"]));
1894 resolve(source);
1895 assertNoErrors(source);
1896 verify([source]);
1897 }
1898
1899 void test_invalidOverrideRequired_less() {
1900 Source source = addSource(EngineTestCase.createSource([
1901 "class A {",
1902 " m(a, b) {}",
1903 "}",
1904 "class B extends A {",
1905 " m(a, [b]) {}",
1906 "}"]));
1907 resolve(source);
1908 assertNoErrors(source);
1909 verify([source]);
1910 }
1911
1912 void test_invalidOverrideRequired_same() {
1913 Source source = addSource(EngineTestCase.createSource([
1914 "class A {",
1915 " m(a) {}",
1916 "}",
1917 "class B extends A {",
1918 " m(a) {}",
1919 "}"]));
1920 resolve(source);
1921 assertNoErrors(source);
1922 verify([source]);
1923 }
1924
1925 void test_invalidOverrideReturnType_returnType_interface() {
1926 Source source = addNamedSource("/test.dart", EngineTestCase.createSource([
1927 "abstract class A {",
1928 " num m();",
1929 "}",
1930 "class B implements A {",
1931 " int m() { return 1; }",
1932 "}"]));
1933 resolve(source);
1934 assertNoErrors(source);
1935 verify([source]);
1936 }
1937
1938 void test_invalidOverrideReturnType_returnType_interface2() {
1939 Source source = addNamedSource("/test.dart", EngineTestCase.createSource([
1940 "abstract class A {",
1941 " num m();",
1942 "}",
1943 "abstract class B implements A {",
1944 "}",
1945 "class C implements B {",
1946 " int m() { return 1; }",
1947 "}"]));
1948 resolve(source);
1949 assertNoErrors(source);
1950 verify([source]);
1951 }
1952
1953 void test_invalidOverrideReturnType_returnType_mixin() {
1954 Source source = addNamedSource("/test.dart", EngineTestCase.createSource([
1955 "class A {",
1956 " num m() { return 0; }",
1957 "}",
1958 "class B extends Object with A {",
1959 " int m() { return 1; }",
1960 "}"]));
1961 resolve(source);
1962 assertNoErrors(source);
1963 verify([source]);
1964 }
1965
1966 void test_invalidOverrideReturnType_returnType_parameterizedTypes() {
1967 Source source = addSource(EngineTestCase.createSource([
1968 "abstract class A<E> {",
1969 " List<E> m();",
1970 "}",
1971 "class B extends A<dynamic> {",
1972 " List<dynamic> m() { return new List<dynamic>(); }",
1973 "}"]));
1974 resolve(source);
1975 assertNoErrors(source);
1976 verify([source]);
1977 }
1978
1979 void test_invalidOverrideReturnType_returnType_sameType() {
1980 Source source = addNamedSource("/test.dart", EngineTestCase.createSource([
1981 "class A {",
1982 " int m() { return 0; }",
1983 "}",
1984 "class B extends A {",
1985 " int m() { return 1; }",
1986 "}"]));
1987 resolve(source);
1988 assertNoErrors(source);
1989 verify([source]);
1990 }
1991
1992 void test_invalidOverrideReturnType_returnType_superclass() {
1993 Source source = addNamedSource("/test.dart", EngineTestCase.createSource([
1994 "class A {",
1995 " num m() { return 0; }",
1996 "}",
1997 "class B extends A {",
1998 " int m() { return 1; }",
1999 "}"]));
2000 resolve(source);
2001 assertNoErrors(source);
2002 verify([source]);
2003 }
2004
2005 void test_invalidOverrideReturnType_returnType_superclass2() {
2006 Source source = addNamedSource("/test.dart", EngineTestCase.createSource([
2007 "class A {",
2008 " num m() { return 0; }",
2009 "}",
2010 "class B extends A {",
2011 "}",
2012 "class C extends B {",
2013 " int m() { return 1; }",
2014 "}"]));
2015 resolve(source);
2016 assertNoErrors(source);
2017 verify([source]);
2018 }
2019
2020 void test_invalidOverrideReturnType_returnType_void() {
2021 Source source = addSource(EngineTestCase.createSource([
2022 "class A {",
2023 " void m() {}",
2024 "}",
2025 "class B extends A {",
2026 " int m() { return 0; }",
2027 "}"]));
2028 resolve(source);
2029 assertNoErrors(source);
2030 verify([source]);
2031 }
2032
2033 void test_invalidReferenceToThis_constructor() {
2034 Source source = addSource(EngineTestCase.createSource(["class A {", " A() { ", " var v = this;", " }", "}"]));
2035 resolve(source);
2036 assertNoErrors(source);
2037 verify([source]);
2038 }
2039
2040 void test_invalidReferenceToThis_instanceMethod() {
2041 Source source = addSource(EngineTestCase.createSource(["class A {", " m() { ", " var v = this;", " }", "}"]));
2042 resolve(source);
2043 assertNoErrors(source);
2044 verify([source]);
2045 }
2046
2047 void test_invalidTypeArgumentForKey() {
2048 Source source = addSource(EngineTestCase.createSource([
2049 "class A {",
2050 " m() {",
2051 " return const <int, int>{};",
2052 " }",
2053 "}"]));
2054 resolve(source);
2055 assertNoErrors(source);
2056 verify([source]);
2057 }
2058
2059 void test_invalidTypeArgumentInConstList() {
2060 Source source = addSource(EngineTestCase.createSource([
2061 "class A<E> {",
2062 " m() {",
2063 " return <E>[];",
2064 " }",
2065 "}"]));
2066 resolve(source);
2067 assertNoErrors(source);
2068 verify([source]);
2069 }
2070
2071 void test_invalidTypeArgumentInConstMap() {
2072 Source source = addSource(EngineTestCase.createSource([
2073 "class A<E> {",
2074 " m() {",
2075 " return <String, E>{};",
2076 " }",
2077 "}"]));
2078 resolve(source);
2079 assertNoErrors(source);
2080 verify([source]);
2081 }
2082
2083 void test_invocationOfNonFunction_dynamic() {
2084 Source source = addSource(EngineTestCase.createSource([
2085 "class A {",
2086 " var f;",
2087 "}",
2088 "class B extends A {",
2089 " g() {",
2090 " f();",
2091 " }",
2092 "}"]));
2093 resolve(source);
2094 assertNoErrors(source);
2095 verify([source]);
2096 }
2097
2098 void test_invocationOfNonFunction_getter() {
2099 Source source = addSource(EngineTestCase.createSource([
2100 "class A {",
2101 " var g;",
2102 "}",
2103 "f() {",
2104 " A a;",
2105 " a.g();",
2106 "}"]));
2107 resolve(source);
2108 assertNoErrors(source);
2109 verify([source]);
2110 }
2111
2112 void test_invocationOfNonFunction_localVariable() {
2113 Source source = addSource(EngineTestCase.createSource(["f() {", " var g;", " g();", "}"]));
2114 resolve(source);
2115 assertNoErrors(source);
2116 verify([source]);
2117 }
2118
2119 void test_invocationOfNonFunction_localVariable_dynamic() {
2120 Source source = addSource(EngineTestCase.createSource(["f() {}", "main() {", " var v = f;", " v();", "}"]));
2121 resolve(source);
2122 assertNoErrors(source);
2123 verify([source]);
2124 }
2125
2126 void test_invocationOfNonFunction_localVariable_dynamic2() {
2127 Source source = addSource(EngineTestCase.createSource([
2128 "f() {}",
2129 "main() {",
2130 " var v = f;",
2131 " v = 1;",
2132 " v();",
2133 "}"]));
2134 resolve(source);
2135 assertNoErrors(source);
2136 verify([source]);
2137 }
2138
2139 void test_invocationOfNonFunction_Object() {
2140 Source source = addSource(EngineTestCase.createSource(["main() {", " Object v = null;", " v();", "}"]));
2141 resolve(source);
2142 assertNoErrors(source);
2143 verify([source]);
2144 }
2145
2146 void test_invocationOfNonFunction_proxyOnFunctionClass() {
2147 // 16078
2148 Source source = addSource(EngineTestCase.createSource([
2149 "@proxy",
2150 "class Functor implements Function {",
2151 " noSuchMethod(inv) {",
2152 " return 42;",
2153 " }",
2154 "}",
2155 "main() {",
2156 " Functor f = new Functor();",
2157 " f();",
2158 "}"]));
2159 resolve(source);
2160 assertErrors(source, []);
2161 verify([source]);
2162 }
2163
2164 void test_listElementTypeNotAssignable() {
2165 Source source = addSource(EngineTestCase.createSource(["var v1 = <int> [42]; ", "var v2 = const <int> [42];"]));
2166 resolve(source);
2167 assertNoErrors(source);
2168 verify([source]);
2169 }
2170
2171 void test_loadLibraryDefined() {
2172 resolveWithAndWithoutExperimental(<String> [
2173 EngineTestCase.createSource(["library lib1;", "foo() => 22;"]),
2174 EngineTestCase.createSource([
2175 "import 'lib1.dart' deferred as other;",
2176 "main() {",
2177 " other.loadLibrary().then((_) => other.foo());",
2178 "}"])], <ErrorCode> [
2179 ParserErrorCode.DEFERRED_IMPORTS_NOT_SUPPORTED,
2180 StaticTypeWarningCode.UNDEFINED_FUNCTION], <ErrorCode> []);
2181 }
2182
2183 void test_mapKeyTypeNotAssignable() {
2184 Source source = addSource(EngineTestCase.createSource(["var v = <String, int > {'a' : 1};"]));
2185 resolve(source);
2186 assertNoErrors(source);
2187 verify([source]);
2188 }
2189
2190 void test_memberWithClassName_setter() {
2191 Source source = addSource(EngineTestCase.createSource(["class A {", " set A (v) {}", "}"]));
2192 resolve(source);
2193 assertNoErrors(source);
2194 verify([source]);
2195 }
2196
2197 void test_methodDeclaration_scope_signature() {
2198 Source source = addSource(EngineTestCase.createSource([
2199 "const app = 0;",
2200 "class A {",
2201 " foo(@app int app) {}",
2202 "}"]));
2203 resolve(source);
2204 assertNoErrors(source);
2205 verify([source]);
2206 }
2207
2208 void test_misMatchedGetterAndSetterTypes_instance_sameTypes() {
2209 Source source = addSource(EngineTestCase.createSource([
2210 "class C {",
2211 " int get x => 0;",
2212 " set x(int v) {}",
2213 "}"]));
2214 resolve(source);
2215 assertNoErrors(source);
2216 verify([source]);
2217 }
2218
2219 void test_misMatchedGetterAndSetterTypes_instance_unspecifiedGetter() {
2220 Source source = addSource(EngineTestCase.createSource(["class C {", " get x => 0;", " set x(String v) {}", "}"]));
2221 resolve(source);
2222 assertNoErrors(source);
2223 verify([source]);
2224 }
2225
2226 void test_misMatchedGetterAndSetterTypes_instance_unspecifiedSetter() {
2227 Source source = addSource(EngineTestCase.createSource(["class C {", " int g et x => 0;", " set x(v) {}", "}"]));
2228 resolve(source);
2229 assertNoErrors(source);
2230 verify([source]);
2231 }
2232
2233 void test_misMatchedGetterAndSetterTypes_topLevel_sameTypes() {
2234 Source source = addSource(EngineTestCase.createSource(["int get x => 0;", "s et x(int v) {}"]));
2235 resolve(source);
2236 assertNoErrors(source);
2237 verify([source]);
2238 }
2239
2240 void test_misMatchedGetterAndSetterTypes_topLevel_unspecifiedGetter() {
2241 Source source = addSource(EngineTestCase.createSource(["get x => 0;", "set x (String v) {}"]));
2242 resolve(source);
2243 assertNoErrors(source);
2244 verify([source]);
2245 }
2246
2247 void test_misMatchedGetterAndSetterTypes_topLevel_unspecifiedSetter() {
2248 Source source = addSource(EngineTestCase.createSource(["int get x => 0;", "s et x(v) {}"]));
2249 resolve(source);
2250 assertNoErrors(source);
2251 verify([source]);
2252 }
2253
2254 void test_missingEnumConstantInSwitch_all() {
2255 AnalysisOptionsImpl analysisOptions = new AnalysisOptionsImpl();
2256 analysisOptions.enableEnum = true;
2257 resetWithOptions(analysisOptions);
2258 Source source = addSource(EngineTestCase.createSource([
2259 "enum E { A, B, C }",
2260 "",
2261 "f(E e) {",
2262 " switch (e) {",
2263 " case E.A: break;",
2264 " case E.B: break;",
2265 " case E.C: break;",
2266 " }",
2267 "}"]));
2268 resolve(source);
2269 assertNoErrors(source);
2270 verify([source]);
2271 }
2272
2273 void test_missingEnumConstantInSwitch_default() {
2274 AnalysisOptionsImpl analysisOptions = new AnalysisOptionsImpl();
2275 analysisOptions.enableEnum = true;
2276 resetWithOptions(analysisOptions);
2277 Source source = addSource(EngineTestCase.createSource([
2278 "enum E { A, B, C }",
2279 "",
2280 "f(E e) {",
2281 " switch (e) {",
2282 " case E.B: break;",
2283 " default: break;",
2284 " }",
2285 "}"]));
2286 resolve(source);
2287 assertNoErrors(source);
2288 verify([source]);
2289 }
2290
2291 void test_mixedReturnTypes_differentScopes() {
2292 Source source = addSource(EngineTestCase.createSource([
2293 "class C {",
2294 " m(int x) {",
2295 " f(int y) {",
2296 " return;",
2297 " }",
2298 " f(x);",
2299 " return 0;",
2300 " }",
2301 "}"]));
2302 resolve(source);
2303 assertNoErrors(source);
2304 verify([source]);
2305 }
2306
2307 void test_mixedReturnTypes_ignoreImplicit() {
2308 Source source = addSource(EngineTestCase.createSource([
2309 "f(bool p) {",
2310 " if (p) return 42;",
2311 " // implicit 'return;' is ignored",
2312 "}"]));
2313 resolve(source);
2314 assertNoErrors(source);
2315 verify([source]);
2316 }
2317
2318 void test_mixedReturnTypes_ignoreImplicit2() {
2319 Source source = addSource(EngineTestCase.createSource([
2320 "f(bool p) {",
2321 " if (p) {",
2322 " return 42;",
2323 " } else {",
2324 " return 42;",
2325 " }",
2326 " // implicit 'return;' is ignored",
2327 "}"]));
2328 resolve(source);
2329 assertNoErrors(source);
2330 verify([source]);
2331 }
2332
2333 void test_mixedReturnTypes_sameKind() {
2334 Source source = addSource(EngineTestCase.createSource([
2335 "class C {",
2336 " m(int x) {",
2337 " if (x < 0) {",
2338 " return 1;",
2339 " }",
2340 " return 0;",
2341 " }",
2342 "}"]));
2343 resolve(source);
2344 assertNoErrors(source);
2345 verify([source]);
2346 }
2347
2348 void test_mixinDeclaresConstructor() {
2349 Source source = addSource(EngineTestCase.createSource([
2350 "class A {",
2351 " m() {}",
2352 "}",
2353 "class B extends Object with A {}"]));
2354 resolve(source);
2355 assertNoErrors(source);
2356 verify([source]);
2357 }
2358
2359 void test_mixinDeclaresConstructor_factory() {
2360 Source source = addSource(EngineTestCase.createSource([
2361 "class A {",
2362 " factory A() {}",
2363 "}",
2364 "class B extends Object with A {}"]));
2365 resolve(source);
2366 assertNoErrors(source);
2367 verify([source]);
2368 }
2369
2370 void test_mixinInheritsFromNotObject_classDeclaration_mixTypeAlias() {
2371 Source source = addSource(EngineTestCase.createSource([
2372 "class A {}",
2373 "class B = Object with A;",
2374 "class C extends Object with B {}"]));
2375 resolve(source);
2376 assertNoErrors(source);
2377 verify([source]);
2378 }
2379
2380 void test_mixinInheritsFromNotObject_typedef_mixTypeAlias() {
2381 Source source = addSource(EngineTestCase.createSource([
2382 "class A {}",
2383 "class B = Object with A;",
2384 "class C = Object with B;"]));
2385 resolve(source);
2386 assertNoErrors(source);
2387 verify([source]);
2388 }
2389
2390 void test_multipleSuperInitializers_no() {
2391 Source source = addSource(EngineTestCase.createSource(["class A {}", "class B extends A {", " B() {}", "}"]));
2392 resolve(source);
2393 assertNoErrors(source);
2394 verify([source]);
2395 }
2396
2397 void test_multipleSuperInitializers_single() {
2398 Source source = addSource(EngineTestCase.createSource([
2399 "class A {}",
2400 "class B extends A {",
2401 " B() : super() {}",
2402 "}"]));
2403 resolve(source);
2404 assertNoErrors(source);
2405 verify([source]);
2406 }
2407
2408 void test_nativeFunctionBodyInNonSDKCode_function() {
2409 Source source = addSource(EngineTestCase.createSource(["import 'dart-ext:x'; ", "int m(a) native 'string';"]));
2410 resolve(source);
2411 assertNoErrors(source);
2412 // Cannot verify the AST because the import's URI cannot be resolved.
2413 }
2414
2415 void test_newWithAbstractClass_factory() {
2416 Source source = addSource(EngineTestCase.createSource([
2417 "abstract class A {",
2418 " factory A() { return new B(); }",
2419 "}",
2420 "class B implements A {",
2421 " B() {}",
2422 "}",
2423 "A f() {",
2424 " return new A();",
2425 "}"]));
2426 resolve(source);
2427 assertNoErrors(source);
2428 verify([source]);
2429 }
2430
2431 void test_newWithUndefinedConstructor() {
2432 Source source = addSource(EngineTestCase.createSource([
2433 "class A {",
2434 " A.name() {}",
2435 "}",
2436 "f() {",
2437 " new A.name();",
2438 "}"]));
2439 resolve(source);
2440 assertNoErrors(source);
2441 verify([source]);
2442 }
2443
2444 void test_newWithUndefinedConstructorDefault() {
2445 Source source = addSource(EngineTestCase.createSource(["class A {", " A() { }", "}", "f() {", " new A();", "}"]));
2446 resolve(source);
2447 assertNoErrors(source);
2448 verify([source]);
2449 }
2450
2451 void test_nonAbstractClassInheritsAbstractMemberOne_abstractsDontOverrideConcr etes_getter() {
2452 Source source = addSource(EngineTestCase.createSource([
2453 "class A {",
2454 " int get g => 0;",
2455 "}",
2456 "abstract class B extends A {",
2457 " int get g;",
2458 "}",
2459 "class C extends B {}"]));
2460 resolve(source);
2461 assertNoErrors(source);
2462 verify([source]);
2463 }
2464
2465 void test_nonAbstractClassInheritsAbstractMemberOne_abstractsDontOverrideConcr etes_method() {
2466 Source source = addSource(EngineTestCase.createSource([
2467 "class A {",
2468 " m(p) {}",
2469 "}",
2470 "abstract class B extends A {",
2471 " m(p);",
2472 "}",
2473 "class C extends B {}"]));
2474 resolve(source);
2475 assertNoErrors(source);
2476 verify([source]);
2477 }
2478
2479 void test_nonAbstractClassInheritsAbstractMemberOne_abstractsDontOverrideConcr etes_setter() {
2480 Source source = addSource(EngineTestCase.createSource([
2481 "class A {",
2482 " set s(v) {}",
2483 "}",
2484 "abstract class B extends A {",
2485 " set s(v);",
2486 "}",
2487 "class C extends B {}"]));
2488 resolve(source);
2489 assertNoErrors(source);
2490 verify([source]);
2491 }
2492
2493 void test_nonAbstractClassInheritsAbstractMemberOne_classTypeAlias_interface() {
2494 // 15979
2495 Source source = addSource(EngineTestCase.createSource([
2496 "abstract class M {}",
2497 "abstract class A {}",
2498 "abstract class I {",
2499 " m();",
2500 "}",
2501 "abstract class B = A with M implements I;"]));
2502 resolve(source);
2503 assertNoErrors(source);
2504 verify([source]);
2505 }
2506
2507 void test_nonAbstractClassInheritsAbstractMemberOne_classTypeAlias_mixin() {
2508 // 15979
2509 Source source = addSource(EngineTestCase.createSource([
2510 "abstract class M {",
2511 " m();",
2512 "}",
2513 "abstract class A {}",
2514 "abstract class B = A with M;"]));
2515 resolve(source);
2516 assertNoErrors(source);
2517 verify([source]);
2518 }
2519
2520 void test_nonAbstractClassInheritsAbstractMemberOne_classTypeAlias_superclass( ) {
2521 // 15979
2522 Source source = addSource(EngineTestCase.createSource([
2523 "class M {}",
2524 "abstract class A {",
2525 " m();",
2526 "}",
2527 "abstract class B = A with M;"]));
2528 resolve(source);
2529 assertNoErrors(source);
2530 verify([source]);
2531 }
2532
2533 void test_nonAbstractClassInheritsAbstractMemberOne_mixin_getter() {
2534 // 17034
2535 Source source = addSource(EngineTestCase.createSource([
2536 "class A {",
2537 " var a;",
2538 "}",
2539 "abstract class M {",
2540 " get a;",
2541 "}",
2542 "class B extends A with M {}",
2543 "class C extends B {}"]));
2544 resolve(source);
2545 assertNoErrors(source);
2546 verify([source]);
2547 }
2548
2549 void test_nonAbstractClassInheritsAbstractMemberOne_mixin_method() {
2550 Source source = addSource(EngineTestCase.createSource([
2551 "class A {",
2552 " m() {}",
2553 "}",
2554 "abstract class M {",
2555 " m();",
2556 "}",
2557 "class B extends A with M {}",
2558 "class C extends B {}"]));
2559 resolve(source);
2560 assertNoErrors(source);
2561 verify([source]);
2562 }
2563
2564 void test_nonAbstractClassInheritsAbstractMemberOne_mixin_setter() {
2565 Source source = addSource(EngineTestCase.createSource([
2566 "class A {",
2567 " var a;",
2568 "}",
2569 "abstract class M {",
2570 " set a(dynamic v);",
2571 "}",
2572 "class B extends A with M {}",
2573 "class C extends B {}"]));
2574 resolve(source);
2575 assertNoErrors(source);
2576 verify([source]);
2577 }
2578
2579 void test_nonAbstractClassInheritsAbstractMemberOne_noSuchMethod_accessor() {
2580 Source source = addSource(EngineTestCase.createSource([
2581 "abstract class A {",
2582 " int get g;",
2583 "}",
2584 "class B extends A {",
2585 " noSuchMethod(v) => '';",
2586 "}"]));
2587 resolve(source);
2588 assertNoErrors(source);
2589 verify([source]);
2590 }
2591
2592 void test_nonAbstractClassInheritsAbstractMemberOne_noSuchMethod_method() {
2593 Source source = addSource(EngineTestCase.createSource([
2594 "abstract class A {",
2595 " m(p);",
2596 "}",
2597 "class B extends A {",
2598 " noSuchMethod(v) => '';",
2599 "}"]));
2600 resolve(source);
2601 assertNoErrors(source);
2602 verify([source]);
2603 }
2604
2605 void test_nonBoolExpression_functionType() {
2606 Source source = addSource(EngineTestCase.createSource([
2607 "bool makeAssertion() => true;",
2608 "f() {",
2609 " assert(makeAssertion);",
2610 "}"]));
2611 resolve(source);
2612 assertNoErrors(source);
2613 verify([source]);
2614 }
2615
2616 void test_nonBoolExpression_interfaceType() {
2617 Source source = addSource(EngineTestCase.createSource(["f() {", " assert(tr ue);", "}"]));
2618 resolve(source);
2619 assertNoErrors(source);
2620 verify([source]);
2621 }
2622
2623 void test_nonBoolNegationExpression() {
2624 Source source = addSource(EngineTestCase.createSource([
2625 "f(bool pb, pd) {",
2626 " !true;",
2627 " !false;",
2628 " !pb;",
2629 " !pd;",
2630 "}"]));
2631 resolve(source);
2632 assertNoErrors(source);
2633 verify([source]);
2634 }
2635
2636 void test_nonBoolOperand_and_bool() {
2637 Source source = addSource(EngineTestCase.createSource([
2638 "bool f(bool left, bool right) {",
2639 " return left && right;",
2640 "}"]));
2641 resolve(source);
2642 assertNoErrors(source);
2643 verify([source]);
2644 }
2645
2646 void test_nonBoolOperand_and_dynamic() {
2647 Source source = addSource(EngineTestCase.createSource([
2648 "bool f(left, dynamic right) {",
2649 " return left && right;",
2650 "}"]));
2651 resolve(source);
2652 assertNoErrors(source);
2653 verify([source]);
2654 }
2655
2656 void test_nonBoolOperand_or_bool() {
2657 Source source = addSource(EngineTestCase.createSource([
2658 "bool f(bool left, bool right) {",
2659 " return left || right;",
2660 "}"]));
2661 resolve(source);
2662 assertNoErrors(source);
2663 verify([source]);
2664 }
2665
2666 void test_nonBoolOperand_or_dynamic() {
2667 Source source = addSource(EngineTestCase.createSource([
2668 "bool f(dynamic left, right) {",
2669 " return left || right;",
2670 "}"]));
2671 resolve(source);
2672 assertNoErrors(source);
2673 verify([source]);
2674 }
2675
2676 void test_nonConstantDefaultValue_function_named() {
2677 Source source = addSource(EngineTestCase.createSource(["f({x : 2 + 3}) {}"]) );
2678 resolve(source);
2679 assertNoErrors(source);
2680 verify([source]);
2681 }
2682
2683 void test_nonConstantDefaultValue_function_positional() {
2684 Source source = addSource(EngineTestCase.createSource(["f([x = 2 + 3]) {}"]) );
2685 resolve(source);
2686 assertNoErrors(source);
2687 verify([source]);
2688 }
2689
2690 void test_nonConstantDefaultValue_inConstructor_named() {
2691 Source source = addSource(EngineTestCase.createSource(["class A {", " A({x : 2 + 3}) {}", "}"]));
2692 resolve(source);
2693 assertNoErrors(source);
2694 verify([source]);
2695 }
2696
2697 void test_nonConstantDefaultValue_inConstructor_positional() {
2698 Source source = addSource(EngineTestCase.createSource(["class A {", " A([x = 2 + 3]) {}", "}"]));
2699 resolve(source);
2700 assertNoErrors(source);
2701 verify([source]);
2702 }
2703
2704 void test_nonConstantDefaultValue_method_named() {
2705 Source source = addSource(EngineTestCase.createSource(["class A {", " m({x : 2 + 3}) {}", "}"]));
2706 resolve(source);
2707 assertNoErrors(source);
2708 verify([source]);
2709 }
2710
2711 void test_nonConstantDefaultValue_method_positional() {
2712 Source source = addSource(EngineTestCase.createSource(["class A {", " m([x = 2 + 3]) {}", "}"]));
2713 resolve(source);
2714 assertNoErrors(source);
2715 verify([source]);
2716 }
2717
2718 void test_nonConstantValueInInitializer_namedArgument() {
2719 Source source = addSource(EngineTestCase.createSource([
2720 "class A {",
2721 " final a;",
2722 " const A({this.a});",
2723 "}",
2724 "class B extends A {",
2725 " const B({b}) : super(a: b);",
2726 "}"]));
2727 resolve(source);
2728 assertNoErrors(source);
2729 verify([source]);
2730 }
2731
2732 void test_nonConstCaseExpression() {
2733 Source source = addSource(EngineTestCase.createSource([
2734 "f(Type t) {",
2735 " switch (t) {",
2736 " case bool:",
2737 " case int:",
2738 " return true;",
2739 " default:",
2740 " return false;",
2741 " }",
2742 "}"]));
2743 resolve(source);
2744 assertNoErrors(source);
2745 verify([source]);
2746 }
2747
2748 void test_nonConstMapAsExpressionStatement_const() {
2749 Source source = addSource(EngineTestCase.createSource(["f() {", " const {'a ' : 0, 'b' : 1};", "}"]));
2750 resolve(source);
2751 assertNoErrors(source);
2752 verify([source]);
2753 }
2754
2755 void test_nonConstMapAsExpressionStatement_notExpressionStatement() {
2756 Source source = addSource(EngineTestCase.createSource(["f() {", " var m = { 'a' : 0, 'b' : 1};", "}"]));
2757 resolve(source);
2758 assertNoErrors(source);
2759 verify([source]);
2760 }
2761
2762 void test_nonConstMapAsExpressionStatement_typeArguments() {
2763 Source source = addSource(EngineTestCase.createSource(["f() {", " <String, int> {'a' : 0, 'b' : 1};", "}"]));
2764 resolve(source);
2765 assertNoErrors(source);
2766 verify([source]);
2767 }
2768
2769 void test_nonConstValueInInitializer_binary_bool() {
2770 Source source = addSource(EngineTestCase.createSource([
2771 "class A {",
2772 " final v;",
2773 " const A.a1(bool p) : v = p && true;",
2774 " const A.a2(bool p) : v = true && p;",
2775 " const A.b1(bool p) : v = p || true;",
2776 " const A.b2(bool p) : v = true || p;",
2777 "}"]));
2778 resolve(source);
2779 assertErrors(source, [HintCode.DEAD_CODE]);
2780 verify([source]);
2781 }
2782
2783 void test_nonConstValueInInitializer_binary_dynamic() {
2784 Source source = addSource(EngineTestCase.createSource([
2785 "class A {",
2786 " final v;",
2787 " const A.a1(p) : v = p + 5;",
2788 " const A.a2(p) : v = 5 + p;",
2789 " const A.b1(p) : v = p - 5;",
2790 " const A.b2(p) : v = 5 - p;",
2791 " const A.c1(p) : v = p * 5;",
2792 " const A.c2(p) : v = 5 * p;",
2793 " const A.d1(p) : v = p / 5;",
2794 " const A.d2(p) : v = 5 / p;",
2795 " const A.e1(p) : v = p ~/ 5;",
2796 " const A.e2(p) : v = 5 ~/ p;",
2797 " const A.f1(p) : v = p > 5;",
2798 " const A.f2(p) : v = 5 > p;",
2799 " const A.g1(p) : v = p < 5;",
2800 " const A.g2(p) : v = 5 < p;",
2801 " const A.h1(p) : v = p >= 5;",
2802 " const A.h2(p) : v = 5 >= p;",
2803 " const A.i1(p) : v = p <= 5;",
2804 " const A.i2(p) : v = 5 <= p;",
2805 " const A.j1(p) : v = p % 5;",
2806 " const A.j2(p) : v = 5 % p;",
2807 "}"]));
2808 resolve(source);
2809 assertNoErrors(source);
2810 // operations on "p" are not resolved
2811 }
2812
2813 void test_nonConstValueInInitializer_binary_int() {
2814 Source source = addSource(EngineTestCase.createSource([
2815 "class A {",
2816 " final v;",
2817 " const A.a1(int p) : v = p ^ 5;",
2818 " const A.a2(int p) : v = 5 ^ p;",
2819 " const A.b1(int p) : v = p & 5;",
2820 " const A.b2(int p) : v = 5 & p;",
2821 " const A.c1(int p) : v = p | 5;",
2822 " const A.c2(int p) : v = 5 | p;",
2823 " const A.d1(int p) : v = p >> 5;",
2824 " const A.d2(int p) : v = 5 >> p;",
2825 " const A.e1(int p) : v = p << 5;",
2826 " const A.e2(int p) : v = 5 << p;",
2827 "}"]));
2828 resolve(source);
2829 assertNoErrors(source);
2830 verify([source]);
2831 }
2832
2833 void test_nonConstValueInInitializer_binary_num() {
2834 Source source = addSource(EngineTestCase.createSource([
2835 "class A {",
2836 " final v;",
2837 " const A.a1(num p) : v = p + 5;",
2838 " const A.a2(num p) : v = 5 + p;",
2839 " const A.b1(num p) : v = p - 5;",
2840 " const A.b2(num p) : v = 5 - p;",
2841 " const A.c1(num p) : v = p * 5;",
2842 " const A.c2(num p) : v = 5 * p;",
2843 " const A.d1(num p) : v = p / 5;",
2844 " const A.d2(num p) : v = 5 / p;",
2845 " const A.e1(num p) : v = p ~/ 5;",
2846 " const A.e2(num p) : v = 5 ~/ p;",
2847 " const A.f1(num p) : v = p > 5;",
2848 " const A.f2(num p) : v = 5 > p;",
2849 " const A.g1(num p) : v = p < 5;",
2850 " const A.g2(num p) : v = 5 < p;",
2851 " const A.h1(num p) : v = p >= 5;",
2852 " const A.h2(num p) : v = 5 >= p;",
2853 " const A.i1(num p) : v = p <= 5;",
2854 " const A.i2(num p) : v = 5 <= p;",
2855 " const A.j1(num p) : v = p % 5;",
2856 " const A.j2(num p) : v = 5 % p;",
2857 "}"]));
2858 resolve(source);
2859 assertNoErrors(source);
2860 verify([source]);
2861 }
2862
2863 void test_nonConstValueInInitializer_field() {
2864 Source source = addSource(EngineTestCase.createSource([
2865 "class A {",
2866 " final int a;",
2867 " const A() : a = 5;",
2868 "}"]));
2869 resolve(source);
2870 assertNoErrors(source);
2871 verify([source]);
2872 }
2873
2874 void test_nonConstValueInInitializer_redirecting() {
2875 Source source = addSource(EngineTestCase.createSource([
2876 "class A {",
2877 " const A.named(p);",
2878 " const A() : this.named(42);",
2879 "}"]));
2880 resolve(source);
2881 assertNoErrors(source);
2882 verify([source]);
2883 }
2884
2885 void test_nonConstValueInInitializer_super() {
2886 Source source = addSource(EngineTestCase.createSource([
2887 "class A {",
2888 " const A(p);",
2889 "}",
2890 "class B extends A {",
2891 " const B() : super(42);",
2892 "}"]));
2893 resolve(source);
2894 assertNoErrors(source);
2895 verify([source]);
2896 }
2897
2898 void test_nonConstValueInInitializer_unary() {
2899 Source source = addSource(EngineTestCase.createSource([
2900 "class A {",
2901 " final v;",
2902 " const A.a(bool p) : v = !p;",
2903 " const A.b(int p) : v = ~p;",
2904 " const A.c(num p) : v = -p;",
2905 "}"]));
2906 resolve(source);
2907 assertNoErrors(source);
2908 verify([source]);
2909 }
2910
2911 void test_nonGenerativeConstructor() {
2912 Source source = addSource(EngineTestCase.createSource([
2913 "class A {",
2914 " A.named() {}",
2915 " factory A() {}",
2916 "}",
2917 "class B extends A {",
2918 " B() : super.named();",
2919 "}"]));
2920 resolve(source);
2921 assertNoErrors(source);
2922 verify([source]);
2923 }
2924
2925 void test_nonTypeInCatchClause_isClass() {
2926 Source source = addSource(EngineTestCase.createSource([
2927 "f() {",
2928 " try {",
2929 " } on String catch (e) {",
2930 " }",
2931 "}"]));
2932 resolve(source);
2933 assertNoErrors(source);
2934 verify([source]);
2935 }
2936
2937 void test_nonTypeInCatchClause_isFunctionTypeAlias() {
2938 Source source = addSource(EngineTestCase.createSource([
2939 "typedef F();",
2940 "f() {",
2941 " try {",
2942 " } on F catch (e) {",
2943 " }",
2944 "}"]));
2945 resolve(source);
2946 assertNoErrors(source);
2947 verify([source]);
2948 }
2949
2950 void test_nonTypeInCatchClause_isTypeParameter() {
2951 Source source = addSource(EngineTestCase.createSource([
2952 "class A<T> {",
2953 " f() {",
2954 " try {",
2955 " } on T catch (e) {",
2956 " }",
2957 " }",
2958 "}"]));
2959 resolve(source);
2960 assertNoErrors(source);
2961 verify([source]);
2962 }
2963
2964 void test_nonTypeInCatchClause_noType() {
2965 Source source = addSource(EngineTestCase.createSource(["f() {", " try {", " } catch (e) {", " }", "}"]));
2966 resolve(source);
2967 assertNoErrors(source);
2968 verify([source]);
2969 }
2970
2971 void test_nonVoidReturnForOperator_no() {
2972 Source source = addSource(EngineTestCase.createSource(["class A {", " opera tor []=(a, b) {}", "}"]));
2973 resolve(source);
2974 assertNoErrors(source);
2975 verify([source]);
2976 }
2977
2978 void test_nonVoidReturnForOperator_void() {
2979 Source source = addSource(EngineTestCase.createSource(["class A {", " void operator []=(a, b) {}", "}"]));
2980 resolve(source);
2981 assertNoErrors(source);
2982 verify([source]);
2983 }
2984
2985 void test_nonVoidReturnForSetter_function_no() {
2986 Source source = addSource("set x(v) {}");
2987 resolve(source);
2988 assertNoErrors(source);
2989 verify([source]);
2990 }
2991
2992 void test_nonVoidReturnForSetter_function_void() {
2993 Source source = addSource("void set x(v) {}");
2994 resolve(source);
2995 assertNoErrors(source);
2996 verify([source]);
2997 }
2998
2999 void test_nonVoidReturnForSetter_method_no() {
3000 Source source = addSource(EngineTestCase.createSource(["class A {", " set x (v) {}", "}"]));
3001 resolve(source);
3002 assertNoErrors(source);
3003 verify([source]);
3004 }
3005
3006 void test_nonVoidReturnForSetter_method_void() {
3007 Source source = addSource(EngineTestCase.createSource(["class A {", " void set x(v) {}", "}"]));
3008 resolve(source);
3009 assertNoErrors(source);
3010 verify([source]);
3011 }
3012
3013 void test_null_callMethod() {
3014 Source source = addSource(EngineTestCase.createSource(["main() {", " null.m ();", "}"]));
3015 resolve(source);
3016 assertNoErrors(source);
3017 }
3018
3019 void test_null_callOperator() {
3020 Source source = addSource(EngineTestCase.createSource([
3021 "main() {",
3022 " null + 5;",
3023 " null == 5;",
3024 " null[0];",
3025 "}"]));
3026 resolve(source);
3027 assertNoErrors(source);
3028 }
3029
3030 void test_optionalParameterInOperator_required() {
3031 Source source = addSource(EngineTestCase.createSource(["class A {", " opera tor +(p) {}", "}"]));
3032 resolve(source);
3033 assertNoErrors(source);
3034 verify([source]);
3035 }
3036
3037 void test_prefixCollidesWithTopLevelMembers() {
3038 addNamedSource("/lib.dart", EngineTestCase.createSource(["library lib;", "cl ass A {}"]));
3039 Source source = addSource(EngineTestCase.createSource([
3040 "import 'lib.dart' as p;",
3041 "typedef P();",
3042 "p2() {}",
3043 "var p3;",
3044 "class p4 {}",
3045 "p.A a;"]));
3046 resolve(source);
3047 assertNoErrors(source);
3048 verify([source]);
3049 }
3050
3051 void test_propagateTypeArgs_intoBounds() {
3052 Source source = addSource(EngineTestCase.createSource([
3053 "abstract class A<E> {}",
3054 "abstract class B<F> implements A<F>{}",
3055 "abstract class C<G, H extends A<G>> {}",
3056 "class D<I> extends C<I, B<I>> {}"]));
3057 resolve(source);
3058 assertNoErrors(source);
3059 verify([source]);
3060 }
3061
3062 void test_propagateTypeArgs_intoSupertype() {
3063 Source source = addSource(EngineTestCase.createSource([
3064 "class A<T> {",
3065 " A(T p);",
3066 " A.named(T p);",
3067 "}",
3068 "class B<S> extends A<S> {",
3069 " B(S p) : super(p);",
3070 " B.named(S p) : super.named(p);",
3071 "}"]));
3072 resolve(source);
3073 assertNoErrors(source);
3074 verify([source]);
3075 }
3076
3077 void test_proxy_annotation_prefixed() {
3078 Source source = addSource(EngineTestCase.createSource([
3079 "library L;",
3080 "@proxy",
3081 "class A {}",
3082 "f(A a) {",
3083 " a.m();",
3084 " var x = a.g;",
3085 " a.s = 1;",
3086 " var y = a + a;",
3087 " a++;",
3088 " ++a;",
3089 "}"]));
3090 resolve(source);
3091 assertNoErrors(source);
3092 }
3093
3094 void test_proxy_annotation_prefixed2() {
3095 Source source = addSource(EngineTestCase.createSource([
3096 "library L;",
3097 "@proxy",
3098 "class A {}",
3099 "class B {",
3100 " f(A a) {",
3101 " a.m();",
3102 " var x = a.g;",
3103 " a.s = 1;",
3104 " var y = a + a;",
3105 " a++;",
3106 " ++a;",
3107 " }",
3108 "}"]));
3109 resolve(source);
3110 assertNoErrors(source);
3111 }
3112
3113 void test_proxy_annotation_prefixed3() {
3114 Source source = addSource(EngineTestCase.createSource([
3115 "library L;",
3116 "class B {",
3117 " f(A a) {",
3118 " a.m();",
3119 " var x = a.g;",
3120 " a.s = 1;",
3121 " var y = a + a;",
3122 " a++;",
3123 " ++a;",
3124 " }",
3125 "}",
3126 "@proxy",
3127 "class A {}"]));
3128 resolve(source);
3129 assertNoErrors(source);
3130 }
3131
3132 void test_proxy_annotation_proxyHasPrefixedIdentifier() {
3133 Source source = addSource(EngineTestCase.createSource([
3134 "library L;",
3135 "import 'dart:core' as core;",
3136 "@core.proxy class PrefixProxy {}",
3137 "main() {",
3138 " new PrefixProxy().foo;",
3139 " new PrefixProxy().foo();",
3140 "}"]));
3141 resolve(source);
3142 assertNoErrors(source);
3143 }
3144
3145 void test_proxy_annotation_simple() {
3146 Source source = addSource(EngineTestCase.createSource([
3147 "library L;",
3148 "@proxy",
3149 "class B {",
3150 " m() {",
3151 " n();",
3152 " var x = g;",
3153 " s = 1;",
3154 " var y = this + this;",
3155 " }",
3156 "}"]));
3157 resolve(source);
3158 assertNoErrors(source);
3159 }
3160
3161 void test_proxy_annotation_superclass() {
3162 Source source = addSource(EngineTestCase.createSource([
3163 "library L;",
3164 "class B extends A {",
3165 " m() {",
3166 " n();",
3167 " var x = g;",
3168 " s = 1;",
3169 " var y = this + this;",
3170 " }",
3171 "}",
3172 "@proxy",
3173 "class A {}"]));
3174 resolve(source);
3175 assertNoErrors(source);
3176 }
3177
3178 void test_proxy_annotation_superclass_mixin() {
3179 Source source = addSource(EngineTestCase.createSource([
3180 "library L;",
3181 "class B extends Object with A {",
3182 " m() {",
3183 " n();",
3184 " var x = g;",
3185 " s = 1;",
3186 " var y = this + this;",
3187 " }",
3188 "}",
3189 "@proxy",
3190 "class A {}"]));
3191 resolve(source);
3192 assertNoErrors(source);
3193 }
3194
3195 void test_proxy_annotation_superinterface() {
3196 Source source = addSource(EngineTestCase.createSource([
3197 "library L;",
3198 "class B implements A {",
3199 " m() {",
3200 " n();",
3201 " var x = g;",
3202 " s = 1;",
3203 " var y = this + this;",
3204 " }",
3205 "}",
3206 "@proxy",
3207 "class A {}"]));
3208 resolve(source);
3209 assertNoErrors(source);
3210 }
3211
3212 void test_proxy_annotation_superinterface_infiniteLoop() {
3213 Source source = addSource(EngineTestCase.createSource([
3214 "library L;",
3215 "class C implements A {",
3216 " m() {",
3217 " n();",
3218 " var x = g;",
3219 " s = 1;",
3220 " var y = this + this;",
3221 " }",
3222 "}",
3223 "class B implements A{}",
3224 "class A implements B{}"]));
3225 resolve(source);
3226 // Test is that a stack overflow isn't reached in resolution (previous line) , no need to assert
3227 // error set.
3228 }
3229
3230 void test_recursiveConstructorRedirect() {
3231 Source source = addSource(EngineTestCase.createSource([
3232 "class A {",
3233 " A.a() : this.b();",
3234 " A.b() : this.c();",
3235 " A.c() {}",
3236 "}"]));
3237 resolve(source);
3238 assertNoErrors(source);
3239 verify([source]);
3240 }
3241
3242 void test_recursiveFactoryRedirect() {
3243 Source source = addSource(EngineTestCase.createSource([
3244 "class A {",
3245 " factory A() = B;",
3246 "}",
3247 "class B implements A {",
3248 " factory B() = C;",
3249 "}",
3250 "class C implements B {",
3251 " factory C() {}",
3252 "}"]));
3253 resolve(source);
3254 assertNoErrors(source);
3255 verify([source]);
3256 }
3257
3258 void test_redirectToInvalidFunctionType() {
3259 Source source = addSource(EngineTestCase.createSource([
3260 "class A implements B {",
3261 " A(int p) {}",
3262 "}",
3263 "class B {",
3264 " factory B(int p) = A;",
3265 "}"]));
3266 resolve(source);
3267 assertNoErrors(source);
3268 verify([source]);
3269 }
3270
3271 void test_redirectToInvalidReturnType() {
3272 Source source = addSource(EngineTestCase.createSource([
3273 "class A {",
3274 " A() {}",
3275 "}",
3276 "class B extends A {",
3277 " factory B() = A;",
3278 "}"]));
3279 resolve(source);
3280 assertNoErrors(source);
3281 verify([source]);
3282 }
3283
3284 void test_redirectToNonConstConstructor() {
3285 Source source = addSource(EngineTestCase.createSource([
3286 "class A {",
3287 " const A.a();",
3288 " const factory A.b() = A.a;",
3289 "}"]));
3290 resolve(source);
3291 assertNoErrors(source);
3292 verify([source]);
3293 }
3294
3295 void test_referenceToDeclaredVariableInInitializer_constructorName() {
3296 Source source = addSource(EngineTestCase.createSource([
3297 "class A {",
3298 " A.x() {}",
3299 "}",
3300 "f() {",
3301 " var x = new A.x();",
3302 "}"]));
3303 resolve(source);
3304 assertNoErrors(source);
3305 verify([source]);
3306 }
3307
3308 void test_referenceToDeclaredVariableInInitializer_methodName() {
3309 Source source = addSource(EngineTestCase.createSource([
3310 "class A {",
3311 " x() {}",
3312 "}",
3313 "f(A a) {",
3314 " var x = a.x();",
3315 "}"]));
3316 resolve(source);
3317 assertNoErrors(source);
3318 verify([source]);
3319 }
3320
3321 void test_referenceToDeclaredVariableInInitializer_propertyName() {
3322 Source source = addSource(EngineTestCase.createSource([
3323 "class A {",
3324 " var x;",
3325 "}",
3326 "f(A a) {",
3327 " var x = a.x;",
3328 "}"]));
3329 resolve(source);
3330 assertNoErrors(source);
3331 verify([source]);
3332 }
3333
3334 void test_rethrowOutsideCatch() {
3335 Source source = addSource(EngineTestCase.createSource([
3336 "class A {",
3337 " void m() {",
3338 " try {} catch (e) {rethrow;}",
3339 " }",
3340 "}"]));
3341 resolve(source);
3342 assertNoErrors(source);
3343 verify([source]);
3344 }
3345
3346 void test_returnInGenerativeConstructor() {
3347 Source source = addSource(EngineTestCase.createSource(["class A {", " A() { return; }", "}"]));
3348 resolve(source);
3349 assertNoErrors(source);
3350 verify([source]);
3351 }
3352
3353 void test_returnInGenerator_async() {
3354 resetWithAsync();
3355 Source source = addSource(EngineTestCase.createSource(["f() async {", " ret urn 0;", "}"]));
3356 resolve(source);
3357 assertNoErrors(source);
3358 verify([source]);
3359 }
3360
3361 void test_returnInGenerator_sync() {
3362 Source source = addSource(EngineTestCase.createSource(["f() {", " return 0; ", "}"]));
3363 resolve(source);
3364 assertNoErrors(source);
3365 verify([source]);
3366 }
3367
3368 void test_returnOfInvalidType_async() {
3369 AnalysisOptionsImpl options = new AnalysisOptionsImpl.con1(analysisContext2. analysisOptions);
3370 options.enableAsync = true;
3371 resetWithOptions(options);
3372 Source source = addSource(EngineTestCase.createSource([
3373 "import 'dart:async';",
3374 "class A {",
3375 " Future<int> m() async {",
3376 " return 0;",
3377 " }",
3378 "}"]));
3379 resolve(source);
3380 assertNoErrors(source);
3381 verify([source]);
3382 }
3383
3384 void test_returnOfInvalidType_dynamic() {
3385 Source source = addSource(EngineTestCase.createSource([
3386 "class TypeError {}",
3387 "class A {",
3388 " static void testLogicalOp() {",
3389 " testOr(a, b, onTypeError) {",
3390 " try {",
3391 " return a || b;",
3392 " } on TypeError catch (t) {",
3393 " return onTypeError;",
3394 " }",
3395 " }",
3396 " }",
3397 "}"]));
3398 resolve(source);
3399 assertNoErrors(source);
3400 verify([source]);
3401 }
3402
3403 void test_returnOfInvalidType_dynamicAsTypeArgument() {
3404 Source source = addSource(EngineTestCase.createSource([
3405 "class I<T> {",
3406 " factory I() => new A<T>();",
3407 "}",
3408 "class A<T> implements I {",
3409 "}"]));
3410 resolve(source);
3411 assertNoErrors(source);
3412 verify([source]);
3413 }
3414
3415 void test_returnOfInvalidType_subtype() {
3416 Source source = addSource(EngineTestCase.createSource([
3417 "class A {}",
3418 "class B extends A {}",
3419 "A f(B b) { return b; }"]));
3420 resolve(source);
3421 assertNoErrors(source);
3422 verify([source]);
3423 }
3424
3425 void test_returnOfInvalidType_supertype() {
3426 Source source = addSource(EngineTestCase.createSource([
3427 "class A {}",
3428 "class B extends A {}",
3429 "B f(A a) { return a; }"]));
3430 resolve(source);
3431 assertNoErrors(source);
3432 verify([source]);
3433 }
3434
3435 void test_returnOfInvalidType_typeParameter_18468() {
3436 // https://code.google.com/p/dart/issues/detail?id=18468
3437 //
3438 // This test verifies that the type of T is more specific than Type,
3439 // where T is a type parameter and Type is the type Type from
3440 // core, this particular test case comes from issue 18468.
3441 //
3442 // A test cannot be added to TypeParameterTypeImplTest since the types retur ned out of the
3443 // TestTypeProvider don't have a mock 'dart.core' enclosing library element.
3444 // See TypeParameterTypeImpl.isMoreSpecificThan().
3445 Source source = addSource(EngineTestCase.createSource(["class Foo<T> {", " Type get t => T;", "}"]));
3446 resolve(source);
3447 assertErrors(source, []);
3448 verify([source]);
3449 }
3450
3451 void test_returnOfInvalidType_void() {
3452 Source source = addSource(EngineTestCase.createSource([
3453 "void f1() {}",
3454 "void f2() { return; }",
3455 "void f3() { return null; }",
3456 "void f4() { return g1(); }",
3457 "void f5() { return g2(); }",
3458 "g1() {}",
3459 "void g2() {}",
3460 ""]));
3461 resolve(source);
3462 assertNoErrors(source);
3463 verify([source]);
3464 }
3465
3466 void test_returnWithoutValue_noReturnType() {
3467 Source source = addSource(EngineTestCase.createSource(["f() { return; }"]));
3468 resolve(source);
3469 assertNoErrors(source);
3470 verify([source]);
3471 }
3472
3473 void test_returnWithoutValue_void() {
3474 Source source = addSource(EngineTestCase.createSource(["void f() { return; } "]));
3475 resolve(source);
3476 assertNoErrors(source);
3477 verify([source]);
3478 }
3479
3480 void test_reversedTypeArguments() {
3481 Source source = addSource(EngineTestCase.createSource([
3482 "class Codec<S1, T1> {",
3483 " Codec<T1, S1> get inverted => new _InvertedCodec<T1, S1>(this);",
3484 "}",
3485 "class _InvertedCodec<T2, S2> extends Codec<T2, S2> {",
3486 " _InvertedCodec(Codec<S2, T2> codec);",
3487 "}"]));
3488 resolve(source);
3489 assertNoErrors(source);
3490 verify([source]);
3491 }
3492
3493 void test_sharedDeferredPrefix() {
3494 resolveWithAndWithoutExperimental(<String> [
3495 EngineTestCase.createSource(["library lib1;", "f1() {}"]),
3496 EngineTestCase.createSource(["library lib2;", "f2() {}"]),
3497 EngineTestCase.createSource(["library lib3;", "f3() {}"]),
3498 EngineTestCase.createSource([
3499 "library root;",
3500 "import 'lib1.dart' deferred as lib1;",
3501 "import 'lib2.dart' as lib;",
3502 "import 'lib3.dart' as lib;",
3503 "main() { lib1.f1(); lib.f2(); lib.f3(); }"])], <ErrorCode> [ParserError Code.DEFERRED_IMPORTS_NOT_SUPPORTED], <ErrorCode> []);
3504 }
3505
3506 void test_staticAccessToInstanceMember_annotation() {
3507 Source source = addSource(EngineTestCase.createSource([
3508 "class A {",
3509 " const A.name();",
3510 "}",
3511 "@A.name()",
3512 "main() {",
3513 "}"]));
3514 resolve(source);
3515 assertNoErrors(source);
3516 verify([source]);
3517 }
3518
3519 void test_staticAccessToInstanceMember_method() {
3520 Source source = addSource(EngineTestCase.createSource([
3521 "class A {",
3522 " static m() {}",
3523 "}",
3524 "main() {",
3525 " A.m;",
3526 " A.m();",
3527 "}"]));
3528 resolve(source);
3529 assertNoErrors(source);
3530 verify([source]);
3531 }
3532
3533 void test_staticAccessToInstanceMember_propertyAccess_field() {
3534 Source source = addSource(EngineTestCase.createSource([
3535 "class A {",
3536 " static var f;",
3537 "}",
3538 "main() {",
3539 " A.f;",
3540 " A.f = 1;",
3541 "}"]));
3542 resolve(source);
3543 assertNoErrors(source);
3544 verify([source]);
3545 }
3546
3547 void test_staticAccessToInstanceMember_propertyAccess_propertyAccessor() {
3548 Source source = addSource(EngineTestCase.createSource([
3549 "class A {",
3550 " static get f => 42;",
3551 " static set f(x) {}",
3552 "}",
3553 "main() {",
3554 " A.f;",
3555 " A.f = 1;",
3556 "}"]));
3557 resolve(source);
3558 assertNoErrors(source);
3559 verify([source]);
3560 }
3561
3562 void test_superInInvalidContext() {
3563 Source source = addSource(EngineTestCase.createSource([
3564 "class A {",
3565 " m() {}",
3566 "}",
3567 "class B extends A {",
3568 " B() {",
3569 " var v = super.m();",
3570 " }",
3571 " n() {",
3572 " var v = super.m();",
3573 " }",
3574 "}"]));
3575 resolve(source);
3576 assertNoErrors(source);
3577 verify([source]);
3578 }
3579
3580 void test_typeAliasCannotReferenceItself_returnClass_withTypeAlias() {
3581 Source source = addSource(EngineTestCase.createSource(["typedef B A();", "cl ass B {", " A a;", "}"]));
3582 resolve(source);
3583 assertNoErrors(source);
3584 verify([source]);
3585 }
3586
3587 void test_typeArgumentNotMatchingBounds_const() {
3588 Source source = addSource(EngineTestCase.createSource([
3589 "class A {}",
3590 "class B extends A {}",
3591 "class G<E extends A> {",
3592 " const G();",
3593 "}",
3594 "f() { return const G<B>(); }"]));
3595 resolve(source);
3596 assertNoErrors(source);
3597 verify([source]);
3598 }
3599
3600 void test_typeArgumentNotMatchingBounds_new() {
3601 Source source = addSource(EngineTestCase.createSource([
3602 "class A {}",
3603 "class B extends A {}",
3604 "class G<E extends A> {}",
3605 "f() { return new G<B>(); }"]));
3606 resolve(source);
3607 assertNoErrors(source);
3608 verify([source]);
3609 }
3610
3611 void test_typeArgumentNotMatchingBounds_typeArgumentList_0() {
3612 Source source = addSource(EngineTestCase.createSource(["abstract class A<T e xtends A>{}"]));
3613 resolve(source);
3614 assertNoErrors(source);
3615 verify([source]);
3616 }
3617
3618 void test_typeArgumentNotMatchingBounds_typeArgumentList_1() {
3619 Source source = addSource(EngineTestCase.createSource(["abstract class A<T e xtends A<A>>{}"]));
3620 resolve(source);
3621 assertNoErrors(source);
3622 verify([source]);
3623 }
3624
3625 void test_typeArgumentNotMatchingBounds_typeArgumentList_20() {
3626 Source source = addSource(EngineTestCase.createSource(["abstract class A<T e xtends A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A>>>>>>>>>>>>>>>>>>>>>{}"]));
3627 resolve(source);
3628 assertNoErrors(source);
3629 verify([source]);
3630 }
3631
3632 void test_typePromotion_booleanAnd_useInRight() {
3633 Source source = addSource(EngineTestCase.createSource([
3634 "main(Object p) {",
3635 " p is String && p.length != 0;",
3636 "}"]));
3637 resolve(source);
3638 assertNoErrors(source);
3639 verify([source]);
3640 }
3641
3642 void test_typePromotion_booleanAnd_useInRight_accessedInClosureRight_noAssignm ent() {
3643 Source source = addSource(EngineTestCase.createSource([
3644 "callMe(f()) { f(); }",
3645 "main(Object p) {",
3646 " (p is String) && callMe(() { p.length; });",
3647 "}"]));
3648 resolve(source);
3649 assertNoErrors(source);
3650 verify([source]);
3651 }
3652
3653 void test_typePromotion_conditional_issue14655() {
3654 Source source = addSource(EngineTestCase.createSource([
3655 "class A {}",
3656 "class B extends A {}",
3657 "class C extends B {",
3658 " mc() {}",
3659 "}",
3660 "print(_) {}",
3661 "main(A p) {",
3662 " (p is C) && (print(() => p) && (p is B)) ? p.mc() : p = null;",
3663 "}"]));
3664 resolve(source);
3665 assertNoErrors(source);
3666 verify([source]);
3667 }
3668
3669 void test_typePromotion_conditional_useInThen() {
3670 Source source = addSource(EngineTestCase.createSource(["main(Object p) {", " p is String ? p.length : 0;", "}"]));
3671 resolve(source);
3672 assertNoErrors(source);
3673 verify([source]);
3674 }
3675
3676 void test_typePromotion_conditional_useInThen_accessedInClosure_noAssignment() {
3677 Source source = addSource(EngineTestCase.createSource([
3678 "callMe(f()) { f(); }",
3679 "main(Object p) {",
3680 " p is String ? callMe(() { p.length; }) : 0;",
3681 "}"]));
3682 resolve(source);
3683 assertNoErrors(source);
3684 verify([source]);
3685 }
3686
3687 void test_typePromotion_functionType_arg_ignoreIfNotMoreSpecific() {
3688 Source source = addSource(EngineTestCase.createSource([
3689 "typedef FuncB(B b);",
3690 "typedef FuncA(A a);",
3691 "class A {}",
3692 "class B {}",
3693 "main(FuncA f) {",
3694 " if (f is FuncB) {",
3695 " f(new A());",
3696 " }",
3697 "}"]));
3698 resolve(source);
3699 assertNoErrors(source);
3700 verify([source]);
3701 }
3702
3703 void test_typePromotion_functionType_return_ignoreIfNotMoreSpecific() {
3704 Source source = addSource(EngineTestCase.createSource([
3705 "class A {}",
3706 "typedef FuncAtoDyn(A a);",
3707 "typedef FuncDynToDyn(x);",
3708 "main(FuncAtoDyn f) {",
3709 " if (f is FuncDynToDyn) {",
3710 " A a = f(new A());",
3711 " }",
3712 "}"]));
3713 resolve(source);
3714 assertNoErrors(source);
3715 verify([source]);
3716 }
3717
3718 void test_typePromotion_functionType_return_voidToDynamic() {
3719 Source source = addSource(EngineTestCase.createSource([
3720 "typedef FuncDynToDyn(x);",
3721 "typedef void FuncDynToVoid(x);",
3722 "class A {}",
3723 "main(FuncDynToVoid f) {",
3724 " if (f is FuncDynToDyn) {",
3725 " A a = f(null);",
3726 " }",
3727 "}"]));
3728 resolve(source);
3729 assertNoErrors(source);
3730 verify([source]);
3731 }
3732
3733 void test_typePromotion_if_accessedInClosure_noAssignment() {
3734 Source source = addSource(EngineTestCase.createSource([
3735 "callMe(f()) { f(); }",
3736 "main(Object p) {",
3737 " if (p is String) {",
3738 " callMe(() {",
3739 " p.length;",
3740 " });",
3741 " }",
3742 "}"]));
3743 resolve(source);
3744 assertNoErrors(source);
3745 verify([source]);
3746 }
3747
3748 void test_typePromotion_if_extends_moreSpecific() {
3749 Source source = addSource(EngineTestCase.createSource([
3750 "class V {}",
3751 "class VP extends V {}",
3752 "class A<T> {}",
3753 "class B<S> extends A<S> {",
3754 " var b;",
3755 "}",
3756 "",
3757 "main(A<V> p) {",
3758 " if (p is B<VP>) {",
3759 " p.b;",
3760 " }",
3761 "}"]));
3762 resolve(source);
3763 assertNoErrors(source);
3764 verify([source]);
3765 }
3766
3767 void test_typePromotion_if_hasAssignment_outsideAfter() {
3768 Source source = addSource(EngineTestCase.createSource([
3769 "main(Object p) {",
3770 " if (p is String) {",
3771 " p.length;",
3772 " }",
3773 " p = 0;",
3774 "}"]));
3775 resolve(source);
3776 assertNoErrors(source);
3777 verify([source]);
3778 }
3779
3780 void test_typePromotion_if_hasAssignment_outsideBefore() {
3781 Source source = addSource(EngineTestCase.createSource([
3782 "main(Object p, Object p2) {",
3783 " p = p2;",
3784 " if (p is String) {",
3785 " p.length;",
3786 " }",
3787 "}"]));
3788 resolve(source);
3789 assertNoErrors(source);
3790 verify([source]);
3791 }
3792
3793 void test_typePromotion_if_implements_moreSpecific() {
3794 Source source = addSource(EngineTestCase.createSource([
3795 "class V {}",
3796 "class VP extends V {}",
3797 "class A<T> {}",
3798 "class B<S> implements A<S> {",
3799 " var b;",
3800 "}",
3801 "",
3802 "main(A<V> p) {",
3803 " if (p is B<VP>) {",
3804 " p.b;",
3805 " }",
3806 "}"]));
3807 resolve(source);
3808 assertNoErrors(source);
3809 verify([source]);
3810 }
3811
3812 void test_typePromotion_if_inClosure_assignedAfter_inSameFunction() {
3813 Source source = addSource(EngineTestCase.createSource([
3814 "main() {",
3815 " f(Object p) {",
3816 " if (p is String) {",
3817 " p.length;",
3818 " }",
3819 " p = 0;",
3820 " };",
3821 "}"]));
3822 resolve(source);
3823 assertNoErrors(source);
3824 verify([source]);
3825 }
3826
3827 void test_typePromotion_if_is_and_left() {
3828 Source source = addSource(EngineTestCase.createSource([
3829 "bool tt() => true;",
3830 "main(Object p) {",
3831 " if (p is String && tt()) {",
3832 " p.length;",
3833 " }",
3834 "}"]));
3835 resolve(source);
3836 assertNoErrors(source);
3837 verify([source]);
3838 }
3839
3840 void test_typePromotion_if_is_and_right() {
3841 Source source = addSource(EngineTestCase.createSource([
3842 "bool tt() => true;",
3843 "main(Object p) {",
3844 " if (tt() && p is String) {",
3845 " p.length;",
3846 " }",
3847 "}"]));
3848 resolve(source);
3849 assertNoErrors(source);
3850 verify([source]);
3851 }
3852
3853 void test_typePromotion_if_is_and_subThenSuper() {
3854 Source source = addSource(EngineTestCase.createSource([
3855 "class A {",
3856 " var a;",
3857 "}",
3858 "class B extends A {",
3859 " var b;",
3860 "}",
3861 "main(Object p) {",
3862 " if (p is B && p is A) {",
3863 " p.a;",
3864 " p.b;",
3865 " }",
3866 "}"]));
3867 resolve(source);
3868 assertNoErrors(source);
3869 verify([source]);
3870 }
3871
3872 void test_typePromotion_if_is_parenthesized() {
3873 Source source = addSource(EngineTestCase.createSource([
3874 "main(Object p) {",
3875 " if ((p is String)) {",
3876 " p.length;",
3877 " }",
3878 "}"]));
3879 resolve(source);
3880 assertNoErrors(source);
3881 verify([source]);
3882 }
3883
3884 void test_typePromotion_if_is_single() {
3885 Source source = addSource(EngineTestCase.createSource([
3886 "main(Object p) {",
3887 " if (p is String) {",
3888 " p.length;",
3889 " }",
3890 "}"]));
3891 resolve(source);
3892 assertNoErrors(source);
3893 verify([source]);
3894 }
3895
3896 void test_typePromotion_parentheses() {
3897 Source source = addSource(EngineTestCase.createSource([
3898 "main(Object p) {",
3899 " (p is String) ? p.length : 0;",
3900 " (p) is String ? p.length : 0;",
3901 " ((p)) is String ? p.length : 0;",
3902 " ((p) is String) ? p.length : 0;",
3903 "}"]));
3904 resolve(source);
3905 assertNoErrors(source);
3906 verify([source]);
3907 }
3908
3909 void test_typeType_class() {
3910 Source source = addSource(EngineTestCase.createSource(["class C {}", "f(Type t) {}", "main() {", " f(C);", "}"]));
3911 resolve(source);
3912 assertNoErrors(source);
3913 verify([source]);
3914 }
3915
3916 void test_typeType_class_prefixed() {
3917 addNamedSource("/lib.dart", EngineTestCase.createSource(["library lib;", "cl ass C {}"]));
3918 Source source = addSource(EngineTestCase.createSource([
3919 "import 'lib.dart' as p;",
3920 "f(Type t) {}",
3921 "main() {",
3922 " f(p.C);",
3923 "}"]));
3924 resolve(source);
3925 assertNoErrors(source);
3926 verify([source]);
3927 }
3928
3929 void test_typeType_functionTypeAlias() {
3930 Source source = addSource(EngineTestCase.createSource([
3931 "typedef F();",
3932 "f(Type t) {}",
3933 "main() {",
3934 " f(F);",
3935 "}"]));
3936 resolve(source);
3937 assertNoErrors(source);
3938 verify([source]);
3939 }
3940
3941 void test_typeType_functionTypeAlias_prefixed() {
3942 addNamedSource("/lib.dart", EngineTestCase.createSource(["library lib;", "ty pedef F();"]));
3943 Source source = addSource(EngineTestCase.createSource([
3944 "import 'lib.dart' as p;",
3945 "f(Type t) {}",
3946 "main() {",
3947 " f(p.F);",
3948 "}"]));
3949 resolve(source);
3950 assertNoErrors(source);
3951 verify([source]);
3952 }
3953
3954 void test_undefinedConstructorInInitializer_explicit_named() {
3955 Source source = addSource(EngineTestCase.createSource([
3956 "class A {",
3957 " A.named() {}",
3958 "}",
3959 "class B extends A {",
3960 " B() : super.named();",
3961 "}"]));
3962 resolve(source);
3963 assertNoErrors(source);
3964 verify([source]);
3965 }
3966
3967 void test_undefinedConstructorInInitializer_explicit_unnamed() {
3968 Source source = addSource(EngineTestCase.createSource([
3969 "class A {",
3970 " A() {}",
3971 "}",
3972 "class B extends A {",
3973 " B() : super();",
3974 "}"]));
3975 resolve(source);
3976 assertNoErrors(source);
3977 verify([source]);
3978 }
3979
3980 void test_undefinedConstructorInInitializer_hasOptionalParameters() {
3981 Source source = addSource(EngineTestCase.createSource([
3982 "class A {",
3983 " A([p]) {}",
3984 "}",
3985 "class B extends A {",
3986 " B();",
3987 "}"]));
3988 resolve(source);
3989 assertNoErrors(source);
3990 verify([source]);
3991 }
3992
3993 void test_undefinedConstructorInInitializer_implicit() {
3994 Source source = addSource(EngineTestCase.createSource([
3995 "class A {",
3996 " A() {}",
3997 "}",
3998 "class B extends A {",
3999 " B();",
4000 "}"]));
4001 resolve(source);
4002 assertNoErrors(source);
4003 verify([source]);
4004 }
4005
4006 void test_undefinedConstructorInInitializer_implicit_typeAlias() {
4007 Source source = addSource(EngineTestCase.createSource([
4008 "class M {}",
4009 "class A = Object with M;",
4010 "class B extends A {",
4011 " B();",
4012 "}"]));
4013 resolve(source);
4014 assertNoErrors(source);
4015 verify([source]);
4016 }
4017
4018 void test_undefinedConstructorInInitializer_redirecting() {
4019 Source source = addSource(EngineTestCase.createSource([
4020 "class Foo {",
4021 " Foo.ctor();",
4022 "}",
4023 "class Bar extends Foo {",
4024 " Bar() : this.ctor();",
4025 " Bar.ctor() : super.ctor();",
4026 "}"]));
4027 resolve(source);
4028 assertNoErrors(source);
4029 verify([source]);
4030 }
4031
4032 void test_undefinedGetter_typeSubstitution() {
4033 Source source = addSource(EngineTestCase.createSource([
4034 "class A<E> {",
4035 " E element;",
4036 "}",
4037 "class B extends A<List> {",
4038 " m() {",
4039 " element.last;",
4040 " }",
4041 "}"]));
4042 resolve(source);
4043 assertNoErrors(source);
4044 verify([source]);
4045 }
4046
4047 void test_undefinedIdentifier_hide() {
4048 Source source = addSource(EngineTestCase.createSource(["library L;", "export 'lib1.dart' hide a;"]));
4049 addNamedSource("/lib1.dart", EngineTestCase.createSource(["library lib1;"])) ;
4050 resolve(source);
4051 assertNoErrors(source);
4052 verify([source]);
4053 }
4054
4055 void test_undefinedIdentifier_show() {
4056 Source source = addSource(EngineTestCase.createSource(["library L;", "export 'lib1.dart' show a;"]));
4057 addNamedSource("/lib1.dart", EngineTestCase.createSource(["library lib1;"])) ;
4058 resolve(source);
4059 assertNoErrors(source);
4060 verify([source]);
4061 }
4062
4063 void test_undefinedIdentifier_synthetic_whenExpression() {
4064 Source source = addSource(EngineTestCase.createSource(["print(x) {}", "main( ) {", " print(is String);", "}"]));
4065 resolve(source);
4066 assertErrors(source, [ParserErrorCode.MISSING_IDENTIFIER]);
4067 }
4068
4069 void test_undefinedIdentifier_synthetic_whenMethodName() {
4070 Source source = addSource(EngineTestCase.createSource(["print(x) {}", "main( int p) {", " p.();", "}"]));
4071 resolve(source);
4072 assertErrors(source, [ParserErrorCode.MISSING_IDENTIFIER]);
4073 }
4074
4075 void test_undefinedMethod_functionExpression_callMethod() {
4076 Source source = addSource(EngineTestCase.createSource(["main() {", " (() => null).call();", "}"]));
4077 resolve(source);
4078 assertNoErrors(source);
4079 // A call to verify(source) fails as '.call()' isn't resolved.
4080 }
4081
4082 void test_undefinedMethod_functionExpression_directCall() {
4083 Source source = addSource(EngineTestCase.createSource(["main() {", " (() => null)();", "}"]));
4084 resolve(source);
4085 assertNoErrors(source);
4086 // A call to verify(source) fails as '(() => null)()' isn't resolved.
4087 }
4088
4089 void test_undefinedOperator_index() {
4090 Source source = addSource(EngineTestCase.createSource([
4091 "class A {",
4092 " operator [](a) {}",
4093 " operator []=(a, b) {}",
4094 "}",
4095 "f(A a) {",
4096 " a[0];",
4097 " a[0] = 1;",
4098 "}"]));
4099 resolve(source);
4100 assertNoErrors(source);
4101 verify([source]);
4102 }
4103
4104 void test_undefinedOperator_tilde() {
4105 Source source = addSource(EngineTestCase.createSource(["const A = 3;", "cons t B = ~((1 << A) - 1);"]));
4106 resolve(source);
4107 assertNoErrors(source);
4108 verify([source]);
4109 }
4110
4111 void test_undefinedSetter_importWithPrefix() {
4112 addNamedSource("/lib.dart", EngineTestCase.createSource(["library lib;", "se t y(int value) {}"]));
4113 Source source = addSource(EngineTestCase.createSource(["import 'lib.dart' as x;", "main() {", " x.y = 0;", "}"]));
4114 resolve(source);
4115 assertNoErrors(source);
4116 verify([source]);
4117 }
4118
4119 void test_undefinedSuperMethod_field() {
4120 Source source = addSource(EngineTestCase.createSource([
4121 "class A {",
4122 " var m;",
4123 "}",
4124 "class B extends A {",
4125 " f() {",
4126 " super.m();",
4127 " }",
4128 "}"]));
4129 resolve(source);
4130 assertNoErrors(source);
4131 verify([source]);
4132 }
4133
4134 void test_undefinedSuperMethod_method() {
4135 Source source = addSource(EngineTestCase.createSource([
4136 "class A {",
4137 " m() {}",
4138 "}",
4139 "class B extends A {",
4140 " f() {",
4141 " super.m();",
4142 " }",
4143 "}"]));
4144 resolve(source);
4145 assertNoErrors(source);
4146 verify([source]);
4147 }
4148
4149 void test_unqualifiedReferenceToNonLocalStaticMember_fromComment_new() {
4150 Source source = addSource(EngineTestCase.createSource([
4151 "class A {",
4152 " A() {}",
4153 " A.named() {}",
4154 "}",
4155 "/// [new A] or [new A.named]",
4156 "main() {",
4157 "}"]));
4158 resolve(source);
4159 assertNoErrors(source);
4160 verify([source]);
4161 }
4162
4163 void test_uriDoesNotExist_dll() {
4164 addNamedSource("/lib.dll", "");
4165 Source source = addSource(EngineTestCase.createSource(["import 'dart-ext:lib ';"]));
4166 resolve(source);
4167 assertNoErrors(source);
4168 }
4169
4170 void test_uriDoesNotExist_dylib() {
4171 addNamedSource("/lib.dylib", "");
4172 Source source = addSource(EngineTestCase.createSource(["import 'dart-ext:lib ';"]));
4173 resolve(source);
4174 assertNoErrors(source);
4175 }
4176
4177 void test_uriDoesNotExist_so() {
4178 addNamedSource("/lib.so", "");
4179 Source source = addSource(EngineTestCase.createSource(["import 'dart-ext:lib ';"]));
4180 resolve(source);
4181 assertNoErrors(source);
4182 }
4183
4184 void test_wrongNumberOfParametersForOperator_index() {
4185 Source source = addSource(EngineTestCase.createSource(["class A {", " opera tor []=(a, b) {}", "}"]));
4186 resolve(source);
4187 assertNoErrors(source);
4188 verify([source]);
4189 }
4190
4191 void test_wrongNumberOfParametersForOperator_minus() {
4192 _check_wrongNumberOfParametersForOperator("-", "");
4193 _check_wrongNumberOfParametersForOperator("-", "a");
4194 }
4195
4196 void test_wrongNumberOfParametersForOperator1() {
4197 _check_wrongNumberOfParametersForOperator1("<");
4198 _check_wrongNumberOfParametersForOperator1(">");
4199 _check_wrongNumberOfParametersForOperator1("<=");
4200 _check_wrongNumberOfParametersForOperator1(">=");
4201 _check_wrongNumberOfParametersForOperator1("+");
4202 _check_wrongNumberOfParametersForOperator1("/");
4203 _check_wrongNumberOfParametersForOperator1("~/");
4204 _check_wrongNumberOfParametersForOperator1("*");
4205 _check_wrongNumberOfParametersForOperator1("%");
4206 _check_wrongNumberOfParametersForOperator1("|");
4207 _check_wrongNumberOfParametersForOperator1("^");
4208 _check_wrongNumberOfParametersForOperator1("&");
4209 _check_wrongNumberOfParametersForOperator1("<<");
4210 _check_wrongNumberOfParametersForOperator1(">>");
4211 _check_wrongNumberOfParametersForOperator1("[]");
4212 }
4213
4214 void test_wrongNumberOfParametersForSetter() {
4215 Source source = addSource(EngineTestCase.createSource(["class A {", " set x (a) {}", "}"]));
4216 resolve(source);
4217 assertNoErrors(source);
4218 verify([source]);
4219 }
4220
4221 void test_yieldEachInNonGenerator_asyncStar() {
4222 resetWithAsync();
4223 Source source = addSource(EngineTestCase.createSource(["f() async* {", " yi eld* 0;", "}"]));
4224 resolve(source);
4225 assertNoErrors(source);
4226 verify([source]);
4227 }
4228
4229 void test_yieldEachInNonGenerator_syncStar() {
4230 resetWithAsync();
4231 Source source = addSource(EngineTestCase.createSource(["f() sync* {", " yie ld* 0;", "}"]));
4232 resolve(source);
4233 assertNoErrors(source);
4234 verify([source]);
4235 }
4236
4237 void test_yieldInNonGenerator_asyncStar() {
4238 resetWithAsync();
4239 Source source = addSource(EngineTestCase.createSource(["f() async* {", " yi eld 0;", "}"]));
4240 resolve(source);
4241 assertNoErrors(source);
4242 verify([source]);
4243 }
4244
4245 void test_yieldInNonGenerator_syncStar() {
4246 resetWithAsync();
4247 Source source = addSource(EngineTestCase.createSource(["f() sync* {", " yie ld 0;", "}"]));
4248 resolve(source);
4249 assertNoErrors(source);
4250 verify([source]);
4251 }
4252
4253 void _check_wrongNumberOfParametersForOperator(String name, String parameters) {
4254 Source source = addSource(EngineTestCase.createSource(["class A {", " opera tor ${name}(${parameters}) {}", "}"]));
4255 resolve(source);
4256 assertNoErrors(source);
4257 verify([source]);
4258 reset();
4259 }
4260
4261 void _check_wrongNumberOfParametersForOperator1(String name) {
4262 _check_wrongNumberOfParametersForOperator(name, "a");
4263 }
4264 }
4265
4266 main() {
4267 _ut.groupSep = ' | ';
4268 runReflectiveTests(NonErrorResolverTest);
4269 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698