OLD | NEW |
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 library analyzer.test.src.task.strong.checker_test; | 5 library analyzer.test.src.task.strong.checker_test; |
6 | 6 |
7 import 'package:test_reflective_loader/test_reflective_loader.dart'; | 7 import 'package:test_reflective_loader/test_reflective_loader.dart'; |
8 | 8 |
9 import 'strong_test_helper.dart'; | 9 import 'strong_test_helper.dart'; |
10 | 10 |
(...skipping 481 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
492 var toStringClosure2 = helper.toString; | 492 var toStringClosure2 = helper.toString; |
493 (/*info:DYNAMIC_INVOKE*/toStringClosure2()); | 493 (/*info:DYNAMIC_INVOKE*/toStringClosure2()); |
494 int hashCode = /*info:DYNAMIC_CAST*/helper.hashCode; | 494 int hashCode = /*info:DYNAMIC_CAST*/helper.hashCode; |
495 | 495 |
496 baz().toString(); | 496 baz().toString(); |
497 baz().hashCode; | 497 baz().hashCode; |
498 } | 498 } |
499 '''); | 499 '''); |
500 } | 500 } |
501 | 501 |
| 502 void test_covariantOverride() { |
| 503 addFile(r''' |
| 504 library meta; |
| 505 class _Covariant { const _Covariant(); } |
| 506 const Object covariant = const _Covariant(); |
| 507 ''', name: '/meta.dart'); |
| 508 |
| 509 checkFile(r''' |
| 510 import 'meta.dart'; |
| 511 class C { |
| 512 num f(num x) => x; |
| 513 } |
| 514 class D extends C { |
| 515 int f(@covariant int x) => x; |
| 516 } |
| 517 class E extends D { |
| 518 int f(Object x) => /*info:DOWN_CAST_IMPLICIT*/x; |
| 519 } |
| 520 class F extends E { |
| 521 int f(@covariant int x) => x; |
| 522 } |
| 523 class G extends E implements D {} |
| 524 |
| 525 class D_error extends C { |
| 526 /*error:INVALID_METHOD_OVERRIDE*/int f(int x) => x; |
| 527 } |
| 528 class E_error extends D { |
| 529 /*error:INVALID_METHOD_OVERRIDE*/int f(@covariant double x) => 0; |
| 530 } |
| 531 class F_error extends E { |
| 532 /*error:INVALID_METHOD_OVERRIDE*/int f(@covariant double x) => 0; |
| 533 } |
| 534 class G_error extends E implements D { |
| 535 /*error:INVALID_METHOD_OVERRIDE*/int f(@covariant double x) => 0; |
| 536 } |
| 537 '''); |
| 538 } |
| 539 |
| 540 void test_covariantOverride_leastUpperBound() { |
| 541 addFile(r''' |
| 542 library meta; |
| 543 class _Covariant { const _Covariant(); } |
| 544 const Object covariant = const _Covariant(); |
| 545 ''', name: '/meta.dart'); |
| 546 |
| 547 checkFile(r''' |
| 548 import "meta.dart"; |
| 549 abstract class Top {} |
| 550 abstract class Left implements Top {} |
| 551 abstract class Right implements Top {} |
| 552 abstract class Bottom implements Left, Right {} |
| 553 |
| 554 abstract class TakesLeft { |
| 555 m(Left x); |
| 556 } |
| 557 abstract class TakesRight { |
| 558 m(Right x); |
| 559 } |
| 560 abstract class TakesTop implements TakesLeft, TakesRight { |
| 561 m(Top x); // works today |
| 562 } |
| 563 abstract class TakesBottom implements TakesLeft, TakesRight { |
| 564 // LUB(Left, Right) == Top, so this is an implicit cast from Top to Bottom. |
| 565 m(@covariant Bottom x); |
| 566 } |
| 567 '''); |
| 568 } |
| 569 |
| 570 void test_covariantOverride_markerIsInherited() { |
| 571 addFile(r''' |
| 572 library meta; |
| 573 class _Covariant { const _Covariant(); } |
| 574 const Object covariant = const _Covariant(); |
| 575 ''', name: '/meta.dart'); |
| 576 |
| 577 checkFile(r''' |
| 578 import 'meta.dart'; |
| 579 class C { |
| 580 num f(@covariant num x) => x; |
| 581 } |
| 582 class D extends C { |
| 583 int f(int x) => x; |
| 584 } |
| 585 class E extends D { |
| 586 int f(Object x) => /*info:DOWN_CAST_IMPLICIT*/x; |
| 587 } |
| 588 class F extends E { |
| 589 int f(int x) => x; |
| 590 } |
| 591 class G extends E implements D {} |
| 592 |
| 593 class D_error extends C { |
| 594 /*error:INVALID_METHOD_OVERRIDE*/int f(String x) => 0; |
| 595 } |
| 596 class E_error extends D { |
| 597 /*error:INVALID_METHOD_OVERRIDE*/int f(double x) => 0; |
| 598 } |
| 599 class F_error extends E { |
| 600 /*error:INVALID_METHOD_OVERRIDE*/int f(double x) => 0; |
| 601 } |
| 602 class G_error extends E implements D { |
| 603 /*error:INVALID_METHOD_OVERRIDE*/int f(double x) => 0; |
| 604 } |
| 605 '''); |
| 606 } |
| 607 |
502 void test_dynamicInvocation() { | 608 void test_dynamicInvocation() { |
503 checkFile(''' | 609 checkFile(''' |
504 typedef dynamic A(dynamic x); | 610 typedef dynamic A(dynamic x); |
505 class B { | 611 class B { |
506 int call(int x) => x; | 612 int call(int x) => x; |
507 double col(double x) => x; | 613 double col(double x) => x; |
508 } | 614 } |
509 void main() { | 615 void main() { |
510 { | 616 { |
511 B f = new B(); | 617 B f = new B(); |
(...skipping 3215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3727 // Regression test for https://github.com/dart-lang/sdk/issues/25069 | 3833 // Regression test for https://github.com/dart-lang/sdk/issues/25069 |
3728 checkFile(''' | 3834 checkFile(''' |
3729 typedef int Foo(); | 3835 typedef int Foo(); |
3730 void foo() {} | 3836 void foo() {} |
3731 void main () { | 3837 void main () { |
3732 Foo x = /*error:INVALID_ASSIGNMENT,info:USE_OF_VOID_RESULT*/foo(); | 3838 Foo x = /*error:INVALID_ASSIGNMENT,info:USE_OF_VOID_RESULT*/foo(); |
3733 } | 3839 } |
3734 '''); | 3840 '''); |
3735 } | 3841 } |
3736 } | 3842 } |
OLD | NEW |