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

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 void main() {
560 Top top;
561 Left left;
562 Right right;
563 Bottom bot;
564 {
565 Top f;
566 f = top;
567 f = left;
568 f = right;
569 f = bot;
570 }
571 {
572 Left f;
573 f = /*warning:DOWN_CAST_COMPOSITE*/top;
574 f = left;
575 f = /*warning:DOWN_CAST_COMPOSITE*/right;
576 f = bot;
577 }
578 {
579 Right f;
580 f = /*warning:DOWN_CAST_COMPOSITE*/top;
581 f = /*warning:DOWN_CAST_COMPOSITE*/left;
582 f = right;
583 f = bot;
584 }
585 {
586 Bottom f;
587 f = /*warning:DOWN_CAST_COMPOSITE*/top;
588 f = /*warning:DOWN_CAST_COMPOSITE*/left;
589 f = /*warning:DOWN_CAST_COMPOSITE*/right;
590 f = bot;
591 }
592 }
593 ''');
594 });
595
596 test('dynamic - known functions', () {
597 checkFile('''
598
599 class A {}
Leaf 2016/02/16 20:30:43 A little pedantic, but I think it's worth getting
Jennifer Messerly 2016/02/17 20:13:23 Done! * used that picture in a comment. Thanks :)
600
601 typedef dynamic Top(dynamic x); // Top of the lattice
602 typedef dynamic Left(A x); // Left branch
603 typedef A Right(dynamic x); // Right branch
604 typedef A Bottom(A x); // Bottom of the lattice
Leaf 2016/02/16 20:30:43 This is not the bottom type in this lattice.
Jennifer Messerly 2016/02/17 20:13:23 Fixed. See above.
605
559 dynamic left(A x) => x; 606 dynamic left(A x) => x;
560 A bot(A x) => x; 607 A bot(A x) => x;
Leaf 2016/02/16 20:30:43 This is not the bottom type in this lattice.
Jennifer Messerly 2016/02/17 20:13:23 Fixed. See above.
561 dynamic top(dynamic x) => x; 608 dynamic top(dynamic x) => x;
Leaf 2016/02/16 20:30:43 This is not the top type in this lattice.
Jennifer Messerly 2016/02/17 20:13:23 Fixed. See above.
562 A right(dynamic x) => /*info:DYNAMIC_CAST*/x; 609 A right(dynamic x) => /*info:DYNAMIC_CAST*/x;
Leaf 2016/02/16 20:30:43 This is the bottom type in this lattice.
Jennifer Messerly 2016/02/17 20:13:23 Fixed. See above.
563 610
564 void main() { 611 void main() {
565 { 612 {
566 Top f; 613 Top f;
567 f = top; 614 f = top;
568 f = left; 615 f = left;
569 f = right; 616 f = right;
570 f = bot; 617 f = bot;
571 } 618 }
572 { 619 {
573 Left f; 620 Left f;
574 f = /*severe:STATIC_TYPE_ERROR*/top; 621 f = top;
575 f = left; 622 f = left;
576 f = /*severe:STATIC_TYPE_ERROR*/right; 623 f = right;
577 f = bot; 624 f = bot;
578 } 625 }
579 { 626 {
580 Right f; 627 Right f;
581 f = /*severe:STATIC_TYPE_ERROR*/top; 628 f = /*severe:STATIC_TYPE_ERROR*/top;
582 f = /*severe:STATIC_TYPE_ERROR*/left; 629 f = /*severe:STATIC_TYPE_ERROR*/left;
583 f = right; 630 f = right;
584 f = bot; 631 f = bot;
585 } 632 }
586 { 633 {
587 Bottom f; 634 Bottom f;
588 f = /*severe:STATIC_TYPE_ERROR*/top; 635 f = /*severe:STATIC_TYPE_ERROR*/top;
589 f = /*severe:STATIC_TYPE_ERROR*/left; 636 f = /*severe:STATIC_TYPE_ERROR*/left;
590 f = /*severe:STATIC_TYPE_ERROR*/right; 637 f = right;
591 f = bot; 638 f = bot;
592 } 639 }
593 } 640 }
594 '''); 641 ''');
595 }); 642 });
596 643
597 test('function literal variance', () { 644 test('function literal variance', () {
598 checkFile(''' 645 checkFile('''
599 646
600 class A {} 647 class A {}
(...skipping 2193 matching lines...) Expand 10 before | Expand all | Expand 10 after
2794 2841
2795 baz1() sync* { yield* (/*info:DYNAMIC_CAST*/x); } 2842 baz1() sync* { yield* (/*info:DYNAMIC_CAST*/x); }
2796 Iterable baz2() sync* { yield* (/*info:DYNAMIC_CAST*/x); } 2843 Iterable baz2() sync* { yield* (/*info:DYNAMIC_CAST*/x); }
2797 Iterable<int> baz3() sync* { yield* (/*warning:DOWN_CAST_COMPOSITE*/x); } 2844 Iterable<int> baz3() sync* { yield* (/*warning:DOWN_CAST_COMPOSITE*/x); }
2798 Iterable<int> baz4() sync* { yield* new Iterable<int>(); } 2845 Iterable<int> baz4() sync* { yield* new Iterable<int>(); }
2799 Iterable<int> baz5() sync* { yield* (/*info:INFERRED_TYPE_ALLOCATION*/ne w Iterable()); } 2846 Iterable<int> baz5() sync* { yield* (/*info:INFERRED_TYPE_ALLOCATION*/ne w Iterable()); }
2800 '''); 2847 ''');
2801 }); 2848 });
2802 }); 2849 });
2803 } 2850 }
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