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