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

Side by Side Diff: pkg/analyzer/test/src/task/strong/checker_test.dart

Issue 1700523002: fixes #24507, allow known functions to be treated as strict arrows (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « pkg/analyzer/lib/src/task/strong/info.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 // TODO(jmesserly): this file needs to be refactored, it's a port from 5 // TODO(jmesserly): this file needs to be refactored, it's a port from
6 // package:dev_compiler's tests 6 // package:dev_compiler's tests
7 /// General type checking tests 7 /// General type checking tests
8 library analyzer.test.src.task.strong.checker_test; 8 library analyzer.test.src.task.strong.checker_test;
9 9
10 import 'package:unittest/unittest.dart'; 10 import 'package:unittest/unittest.dart';
(...skipping 538 matching lines...) Expand 10 before | Expand all | Expand 10 after
549 test('dynamic', () { 549 test('dynamic', () {
550 checkFile(''' 550 checkFile('''
551 551
552 class A {} 552 class A {}
553 553
554 typedef dynamic Top(dynamic x); // Top of the lattice 554 typedef dynamic Top(dynamic x); // Top of the lattice
555 typedef dynamic Left(A x); // Left branch 555 typedef dynamic Left(A x); // Left branch
556 typedef A Right(dynamic x); // Right branch 556 typedef A Right(dynamic x); // Right branch
557 typedef A Bottom(A x); // Bottom of the lattice 557 typedef A Bottom(A x); // Bottom of the lattice
558 558
559 dynamic left(A x) => x;
560 A bot(A x) => x;
561 dynamic top(dynamic x) => x;
562 A right(dynamic x) => /*info:DYNAMIC_CAST*/x;
563
564 void main() { 559 void main() {
560 Top top;
561 Left left;
562 Right right;
563 Bottom bot;
565 { 564 {
566 Top f; 565 Top f;
567 f = top; 566 f = top;
568 f = left; 567 f = left;
569 f = right; 568 f = right;
570 f = bot; 569 f = bot;
571 } 570 }
572 { 571 {
573 Left f; 572 Left f;
574 f = /*severe:STATIC_TYPE_ERROR*/top; 573 f = /*warning:DOWN_CAST_COMPOSITE*/top;
575 f = left; 574 f = left;
576 f = /*severe:STATIC_TYPE_ERROR*/right; 575 f = /*warning:DOWN_CAST_COMPOSITE*/right;
577 f = bot; 576 f = bot;
578 } 577 }
579 { 578 {
580 Right f; 579 Right f;
581 f = /*severe:STATIC_TYPE_ERROR*/top; 580 f = /*warning:DOWN_CAST_COMPOSITE*/top;
582 f = /*severe:STATIC_TYPE_ERROR*/left; 581 f = /*warning:DOWN_CAST_COMPOSITE*/left;
583 f = right; 582 f = right;
584 f = bot; 583 f = bot;
585 } 584 }
586 { 585 {
587 Bottom f; 586 Bottom f;
588 f = /*severe:STATIC_TYPE_ERROR*/top; 587 f = /*warning:DOWN_CAST_COMPOSITE*/top;
589 f = /*severe:STATIC_TYPE_ERROR*/left; 588 f = /*warning:DOWN_CAST_COMPOSITE*/left;
590 f = /*severe:STATIC_TYPE_ERROR*/right; 589 f = /*warning:DOWN_CAST_COMPOSITE*/right;
591 f = bot; 590 f = bot;
592 } 591 }
593 } 592 }
594 '''); 593 ''');
595 }); 594 });
596 595
596 test('dynamic - known functions', () {
597
598 // Our lattice should look like this:
599 //
600 //
601 // Bot -> Top
602 // / \
603 // A -> Top Bot -> A
604 // / \ /
605 // Top -> Top A -> A
606 // \ /
607 // Top -> A
608 //
609 checkFile('''
610 class A {}
611
612 typedef dynamic BotTop(dynamic x);
613 typedef dynamic ATop(A x);
614 typedef A BotA(dynamic x);
615 typedef A AA(A x);
616 typedef A TopA(Object x);
617 typedef dynamic TopTop(Object x);
618
619 dynamic aTop(A x) => x;
620 A aa(A x) => x;
621 dynamic topTop(dynamic x) => x;
622 A topA(dynamic x) => /*info:DYNAMIC_CAST*/x;
623
624 void main() {
625 BotTop botTop;
626 BotA botA;
627 {
628 BotTop f;
629 f = topTop;
630 f = aTop;
631 f = topA;
632 f = aa;
633 }
634 {
635 ATop f;
636 f = topTop;
637 f = aTop;
638 f = topA;
639 f = aa;
640 }
641 {
642 BotA f;
643 f = /*severe:STATIC_TYPE_ERROR*/topTop;
644 f = /*severe:STATIC_TYPE_ERROR*/aTop;
645 f = topA;
646 f = aa;
647 }
648 {
649 AA f;
650 f = /*severe:STATIC_TYPE_ERROR*/topTop;
651 f = /*severe:STATIC_TYPE_ERROR*/aTop;
652 f = topA;
653 f = aa;
654 }
655 {
656 TopTop f;
657 f = topTop;
658 f = /*severe:STATIC_TYPE_ERROR*/aTop;
659 f = topA;
660 f = /*severe:STATIC_TYPE_ERROR*/aa;
661 }
662 {
663 TopA f;
664 f = /*severe:STATIC_TYPE_ERROR*/topTop;
665 f = /*severe:STATIC_TYPE_ERROR*/aTop;
666 f = topA;
667 f = /*severe:STATIC_TYPE_ERROR*/aa;
668 }
669 }
670 ''');
671 });
672
597 test('function literal variance', () { 673 test('function literal variance', () {
598 checkFile(''' 674 checkFile('''
599 675
600 class A {} 676 class A {}
601 class B extends A {} 677 class B extends A {}
602 678
603 typedef T Function2<S, T>(S z); 679 typedef T Function2<S, T>(S z);
604 680
605 A top(B x) => x; 681 A top(B x) => x;
606 B left(B x) => x; 682 B left(B x) => x;
(...skipping 2190 matching lines...) Expand 10 before | Expand all | Expand 10 after
2797 2873
2798 baz1() sync* { yield* (/*info:DYNAMIC_CAST*/x); } 2874 baz1() sync* { yield* (/*info:DYNAMIC_CAST*/x); }
2799 Iterable baz2() sync* { yield* (/*info:DYNAMIC_CAST*/x); } 2875 Iterable baz2() sync* { yield* (/*info:DYNAMIC_CAST*/x); }
2800 Iterable<int> baz3() sync* { yield* (/*warning:DOWN_CAST_COMPOSITE*/x); } 2876 Iterable<int> baz3() sync* { yield* (/*warning:DOWN_CAST_COMPOSITE*/x); }
2801 Iterable<int> baz4() sync* { yield* new Iterable<int>(); } 2877 Iterable<int> baz4() sync* { yield* new Iterable<int>(); }
2802 Iterable<int> baz5() sync* { yield* (/*info:INFERRED_TYPE_ALLOCATION*/ne w Iterable()); } 2878 Iterable<int> baz5() sync* { yield* (/*info:INFERRED_TYPE_ALLOCATION*/ne w Iterable()); }
2803 '''); 2879 ''');
2804 }); 2880 });
2805 }); 2881 });
2806 } 2882 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/task/strong/info.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698