| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 library engine.compile_time_error_code_test; | 5 library engine.compile_time_error_code_test; |
| 6 | 6 |
| 7 import 'package:analyzer/src/generated/error.dart'; | 7 import 'package:analyzer/src/generated/error.dart'; |
| 8 import 'package:analyzer/src/generated/parser.dart' show ParserErrorCode; | 8 import 'package:analyzer/src/generated/parser.dart' show ParserErrorCode; |
| 9 import 'package:analyzer/src/generated/source_io.dart'; | 9 import 'package:analyzer/src/generated/source_io.dart'; |
| 10 import 'package:unittest/unittest.dart' as _ut; | 10 import 'package:unittest/unittest.dart' as _ut; |
| (...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 239 library lib1; | 239 library lib1; |
| 240 class N {}'''); | 240 class N {}'''); |
| 241 addNamedSource("/lib2.dart", r''' | 241 addNamedSource("/lib2.dart", r''' |
| 242 library lib2; | 242 library lib2; |
| 243 class N {}'''); | 243 class N {}'''); |
| 244 resolve(source); | 244 resolve(source); |
| 245 assertErrors(source, [CompileTimeErrorCode.AMBIGUOUS_EXPORT]); | 245 assertErrors(source, [CompileTimeErrorCode.AMBIGUOUS_EXPORT]); |
| 246 verify([source]); | 246 verify([source]); |
| 247 } | 247 } |
| 248 | 248 |
| 249 void test_async_used_as_identifier_in_annotation() { |
| 250 Source source = addSource(''' |
| 251 const int async = 0; |
| 252 f() async { |
| 253 g(@async x) {} |
| 254 g(0); |
| 255 } |
| 256 '''); |
| 257 resolve(source); |
| 258 assertErrors(source, [ParserErrorCode.ASYNC_KEYWORD_USED_AS_IDENTIFIER]); |
| 259 verify([source]); |
| 260 } |
| 261 |
| 262 void test_async_used_as_identifier_in_argument_label() { |
| 263 Source source = addSource(''' |
| 264 @proxy |
| 265 class C {} |
| 266 f() async { |
| 267 new C().g(async: 0); |
| 268 } |
| 269 '''); |
| 270 resolve(source); |
| 271 assertErrors(source, [ParserErrorCode.ASYNC_KEYWORD_USED_AS_IDENTIFIER]); |
| 272 // Note: we don't call verify([source]) because verify() doesn't understand |
| 273 // about @proxy. |
| 274 } |
| 275 |
| 276 void test_async_used_as_identifier_in_async_method() { |
| 277 Source source = addSource(''' |
| 278 f() async { |
| 279 var async = 1; |
| 280 } |
| 281 '''); |
| 282 resolve(source); |
| 283 assertErrors(source, [ParserErrorCode.ASYNC_KEYWORD_USED_AS_IDENTIFIER]); |
| 284 verify([source]); |
| 285 } |
| 286 |
| 287 void test_async_used_as_identifier_in_async_star_method() { |
| 288 Source source = addSource(''' |
| 289 f() async* { |
| 290 var async = 1; |
| 291 } |
| 292 '''); |
| 293 resolve(source); |
| 294 assertErrors(source, [ParserErrorCode.ASYNC_KEYWORD_USED_AS_IDENTIFIER]); |
| 295 verify([source]); |
| 296 } |
| 297 |
| 298 void test_async_used_as_identifier_in_break_statement() { |
| 299 Source source = addSource(''' |
| 300 f() async { |
| 301 while (true) { |
| 302 break async; |
| 303 } |
| 304 } |
| 305 '''); |
| 306 resolve(source); |
| 307 assertErrors( |
| 308 source, |
| 309 [ |
| 310 ParserErrorCode.ASYNC_KEYWORD_USED_AS_IDENTIFIER, |
| 311 CompileTimeErrorCode.LABEL_UNDEFINED]); |
| 312 // Note: we don't call verify([source]) because the reference to the |
| 313 // "async" label is unresolved. |
| 314 } |
| 315 |
| 316 void test_async_used_as_identifier_in_cascaded_invocation() { |
| 317 Source source = addSource(''' |
| 318 class C { |
| 319 int async() => 1; |
| 320 } |
| 321 f() async { |
| 322 return new C()..async(); |
| 323 } |
| 324 '''); |
| 325 resolve(source); |
| 326 assertErrors(source, [ParserErrorCode.ASYNC_KEYWORD_USED_AS_IDENTIFIER]); |
| 327 verify([source]); |
| 328 } |
| 329 |
| 330 void test_async_used_as_identifier_in_cascaded_setter_invocation() { |
| 331 Source source = addSource(''' |
| 332 class C { |
| 333 void set async(int i) {} |
| 334 } |
| 335 f() async { |
| 336 return new C()..async = 1; |
| 337 } |
| 338 '''); |
| 339 resolve(source); |
| 340 assertErrors(source, [ParserErrorCode.ASYNC_KEYWORD_USED_AS_IDENTIFIER]); |
| 341 verify([source]); |
| 342 } |
| 343 |
| 344 void test_async_used_as_identifier_in_catch_exception_argument() { |
| 345 Source source = addSource(''' |
| 346 g() {} |
| 347 f() async { |
| 348 try { |
| 349 g(); |
| 350 } catch (async) { } |
| 351 } |
| 352 '''); |
| 353 resolve(source); |
| 354 assertErrors(source, [ParserErrorCode.ASYNC_KEYWORD_USED_AS_IDENTIFIER]); |
| 355 verify([source]); |
| 356 } |
| 357 |
| 358 void test_async_used_as_identifier_in_catch_stacktrace_argument() { |
| 359 Source source = addSource(''' |
| 360 g() {} |
| 361 f() async { |
| 362 try { |
| 363 g(); |
| 364 } catch (e, async) { } |
| 365 } |
| 366 '''); |
| 367 resolve(source); |
| 368 assertErrors(source, [ParserErrorCode.ASYNC_KEYWORD_USED_AS_IDENTIFIER]); |
| 369 verify([source]); |
| 370 } |
| 371 |
| 372 void test_async_used_as_identifier_in_continue_statement() { |
| 373 Source source = addSource(''' |
| 374 f() async { |
| 375 while (true) { |
| 376 continue async; |
| 377 } |
| 378 } |
| 379 '''); |
| 380 resolve(source); |
| 381 assertErrors( |
| 382 source, |
| 383 [ |
| 384 ParserErrorCode.ASYNC_KEYWORD_USED_AS_IDENTIFIER, |
| 385 CompileTimeErrorCode.LABEL_UNDEFINED]); |
| 386 // Note: we don't call verify([source]) because the reference to the |
| 387 // "async" label is unresolved. |
| 388 } |
| 389 |
| 390 void test_async_used_as_identifier_in_for_statement() { |
| 391 Source source = addSource(''' |
| 392 var async; |
| 393 f() async { |
| 394 for (async in []) {} |
| 395 } |
| 396 '''); |
| 397 resolve(source); |
| 398 assertErrors(source, [ParserErrorCode.ASYNC_KEYWORD_USED_AS_IDENTIFIER]); |
| 399 verify([source]); |
| 400 } |
| 401 |
| 402 void test_async_used_as_identifier_in_formal_parameter_name() { |
| 403 Source source = addSource(''' |
| 404 f() async { |
| 405 g(int async) {} |
| 406 g(0); |
| 407 } |
| 408 '''); |
| 409 resolve(source); |
| 410 assertErrors(source, [ParserErrorCode.ASYNC_KEYWORD_USED_AS_IDENTIFIER]); |
| 411 verify([source]); |
| 412 } |
| 413 |
| 414 void test_async_used_as_identifier_in_getter_name() { |
| 415 Source source = addSource(''' |
| 416 class C { |
| 417 int get async => 1; |
| 418 } |
| 419 f() async { |
| 420 return new C().async; |
| 421 } |
| 422 '''); |
| 423 resolve(source); |
| 424 assertErrors(source, [ParserErrorCode.ASYNC_KEYWORD_USED_AS_IDENTIFIER]); |
| 425 verify([source]); |
| 426 } |
| 427 |
| 428 void test_async_used_as_identifier_in_invocation() { |
| 429 Source source = addSource(''' |
| 430 class C { |
| 431 int async() => 1; |
| 432 } |
| 433 f() async { |
| 434 return new C().async(); |
| 435 } |
| 436 '''); |
| 437 resolve(source); |
| 438 assertErrors(source, [ParserErrorCode.ASYNC_KEYWORD_USED_AS_IDENTIFIER]); |
| 439 verify([source]); |
| 440 } |
| 441 |
| 442 void test_async_used_as_identifier_in_local_function_name() { |
| 443 Source source = addSource(''' |
| 444 f() async { |
| 445 int async() => null; |
| 446 } |
| 447 '''); |
| 448 resolve(source); |
| 449 assertErrors(source, [ParserErrorCode.ASYNC_KEYWORD_USED_AS_IDENTIFIER]); |
| 450 verify([source]); |
| 451 } |
| 452 |
| 453 void test_async_used_as_identifier_in_prefix() { |
| 454 Source source = addSource(''' |
| 455 import 'dart:async' as async; |
| 456 f() async { |
| 457 return new async.Future.value(0); |
| 458 } |
| 459 '''); |
| 460 resolve(source); |
| 461 assertErrors(source, [ParserErrorCode.ASYNC_KEYWORD_USED_AS_IDENTIFIER]); |
| 462 verify([source]); |
| 463 } |
| 464 |
| 465 void test_async_used_as_identifier_in_setter_name() { |
| 466 Source source = addSource(''' |
| 467 class C { |
| 468 void set async(int i) {} |
| 469 } |
| 470 f() async { |
| 471 new C().async = 1; |
| 472 } |
| 473 '''); |
| 474 resolve(source); |
| 475 assertErrors(source, [ParserErrorCode.ASYNC_KEYWORD_USED_AS_IDENTIFIER]); |
| 476 verify([source]); |
| 477 } |
| 478 |
| 479 void test_async_used_as_identifier_in_statement_label() { |
| 480 Source source = addSource(''' |
| 481 f() async { |
| 482 async: g(); |
| 483 } |
| 484 g() {} |
| 485 '''); |
| 486 resolve(source); |
| 487 assertErrors(source, [ParserErrorCode.ASYNC_KEYWORD_USED_AS_IDENTIFIER]); |
| 488 verify([source]); |
| 489 } |
| 490 |
| 491 void test_async_used_as_identifier_in_string_interpolation() { |
| 492 Source source = addSource(r''' |
| 493 int async = 1; |
| 494 f() async { |
| 495 return "$async"; |
| 496 } |
| 497 '''); |
| 498 resolve(source); |
| 499 assertErrors(source, [ParserErrorCode.ASYNC_KEYWORD_USED_AS_IDENTIFIER]); |
| 500 verify([source]); |
| 501 } |
| 502 |
| 503 void test_async_used_as_identifier_in_suffix() { |
| 504 addNamedSource("/lib1.dart", r''' |
| 505 library lib1; |
| 506 int async; |
| 507 '''); |
| 508 Source source = addSource(''' |
| 509 import 'lib1.dart' as l; |
| 510 f() async { |
| 511 return l.async; |
| 512 } |
| 513 '''); |
| 514 resolve(source); |
| 515 assertErrors(source, [ParserErrorCode.ASYNC_KEYWORD_USED_AS_IDENTIFIER]); |
| 516 verify([source]); |
| 517 } |
| 518 |
| 519 void test_async_used_as_identifier_in_switch_label() { |
| 520 Source source = addSource(''' |
| 521 f() async { |
| 522 switch (0) { |
| 523 async: case 0: break; |
| 524 } |
| 525 } |
| 526 '''); |
| 527 resolve(source); |
| 528 assertErrors(source, [ParserErrorCode.ASYNC_KEYWORD_USED_AS_IDENTIFIER]); |
| 529 verify([source]); |
| 530 } |
| 531 |
| 532 void test_async_used_as_identifier_in_sync_star_method() { |
| 533 Source source = addSource(''' |
| 534 f() sync* { |
| 535 var async = 1; |
| 536 } |
| 537 '''); |
| 538 resolve(source); |
| 539 assertErrors(source, [ParserErrorCode.ASYNC_KEYWORD_USED_AS_IDENTIFIER]); |
| 540 verify([source]); |
| 541 } |
| 542 |
| 249 void test_asyncForInWrongContext() { | 543 void test_asyncForInWrongContext() { |
| 250 Source source = addSource(r''' | 544 Source source = addSource(r''' |
| 251 f(list) { | 545 f(list) { |
| 252 await for (var e in list) { | 546 await for (var e in list) { |
| 253 } | 547 } |
| 254 }'''); | 548 }'''); |
| 255 resolve(source); | 549 resolve(source); |
| 256 assertErrors(source, [CompileTimeErrorCode.ASYNC_FOR_IN_WRONG_CONTEXT]); | 550 assertErrors(source, [CompileTimeErrorCode.ASYNC_FOR_IN_WRONG_CONTEXT]); |
| 257 verify([source]); | 551 verify([source]); |
| 258 } | 552 } |
| 259 | 553 |
| 554 void test_await_used_as_identifier_in_async_method() { |
| 555 Source source = addSource(''' |
| 556 f() async { |
| 557 var await = 1; |
| 558 } |
| 559 '''); |
| 560 resolve(source); |
| 561 assertErrors(source, [ParserErrorCode.ASYNC_KEYWORD_USED_AS_IDENTIFIER]); |
| 562 verify([source]); |
| 563 } |
| 564 |
| 565 void test_await_used_as_identifier_in_async_star_method() { |
| 566 Source source = addSource(''' |
| 567 f() async* { |
| 568 var await = 1; |
| 569 } |
| 570 '''); |
| 571 resolve(source); |
| 572 assertErrors(source, [ParserErrorCode.ASYNC_KEYWORD_USED_AS_IDENTIFIER]); |
| 573 verify([source]); |
| 574 } |
| 575 |
| 576 void test_await_used_as_identifier_in_sync_star_method() { |
| 577 Source source = addSource(''' |
| 578 f() sync* { |
| 579 var await = 1; |
| 580 } |
| 581 '''); |
| 582 resolve(source); |
| 583 assertErrors(source, [ParserErrorCode.ASYNC_KEYWORD_USED_AS_IDENTIFIER]); |
| 584 verify([source]); |
| 585 } |
| 586 |
| 260 void test_builtInIdentifierAsMixinName_classTypeAlias() { | 587 void test_builtInIdentifierAsMixinName_classTypeAlias() { |
| 261 Source source = addSource(r''' | 588 Source source = addSource(r''' |
| 262 class A {} | 589 class A {} |
| 263 class B {} | 590 class B {} |
| 264 class as = A with B;'''); | 591 class as = A with B;'''); |
| 265 resolve(source); | 592 resolve(source); |
| 266 assertErrors( | 593 assertErrors( |
| 267 source, | 594 source, |
| 268 [CompileTimeErrorCode.BUILT_IN_IDENTIFIER_AS_TYPEDEF_NAME]); | 595 [CompileTimeErrorCode.BUILT_IN_IDENTIFIER_AS_TYPEDEF_NAME]); |
| 269 verify([source]); | 596 verify([source]); |
| (...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 646 void test_constDeferredClass() { | 973 void test_constDeferredClass() { |
| 647 resolveWithErrors(<String>[r''' | 974 resolveWithErrors(<String>[r''' |
| 648 library lib1; | 975 library lib1; |
| 649 class A { | 976 class A { |
| 650 const A(); | 977 const A(); |
| 651 }''', r''' | 978 }''', r''' |
| 652 library root; | 979 library root; |
| 653 import 'lib1.dart' deferred as a; | 980 import 'lib1.dart' deferred as a; |
| 654 main() { | 981 main() { |
| 655 const a.A(); | 982 const a.A(); |
| 656 }'''], | 983 }'''], <ErrorCode>[CompileTimeErrorCode.CONST_DEFERRED_CLASS]); |
| 657 <ErrorCode>[CompileTimeErrorCode.CONST_DEFERRED_CLASS]); | |
| 658 } | 984 } |
| 659 | 985 |
| 660 void test_constDeferredClass_namedConstructor() { | 986 void test_constDeferredClass_namedConstructor() { |
| 661 resolveWithErrors(<String>[r''' | 987 resolveWithErrors(<String>[r''' |
| 662 library lib1; | 988 library lib1; |
| 663 class A { | 989 class A { |
| 664 const A.b(); | 990 const A.b(); |
| 665 }''', r''' | 991 }''', r''' |
| 666 library root; | 992 library root; |
| 667 import 'lib1.dart' deferred as a; | 993 import 'lib1.dart' deferred as a; |
| 668 main() { | 994 main() { |
| 669 const a.A.b(); | 995 const a.A.b(); |
| 670 }'''], | 996 }'''], <ErrorCode>[CompileTimeErrorCode.CONST_DEFERRED_CLASS]); |
| 671 <ErrorCode>[CompileTimeErrorCode.CONST_DEFERRED_CLASS]); | |
| 672 } | 997 } |
| 673 | 998 |
| 674 void test_constEval_newInstance_constConstructor() { | 999 void test_constEval_newInstance_constConstructor() { |
| 675 Source source = addSource(r''' | 1000 Source source = addSource(r''' |
| 676 class A { | 1001 class A { |
| 677 const A(); | 1002 const A(); |
| 678 } | 1003 } |
| 679 const a = new A();'''); | 1004 const a = new A();'''); |
| 680 resolve(source); | 1005 resolve(source); |
| 681 assertErrors( | 1006 assertErrors( |
| (...skipping 4658 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5340 class A { | 5665 class A { |
| 5341 set x(a, b) {} | 5666 set x(a, b) {} |
| 5342 }'''); | 5667 }'''); |
| 5343 resolve(source); | 5668 resolve(source); |
| 5344 assertErrors( | 5669 assertErrors( |
| 5345 source, | 5670 source, |
| 5346 [CompileTimeErrorCode.WRONG_NUMBER_OF_PARAMETERS_FOR_SETTER]); | 5671 [CompileTimeErrorCode.WRONG_NUMBER_OF_PARAMETERS_FOR_SETTER]); |
| 5347 verify([source]); | 5672 verify([source]); |
| 5348 } | 5673 } |
| 5349 | 5674 |
| 5675 void test_yield_used_as_identifier_in_async_method() { |
| 5676 Source source = addSource(''' |
| 5677 f() async { |
| 5678 var yield = 1; |
| 5679 } |
| 5680 '''); |
| 5681 resolve(source); |
| 5682 assertErrors(source, [ParserErrorCode.ASYNC_KEYWORD_USED_AS_IDENTIFIER]); |
| 5683 verify([source]); |
| 5684 } |
| 5685 |
| 5686 void test_yield_used_as_identifier_in_async_star_method() { |
| 5687 Source source = addSource(''' |
| 5688 f() async* { |
| 5689 var yield = 1; |
| 5690 } |
| 5691 '''); |
| 5692 resolve(source); |
| 5693 assertErrors(source, [ParserErrorCode.ASYNC_KEYWORD_USED_AS_IDENTIFIER]); |
| 5694 verify([source]); |
| 5695 } |
| 5696 |
| 5697 void test_yield_used_as_identifier_in_sync_star_method() { |
| 5698 Source source = addSource(''' |
| 5699 f() sync* { |
| 5700 var yield = 1; |
| 5701 } |
| 5702 '''); |
| 5703 resolve(source); |
| 5704 assertErrors(source, [ParserErrorCode.ASYNC_KEYWORD_USED_AS_IDENTIFIER]); |
| 5705 verify([source]); |
| 5706 } |
| 5707 |
| 5350 void _check_constEvalThrowsException_binary_null(String expr, bool resolved) { | 5708 void _check_constEvalThrowsException_binary_null(String expr, bool resolved) { |
| 5351 Source source = addSource("const C = $expr;"); | 5709 Source source = addSource("const C = $expr;"); |
| 5352 resolve(source); | 5710 resolve(source); |
| 5353 if (resolved) { | 5711 if (resolved) { |
| 5354 assertErrors(source, [CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION]); | 5712 assertErrors(source, [CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION]); |
| 5355 verify([source]); | 5713 verify([source]); |
| 5356 } else { | 5714 } else { |
| 5357 assertErrors(source, [CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION]); | 5715 assertErrors(source, [CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION]); |
| 5358 // no verify(), 'null x' is not resolved | 5716 // no verify(), 'null x' is not resolved |
| 5359 } | 5717 } |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5420 [CompileTimeErrorCode.WRONG_NUMBER_OF_PARAMETERS_FOR_OPERATOR]); | 5778 [CompileTimeErrorCode.WRONG_NUMBER_OF_PARAMETERS_FOR_OPERATOR]); |
| 5421 verify([source]); | 5779 verify([source]); |
| 5422 reset(); | 5780 reset(); |
| 5423 } | 5781 } |
| 5424 | 5782 |
| 5425 void _check_wrongNumberOfParametersForOperator1(String name) { | 5783 void _check_wrongNumberOfParametersForOperator1(String name) { |
| 5426 _check_wrongNumberOfParametersForOperator(name, ""); | 5784 _check_wrongNumberOfParametersForOperator(name, ""); |
| 5427 _check_wrongNumberOfParametersForOperator(name, "a, b"); | 5785 _check_wrongNumberOfParametersForOperator(name, "a, b"); |
| 5428 } | 5786 } |
| 5429 } | 5787 } |
| OLD | NEW |