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

Side by Side Diff: pkg/analyzer/test/generated/resolver_test.dart

Issue 2625783002: Explicitly compute analysis results for sources to check errors. (Closed)
Patch Set: Created 3 years, 11 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
OLDNEW
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 analyzer.test.generated.resolver_test; 5 library analyzer.test.generated.resolver_test;
6 6
7 import 'dart:collection'; 7 import 'dart:collection';
8 8
9 import 'package:analyzer/dart/ast/ast.dart'; 9 import 'package:analyzer/dart/ast/ast.dart';
10 import 'package:analyzer/dart/ast/standard_ast_factory.dart'; 10 import 'package:analyzer/dart/ast/standard_ast_factory.dart';
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 class A { 165 class A {
166 void m(int i) { 166 void m(int i) {
167 switch (i) { 167 switch (i) {
168 l: case 0: 168 l: case 0:
169 break; 169 break;
170 case 1: 170 case 1:
171 break l; 171 break l;
172 } 172 }
173 } 173 }
174 }'''); 174 }''');
175 await computeAnalysisResult(source);
175 await assertErrors( 176 await assertErrors(
176 source, [ResolverErrorCode.BREAK_LABEL_ON_SWITCH_MEMBER]); 177 source, [ResolverErrorCode.BREAK_LABEL_ON_SWITCH_MEMBER]);
177 verify([source]); 178 verify([source]);
178 } 179 }
179 180
180 test_continueLabelOnSwitch() async { 181 test_continueLabelOnSwitch() async {
181 Source source = addSource(r''' 182 Source source = addSource(r'''
182 class A { 183 class A {
183 void m(int i) { 184 void m(int i) {
184 l: switch (i) { 185 l: switch (i) {
185 case 0: 186 case 0:
186 continue l; 187 continue l;
187 } 188 }
188 } 189 }
189 }'''); 190 }''');
190 await assertErrors(source, [ResolverErrorCode.CONTINUE_LABEL_ON_SWITCH]); 191 await computeAnalysisResult(source); await assertErrors(source, [ResolverErr orCode.CONTINUE_LABEL_ON_SWITCH]);
Brian Wilkerson 2017/01/10 20:53:34 Perhaps format file this so that the two statement
191 verify([source]); 192 verify([source]);
192 } 193 }
193 194
194 test_enclosingElement_invalidLocalFunction() async { 195 test_enclosingElement_invalidLocalFunction() async {
195 Source source = addSource(r''' 196 Source source = addSource(r'''
196 class C { 197 class C {
197 C() { 198 C() {
198 int get x => 0; 199 int get x => 0;
199 } 200 }
200 }'''); 201 }''');
201 LibraryElement library = resolve2(source); 202 LibraryElement library = resolve2(source);
202 expect(library, isNotNull); 203 expect(library, isNotNull);
203 var unit = library.definingCompilationUnit; 204 var unit = library.definingCompilationUnit;
204 expect(unit, isNotNull); 205 expect(unit, isNotNull);
205 var types = unit.types; 206 var types = unit.types;
206 expect(types, isNotNull); 207 expect(types, isNotNull);
207 expect(types, hasLength(1)); 208 expect(types, hasLength(1));
208 var type = types[0]; 209 var type = types[0];
209 expect(type, isNotNull); 210 expect(type, isNotNull);
210 var constructors = type.constructors; 211 var constructors = type.constructors;
211 expect(constructors, isNotNull); 212 expect(constructors, isNotNull);
212 expect(constructors, hasLength(1)); 213 expect(constructors, hasLength(1));
213 ConstructorElement constructor = constructors[0]; 214 ConstructorElement constructor = constructors[0];
214 expect(constructor, isNotNull); 215 expect(constructor, isNotNull);
215 List<FunctionElement> functions = constructor.functions; 216 List<FunctionElement> functions = constructor.functions;
216 expect(functions, isNotNull); 217 expect(functions, isNotNull);
217 expect(functions, hasLength(1)); 218 expect(functions, hasLength(1));
218 expect(functions[0].enclosingElement, constructor); 219 expect(functions[0].enclosingElement, constructor);
219 await assertErrors(source, [ParserErrorCode.GETTER_IN_FUNCTION]); 220 await computeAnalysisResult(source); await assertErrors(source, [ParserError Code.GETTER_IN_FUNCTION]);
220 } 221 }
221 } 222 }
222 223
223 /** 224 /**
224 * Tests for generic method and function resolution that do not use strong mode. 225 * Tests for generic method and function resolution that do not use strong mode.
225 */ 226 */
226 @reflectiveTest 227 @reflectiveTest
227 class GenericMethodResolverTest extends StaticTypeAnalyzer2TestShared { 228 class GenericMethodResolverTest extends StaticTypeAnalyzer2TestShared {
228 test_genericMethod_propagatedType_promotion() async { 229 test_genericMethod_propagatedType_promotion() async {
229 // Regression test for: 230 // Regression test for:
(...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after
615 @reflectiveTest 616 @reflectiveTest
616 class StrictModeTest extends ResolverTestCase { 617 class StrictModeTest extends ResolverTestCase {
617 fail_for() async { 618 fail_for() async {
618 Source source = addSource(r''' 619 Source source = addSource(r'''
619 int f(List<int> list) { 620 int f(List<int> list) {
620 num sum = 0; 621 num sum = 0;
621 for (num i = 0; i < list.length; i++) { 622 for (num i = 0; i < list.length; i++) {
622 sum += list[i]; 623 sum += list[i];
623 } 624 }
624 }'''); 625 }''');
625 await assertErrors(source, [StaticTypeWarningCode.UNDEFINED_OPERATOR]); 626 await computeAnalysisResult(source); await assertErrors(source, [StaticTypeW arningCode.UNDEFINED_OPERATOR]);
626 } 627 }
627 628
628 @override 629 @override
629 void setUp() { 630 void setUp() {
630 AnalysisOptionsImpl options = new AnalysisOptionsImpl(); 631 AnalysisOptionsImpl options = new AnalysisOptionsImpl();
631 options.hint = false; 632 options.hint = false;
632 resetWithOptions(options); 633 resetWithOptions(options);
633 } 634 }
634 635
635 test_assert_is() async { 636 test_assert_is() async {
636 Source source = addSource(r''' 637 Source source = addSource(r'''
637 int f(num n) { 638 int f(num n) {
638 assert (n is int); 639 assert (n is int);
639 return n & 0x0F; 640 return n & 0x0F;
640 }'''); 641 }''');
641 await assertErrors(source, [StaticTypeWarningCode.UNDEFINED_OPERATOR]); 642 await computeAnalysisResult(source); await assertErrors(source, [StaticTypeW arningCode.UNDEFINED_OPERATOR]);
642 } 643 }
643 644
644 test_conditional_and_is() async { 645 test_conditional_and_is() async {
645 Source source = addSource(r''' 646 Source source = addSource(r'''
646 int f(num n) { 647 int f(num n) {
647 return (n is int && n > 0) ? n & 0x0F : 0; 648 return (n is int && n > 0) ? n & 0x0F : 0;
648 }'''); 649 }''');
649 await assertNoErrors(source); 650 await computeAnalysisResult(source); await assertNoErrors(source);
650 } 651 }
651 652
652 test_conditional_is() async { 653 test_conditional_is() async {
653 Source source = addSource(r''' 654 Source source = addSource(r'''
654 int f(num n) { 655 int f(num n) {
655 return (n is int) ? n & 0x0F : 0; 656 return (n is int) ? n & 0x0F : 0;
656 }'''); 657 }''');
657 await assertNoErrors(source); 658 await computeAnalysisResult(source); await assertNoErrors(source);
658 } 659 }
659 660
660 test_conditional_isNot() async { 661 test_conditional_isNot() async {
661 Source source = addSource(r''' 662 Source source = addSource(r'''
662 int f(num n) { 663 int f(num n) {
663 return (n is! int) ? 0 : n & 0x0F; 664 return (n is! int) ? 0 : n & 0x0F;
664 }'''); 665 }''');
665 await assertErrors(source, [StaticTypeWarningCode.UNDEFINED_OPERATOR]); 666 await computeAnalysisResult(source); await assertErrors(source, [StaticTypeW arningCode.UNDEFINED_OPERATOR]);
666 } 667 }
667 668
668 test_conditional_or_is() async { 669 test_conditional_or_is() async {
669 Source source = addSource(r''' 670 Source source = addSource(r'''
670 int f(num n) { 671 int f(num n) {
671 return (n is! int || n < 0) ? 0 : n & 0x0F; 672 return (n is! int || n < 0) ? 0 : n & 0x0F;
672 }'''); 673 }''');
673 await assertErrors(source, [StaticTypeWarningCode.UNDEFINED_OPERATOR]); 674 await computeAnalysisResult(source); await assertErrors(source, [StaticTypeW arningCode.UNDEFINED_OPERATOR]);
674 } 675 }
675 676
676 test_forEach() async { 677 test_forEach() async {
677 Source source = addSource(r''' 678 Source source = addSource(r'''
678 int f(List<int> list) { 679 int f(List<int> list) {
679 num sum = 0; 680 num sum = 0;
680 for (num n in list) { 681 for (num n in list) {
681 sum += n & 0x0F; 682 sum += n & 0x0F;
682 } 683 }
683 }'''); 684 }''');
684 await assertErrors(source, [StaticTypeWarningCode.UNDEFINED_OPERATOR]); 685 await computeAnalysisResult(source); await assertErrors(source, [StaticTypeW arningCode.UNDEFINED_OPERATOR]);
685 } 686 }
686 687
687 test_if_and_is() async { 688 test_if_and_is() async {
688 Source source = addSource(r''' 689 Source source = addSource(r'''
689 int f(num n) { 690 int f(num n) {
690 if (n is int && n > 0) { 691 if (n is int && n > 0) {
691 return n & 0x0F; 692 return n & 0x0F;
692 } 693 }
693 return 0; 694 return 0;
694 }'''); 695 }''');
695 await assertNoErrors(source); 696 await computeAnalysisResult(source); await assertNoErrors(source);
696 } 697 }
697 698
698 test_if_is() async { 699 test_if_is() async {
699 Source source = addSource(r''' 700 Source source = addSource(r'''
700 int f(num n) { 701 int f(num n) {
701 if (n is int) { 702 if (n is int) {
702 return n & 0x0F; 703 return n & 0x0F;
703 } 704 }
704 return 0; 705 return 0;
705 }'''); 706 }''');
706 await assertNoErrors(source); 707 await computeAnalysisResult(source); await assertNoErrors(source);
707 } 708 }
708 709
709 test_if_isNot() async { 710 test_if_isNot() async {
710 Source source = addSource(r''' 711 Source source = addSource(r'''
711 int f(num n) { 712 int f(num n) {
712 if (n is! int) { 713 if (n is! int) {
713 return 0; 714 return 0;
714 } else { 715 } else {
715 return n & 0x0F; 716 return n & 0x0F;
716 } 717 }
717 }'''); 718 }''');
718 await assertErrors(source, [StaticTypeWarningCode.UNDEFINED_OPERATOR]); 719 await computeAnalysisResult(source); await assertErrors(source, [StaticTypeW arningCode.UNDEFINED_OPERATOR]);
719 } 720 }
720 721
721 test_if_isNot_abrupt() async { 722 test_if_isNot_abrupt() async {
722 Source source = addSource(r''' 723 Source source = addSource(r'''
723 int f(num n) { 724 int f(num n) {
724 if (n is! int) { 725 if (n is! int) {
725 return 0; 726 return 0;
726 } 727 }
727 return n & 0x0F; 728 return n & 0x0F;
728 }'''); 729 }''');
729 await assertErrors(source, [StaticTypeWarningCode.UNDEFINED_OPERATOR]); 730 await computeAnalysisResult(source); await assertErrors(source, [StaticTypeW arningCode.UNDEFINED_OPERATOR]);
730 } 731 }
731 732
732 test_if_or_is() async { 733 test_if_or_is() async {
733 Source source = addSource(r''' 734 Source source = addSource(r'''
734 int f(num n) { 735 int f(num n) {
735 if (n is! int || n < 0) { 736 if (n is! int || n < 0) {
736 return 0; 737 return 0;
737 } else { 738 } else {
738 return n & 0x0F; 739 return n & 0x0F;
739 } 740 }
740 }'''); 741 }''');
741 await assertErrors(source, [StaticTypeWarningCode.UNDEFINED_OPERATOR]); 742 await computeAnalysisResult(source); await assertErrors(source, [StaticTypeW arningCode.UNDEFINED_OPERATOR]);
742 } 743 }
743 744
744 test_localVar() async { 745 test_localVar() async {
745 Source source = addSource(r''' 746 Source source = addSource(r'''
746 int f() { 747 int f() {
747 num n = 1234; 748 num n = 1234;
748 return n & 0x0F; 749 return n & 0x0F;
749 }'''); 750 }''');
750 await assertErrors(source, [StaticTypeWarningCode.UNDEFINED_OPERATOR]); 751 await computeAnalysisResult(source); await assertErrors(source, [StaticTypeW arningCode.UNDEFINED_OPERATOR]);
751 } 752 }
752 } 753 }
753 754
754 @reflectiveTest 755 @reflectiveTest
755 class SubtypeManagerTest { 756 class SubtypeManagerTest {
756 /** 757 /**
757 * The inheritance manager being tested. 758 * The inheritance manager being tested.
758 */ 759 */
759 SubtypeManager _subtypeManager; 760 SubtypeManager _subtypeManager;
760 761
(...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after
1070 bool get g => true; 1071 bool get g => true;
1071 } 1072 }
1072 A f(var p) { 1073 A f(var p) {
1073 if ((p as A).g) { 1074 if ((p as A).g) {
1074 return p; 1075 return p;
1075 } else { 1076 } else {
1076 return null; 1077 return null;
1077 } 1078 }
1078 }'''); 1079 }''');
1079 LibraryElement library = resolve2(source); 1080 LibraryElement library = resolve2(source);
1080 await assertNoErrors(source); 1081 await computeAnalysisResult(source); await assertNoErrors(source);
1081 verify([source]); 1082 verify([source]);
1082 CompilationUnit unit = resolveCompilationUnit(source, library); 1083 CompilationUnit unit = resolveCompilationUnit(source, library);
1083 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration; 1084 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration;
1084 InterfaceType typeA = 1085 InterfaceType typeA =
1085 resolutionMap.elementDeclaredByClassDeclaration(classA).type; 1086 resolutionMap.elementDeclaredByClassDeclaration(classA).type;
1086 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration; 1087 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration;
1087 BlockFunctionBody body = 1088 BlockFunctionBody body =
1088 function.functionExpression.body as BlockFunctionBody; 1089 function.functionExpression.body as BlockFunctionBody;
1089 IfStatement ifStatement = body.block.statements[0] as IfStatement; 1090 IfStatement ifStatement = body.block.statements[0] as IfStatement;
1090 ReturnStatement statement = 1091 ReturnStatement statement =
1091 (ifStatement.thenStatement as Block).statements[0] as ReturnStatement; 1092 (ifStatement.thenStatement as Block).statements[0] as ReturnStatement;
1092 SimpleIdentifier variableName = statement.expression as SimpleIdentifier; 1093 SimpleIdentifier variableName = statement.expression as SimpleIdentifier;
1093 expect(variableName.propagatedType, same(typeA)); 1094 expect(variableName.propagatedType, same(typeA));
1094 } 1095 }
1095 1096
1096 test_assert() async { 1097 test_assert() async {
1097 Source source = addSource(r''' 1098 Source source = addSource(r'''
1098 class A {} 1099 class A {}
1099 A f(var p) { 1100 A f(var p) {
1100 assert (p is A); 1101 assert (p is A);
1101 return p; 1102 return p;
1102 }'''); 1103 }''');
1103 LibraryElement library = resolve2(source); 1104 LibraryElement library = resolve2(source);
1104 await assertNoErrors(source); 1105 await computeAnalysisResult(source); await assertNoErrors(source);
1105 verify([source]); 1106 verify([source]);
1106 CompilationUnit unit = resolveCompilationUnit(source, library); 1107 CompilationUnit unit = resolveCompilationUnit(source, library);
1107 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration; 1108 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration;
1108 InterfaceType typeA = 1109 InterfaceType typeA =
1109 resolutionMap.elementDeclaredByClassDeclaration(classA).type; 1110 resolutionMap.elementDeclaredByClassDeclaration(classA).type;
1110 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration; 1111 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration;
1111 BlockFunctionBody body = 1112 BlockFunctionBody body =
1112 function.functionExpression.body as BlockFunctionBody; 1113 function.functionExpression.body as BlockFunctionBody;
1113 ReturnStatement statement = body.block.statements[1] as ReturnStatement; 1114 ReturnStatement statement = body.block.statements[1] as ReturnStatement;
1114 SimpleIdentifier variableName = statement.expression as SimpleIdentifier; 1115 SimpleIdentifier variableName = statement.expression as SimpleIdentifier;
1115 expect(variableName.propagatedType, same(typeA)); 1116 expect(variableName.propagatedType, same(typeA));
1116 } 1117 }
1117 1118
1118 test_assignment() async { 1119 test_assignment() async {
1119 Source source = addSource(r''' 1120 Source source = addSource(r'''
1120 f() { 1121 f() {
1121 var v; 1122 var v;
1122 v = 0; 1123 v = 0;
1123 return v; 1124 return v;
1124 }'''); 1125 }''');
1125 LibraryElement library = resolve2(source); 1126 LibraryElement library = resolve2(source);
1126 await assertNoErrors(source); 1127 await computeAnalysisResult(source); await assertNoErrors(source);
1127 verify([source]); 1128 verify([source]);
1128 CompilationUnit unit = resolveCompilationUnit(source, library); 1129 CompilationUnit unit = resolveCompilationUnit(source, library);
1129 FunctionDeclaration function = unit.declarations[0] as FunctionDeclaration; 1130 FunctionDeclaration function = unit.declarations[0] as FunctionDeclaration;
1130 BlockFunctionBody body = 1131 BlockFunctionBody body =
1131 function.functionExpression.body as BlockFunctionBody; 1132 function.functionExpression.body as BlockFunctionBody;
1132 ReturnStatement statement = body.block.statements[2] as ReturnStatement; 1133 ReturnStatement statement = body.block.statements[2] as ReturnStatement;
1133 SimpleIdentifier variableName = statement.expression as SimpleIdentifier; 1134 SimpleIdentifier variableName = statement.expression as SimpleIdentifier;
1134 expect(variableName.propagatedType, same(typeProvider.intType)); 1135 expect(variableName.propagatedType, same(typeProvider.intType));
1135 } 1136 }
1136 1137
1137 test_assignment_afterInitializer() async { 1138 test_assignment_afterInitializer() async {
1138 Source source = addSource(r''' 1139 Source source = addSource(r'''
1139 f() { 1140 f() {
1140 var v = 0; 1141 var v = 0;
1141 v = 1.0; 1142 v = 1.0;
1142 return v; 1143 return v;
1143 }'''); 1144 }''');
1144 LibraryElement library = resolve2(source); 1145 LibraryElement library = resolve2(source);
1145 await assertNoErrors(source); 1146 await computeAnalysisResult(source); await assertNoErrors(source);
1146 verify([source]); 1147 verify([source]);
1147 CompilationUnit unit = resolveCompilationUnit(source, library); 1148 CompilationUnit unit = resolveCompilationUnit(source, library);
1148 FunctionDeclaration function = unit.declarations[0] as FunctionDeclaration; 1149 FunctionDeclaration function = unit.declarations[0] as FunctionDeclaration;
1149 BlockFunctionBody body = 1150 BlockFunctionBody body =
1150 function.functionExpression.body as BlockFunctionBody; 1151 function.functionExpression.body as BlockFunctionBody;
1151 ReturnStatement statement = body.block.statements[2] as ReturnStatement; 1152 ReturnStatement statement = body.block.statements[2] as ReturnStatement;
1152 SimpleIdentifier variableName = statement.expression as SimpleIdentifier; 1153 SimpleIdentifier variableName = statement.expression as SimpleIdentifier;
1153 expect(variableName.propagatedType, same(typeProvider.doubleType)); 1154 expect(variableName.propagatedType, same(typeProvider.doubleType));
1154 } 1155 }
1155 1156
1156 test_assignment_null() async { 1157 test_assignment_null() async {
1157 String code = r''' 1158 String code = r'''
1158 main() { 1159 main() {
1159 int v; // declare 1160 int v; // declare
1160 v = null; 1161 v = null;
1161 return v; // return 1162 return v; // return
1162 }'''; 1163 }''';
1163 CompilationUnit unit; 1164 CompilationUnit unit;
1164 { 1165 {
1165 Source source = addSource(code); 1166 Source source = addSource(code);
1166 LibraryElement library = resolve2(source); 1167 LibraryElement library = resolve2(source);
1167 await assertNoErrors(source); 1168 await computeAnalysisResult(source); await assertNoErrors(source);
1168 verify([source]); 1169 verify([source]);
1169 unit = resolveCompilationUnit(source, library); 1170 unit = resolveCompilationUnit(source, library);
1170 } 1171 }
1171 { 1172 {
1172 SimpleIdentifier identifier = EngineTestCase.findNode( 1173 SimpleIdentifier identifier = EngineTestCase.findNode(
1173 unit, code, "v; // declare", (node) => node is SimpleIdentifier); 1174 unit, code, "v; // declare", (node) => node is SimpleIdentifier);
1174 expect(identifier.staticType, same(typeProvider.intType)); 1175 expect(identifier.staticType, same(typeProvider.intType));
1175 expect(identifier.propagatedType, same(null)); 1176 expect(identifier.propagatedType, same(null));
1176 } 1177 }
1177 { 1178 {
(...skipping 11 matching lines...) Expand all
1189 } 1190 }
1190 1191
1191 test_CanvasElement_getContext() async { 1192 test_CanvasElement_getContext() async {
1192 String code = r''' 1193 String code = r'''
1193 import 'dart:html'; 1194 import 'dart:html';
1194 main(CanvasElement canvas) { 1195 main(CanvasElement canvas) {
1195 var context = canvas.getContext('2d'); 1196 var context = canvas.getContext('2d');
1196 }'''; 1197 }''';
1197 Source source = addSource(code); 1198 Source source = addSource(code);
1198 LibraryElement library = resolve2(source); 1199 LibraryElement library = resolve2(source);
1199 await assertNoErrors(source); 1200 await computeAnalysisResult(source); await assertNoErrors(source);
1200 verify([source]); 1201 verify([source]);
1201 CompilationUnit unit = resolveCompilationUnit(source, library); 1202 CompilationUnit unit = resolveCompilationUnit(source, library);
1202 SimpleIdentifier identifier = EngineTestCase.findNode( 1203 SimpleIdentifier identifier = EngineTestCase.findNode(
1203 unit, code, "context", (node) => node is SimpleIdentifier); 1204 unit, code, "context", (node) => node is SimpleIdentifier);
1204 expect(resolutionMap.propagatedTypeForExpression(identifier).name, 1205 expect(resolutionMap.propagatedTypeForExpression(identifier).name,
1205 "CanvasRenderingContext2D"); 1206 "CanvasRenderingContext2D");
1206 } 1207 }
1207 1208
1208 test_forEach() async { 1209 test_forEach() async {
1209 String code = r''' 1210 String code = r'''
1210 main() { 1211 main() {
1211 var list = <String> []; 1212 var list = <String> [];
1212 for (var e in list) { 1213 for (var e in list) {
1213 e; 1214 e;
1214 } 1215 }
1215 }'''; 1216 }''';
1216 Source source = addSource(code); 1217 Source source = addSource(code);
1217 LibraryElement library = resolve2(source); 1218 LibraryElement library = resolve2(source);
1218 await assertNoErrors(source); 1219 await computeAnalysisResult(source); await assertNoErrors(source);
1219 verify([source]); 1220 verify([source]);
1220 CompilationUnit unit = resolveCompilationUnit(source, library); 1221 CompilationUnit unit = resolveCompilationUnit(source, library);
1221 InterfaceType stringType = typeProvider.stringType; 1222 InterfaceType stringType = typeProvider.stringType;
1222 // in the declaration 1223 // in the declaration
1223 { 1224 {
1224 SimpleIdentifier identifier = EngineTestCase.findNode( 1225 SimpleIdentifier identifier = EngineTestCase.findNode(
1225 unit, code, "e in", (node) => node is SimpleIdentifier); 1226 unit, code, "e in", (node) => node is SimpleIdentifier);
1226 expect(identifier.propagatedType, same(stringType)); 1227 expect(identifier.propagatedType, same(stringType));
1227 } 1228 }
1228 // in the loop body 1229 // in the loop body
1229 { 1230 {
1230 SimpleIdentifier identifier = EngineTestCase.findNode( 1231 SimpleIdentifier identifier = EngineTestCase.findNode(
1231 unit, code, "e;", (node) => node is SimpleIdentifier); 1232 unit, code, "e;", (node) => node is SimpleIdentifier);
1232 expect(identifier.propagatedType, same(stringType)); 1233 expect(identifier.propagatedType, same(stringType));
1233 } 1234 }
1234 } 1235 }
1235 1236
1236 test_forEach_async() async { 1237 test_forEach_async() async {
1237 String code = r''' 1238 String code = r'''
1238 import 'dart:async'; 1239 import 'dart:async';
1239 f(Stream<String> stream) async { 1240 f(Stream<String> stream) async {
1240 await for (var e in stream) { 1241 await for (var e in stream) {
1241 e; 1242 e;
1242 } 1243 }
1243 }'''; 1244 }''';
1244 Source source = addSource(code); 1245 Source source = addSource(code);
1245 LibraryElement library = resolve2(source); 1246 LibraryElement library = resolve2(source);
1246 await assertNoErrors(source); 1247 await computeAnalysisResult(source); await assertNoErrors(source);
1247 verify([source]); 1248 verify([source]);
1248 CompilationUnit unit = resolveCompilationUnit(source, library); 1249 CompilationUnit unit = resolveCompilationUnit(source, library);
1249 InterfaceType stringType = typeProvider.stringType; 1250 InterfaceType stringType = typeProvider.stringType;
1250 // in the declaration 1251 // in the declaration
1251 { 1252 {
1252 SimpleIdentifier identifier = EngineTestCase.findNode( 1253 SimpleIdentifier identifier = EngineTestCase.findNode(
1253 unit, code, "e in", (node) => node is SimpleIdentifier); 1254 unit, code, "e in", (node) => node is SimpleIdentifier);
1254 expect(identifier.propagatedType, same(stringType)); 1255 expect(identifier.propagatedType, same(stringType));
1255 } 1256 }
1256 // in the loop body 1257 // in the loop body
(...skipping 11 matching lines...) Expand all
1268 String code = r''' 1269 String code = r'''
1269 import 'dart:async'; 1270 import 'dart:async';
1270 abstract class MyCustomStream<T> implements Stream<List<T>> {} 1271 abstract class MyCustomStream<T> implements Stream<List<T>> {}
1271 f(MyCustomStream<String> stream) async { 1272 f(MyCustomStream<String> stream) async {
1272 await for (var e in stream) { 1273 await for (var e in stream) {
1273 e; 1274 e;
1274 } 1275 }
1275 }'''; 1276 }''';
1276 Source source = addSource(code); 1277 Source source = addSource(code);
1277 LibraryElement library = resolve2(source); 1278 LibraryElement library = resolve2(source);
1278 await assertNoErrors(source); 1279 await computeAnalysisResult(source); await assertNoErrors(source);
1279 verify([source]); 1280 verify([source]);
1280 CompilationUnit unit = resolveCompilationUnit(source, library); 1281 CompilationUnit unit = resolveCompilationUnit(source, library);
1281 InterfaceType listOfStringType = 1282 InterfaceType listOfStringType =
1282 typeProvider.listType.instantiate([typeProvider.stringType]); 1283 typeProvider.listType.instantiate([typeProvider.stringType]);
1283 // in the declaration 1284 // in the declaration
1284 { 1285 {
1285 SimpleIdentifier identifier = EngineTestCase.findNode( 1286 SimpleIdentifier identifier = EngineTestCase.findNode(
1286 unit, code, "e in", (node) => node is SimpleIdentifier); 1287 unit, code, "e in", (node) => node is SimpleIdentifier);
1287 expect(identifier.propagatedType, equals(listOfStringType)); 1288 expect(identifier.propagatedType, equals(listOfStringType));
1288 } 1289 }
(...skipping 11 matching lines...) Expand all
1300 forEach(f(K key, V value)) {} 1301 forEach(f(K key, V value)) {}
1301 } 1302 }
1302 f(MyMap<int, String> m) { 1303 f(MyMap<int, String> m) {
1303 m.forEach((k, v) { 1304 m.forEach((k, v) {
1304 k; 1305 k;
1305 v; 1306 v;
1306 }); 1307 });
1307 }'''; 1308 }''';
1308 Source source = addSource(code); 1309 Source source = addSource(code);
1309 LibraryElement library = resolve2(source); 1310 LibraryElement library = resolve2(source);
1310 await assertNoErrors(source); 1311 await computeAnalysisResult(source); await assertNoErrors(source);
1311 verify([source]); 1312 verify([source]);
1312 CompilationUnit unit = resolveCompilationUnit(source, library); 1313 CompilationUnit unit = resolveCompilationUnit(source, library);
1313 // k 1314 // k
1314 DartType intType = typeProvider.intType; 1315 DartType intType = typeProvider.intType;
1315 FormalParameter kParameter = EngineTestCase.findNode( 1316 FormalParameter kParameter = EngineTestCase.findNode(
1316 unit, code, "k, ", (node) => node is SimpleFormalParameter); 1317 unit, code, "k, ", (node) => node is SimpleFormalParameter);
1317 expect(kParameter.identifier.propagatedType, same(intType)); 1318 expect(kParameter.identifier.propagatedType, same(intType));
1318 SimpleIdentifier kIdentifier = EngineTestCase.findNode( 1319 SimpleIdentifier kIdentifier = EngineTestCase.findNode(
1319 unit, code, "k;", (node) => node is SimpleIdentifier); 1320 unit, code, "k;", (node) => node is SimpleIdentifier);
1320 expect(kIdentifier.propagatedType, same(intType)); 1321 expect(kIdentifier.propagatedType, same(intType));
(...skipping 13 matching lines...) Expand all
1334 String code = r''' 1335 String code = r'''
1335 class MyMap<K, V> { 1336 class MyMap<K, V> {
1336 forEach(f(K key, V value)) {} 1337 forEach(f(K key, V value)) {}
1337 } 1338 }
1338 f(MyMap<int, String> m) { 1339 f(MyMap<int, String> m) {
1339 var m2 = m; 1340 var m2 = m;
1340 m2.forEach((k, v) {}); 1341 m2.forEach((k, v) {});
1341 }'''; 1342 }''';
1342 Source source = addSource(code); 1343 Source source = addSource(code);
1343 LibraryElement library = resolve2(source); 1344 LibraryElement library = resolve2(source);
1344 await assertNoErrors(source); 1345 await computeAnalysisResult(source); await assertNoErrors(source);
1345 verify([source]); 1346 verify([source]);
1346 CompilationUnit unit = resolveCompilationUnit(source, library); 1347 CompilationUnit unit = resolveCompilationUnit(source, library);
1347 // k 1348 // k
1348 DartType intType = typeProvider.intType; 1349 DartType intType = typeProvider.intType;
1349 FormalParameter kParameter = EngineTestCase.findNode( 1350 FormalParameter kParameter = EngineTestCase.findNode(
1350 unit, code, "k, ", (node) => node is SimpleFormalParameter); 1351 unit, code, "k, ", (node) => node is SimpleFormalParameter);
1351 expect(kParameter.identifier.propagatedType, same(intType)); 1352 expect(kParameter.identifier.propagatedType, same(intType));
1352 // v 1353 // v
1353 DartType stringType = typeProvider.stringType; 1354 DartType stringType = typeProvider.stringType;
1354 FormalParameter vParameter = EngineTestCase.findNode( 1355 FormalParameter vParameter = EngineTestCase.findNode(
1355 unit, code, "v)", (node) => node is SimpleFormalParameter); 1356 unit, code, "v)", (node) => node is SimpleFormalParameter);
1356 expect(vParameter.identifier.propagatedType, same(stringType)); 1357 expect(vParameter.identifier.propagatedType, same(stringType));
1357 } 1358 }
1358 1359
1359 test_functionExpression_asInvocationArgument_functionExpressionInvocation() as ync { 1360 test_functionExpression_asInvocationArgument_functionExpressionInvocation() as ync {
1360 String code = r''' 1361 String code = r'''
1361 main() { 1362 main() {
1362 (f(String value)) {} ((v) { 1363 (f(String value)) {} ((v) {
1363 v; 1364 v;
1364 }); 1365 });
1365 }'''; 1366 }''';
1366 Source source = addSource(code); 1367 Source source = addSource(code);
1367 LibraryElement library = resolve2(source); 1368 LibraryElement library = resolve2(source);
1368 await assertNoErrors(source); 1369 await computeAnalysisResult(source); await assertNoErrors(source);
1369 verify([source]); 1370 verify([source]);
1370 CompilationUnit unit = resolveCompilationUnit(source, library); 1371 CompilationUnit unit = resolveCompilationUnit(source, library);
1371 // v 1372 // v
1372 DartType dynamicType = typeProvider.dynamicType; 1373 DartType dynamicType = typeProvider.dynamicType;
1373 DartType stringType = typeProvider.stringType; 1374 DartType stringType = typeProvider.stringType;
1374 FormalParameter vParameter = EngineTestCase.findNode( 1375 FormalParameter vParameter = EngineTestCase.findNode(
1375 unit, code, "v)", (node) => node is FormalParameter); 1376 unit, code, "v)", (node) => node is FormalParameter);
1376 expect(vParameter.identifier.propagatedType, same(stringType)); 1377 expect(vParameter.identifier.propagatedType, same(stringType));
1377 expect(vParameter.identifier.staticType, same(dynamicType)); 1378 expect(vParameter.identifier.staticType, same(dynamicType));
1378 SimpleIdentifier vIdentifier = EngineTestCase.findNode( 1379 SimpleIdentifier vIdentifier = EngineTestCase.findNode(
1379 unit, code, "v;", (node) => node is SimpleIdentifier); 1380 unit, code, "v;", (node) => node is SimpleIdentifier);
1380 expect(vIdentifier.propagatedType, same(stringType)); 1381 expect(vIdentifier.propagatedType, same(stringType));
1381 expect(vIdentifier.staticType, same(dynamicType)); 1382 expect(vIdentifier.staticType, same(dynamicType));
1382 } 1383 }
1383 1384
1384 test_functionExpression_asInvocationArgument_keepIfLessSpecific() async { 1385 test_functionExpression_asInvocationArgument_keepIfLessSpecific() async {
1385 String code = r''' 1386 String code = r'''
1386 class MyList { 1387 class MyList {
1387 forEach(f(Object value)) {} 1388 forEach(f(Object value)) {}
1388 } 1389 }
1389 f(MyList list) { 1390 f(MyList list) {
1390 list.forEach((int v) { 1391 list.forEach((int v) {
1391 v; 1392 v;
1392 }); 1393 });
1393 }'''; 1394 }''';
1394 Source source = addSource(code); 1395 Source source = addSource(code);
1395 LibraryElement library = resolve2(source); 1396 LibraryElement library = resolve2(source);
1396 await assertNoErrors(source); 1397 await computeAnalysisResult(source); await assertNoErrors(source);
1397 verify([source]); 1398 verify([source]);
1398 CompilationUnit unit = resolveCompilationUnit(source, library); 1399 CompilationUnit unit = resolveCompilationUnit(source, library);
1399 // v 1400 // v
1400 DartType intType = typeProvider.intType; 1401 DartType intType = typeProvider.intType;
1401 FormalParameter vParameter = EngineTestCase.findNode( 1402 FormalParameter vParameter = EngineTestCase.findNode(
1402 unit, code, "v)", (node) => node is SimpleFormalParameter); 1403 unit, code, "v)", (node) => node is SimpleFormalParameter);
1403 expect(vParameter.identifier.propagatedType, same(null)); 1404 expect(vParameter.identifier.propagatedType, same(null));
1404 expect(vParameter.identifier.staticType, same(intType)); 1405 expect(vParameter.identifier.staticType, same(intType));
1405 SimpleIdentifier vIdentifier = EngineTestCase.findNode( 1406 SimpleIdentifier vIdentifier = EngineTestCase.findNode(
1406 unit, code, "v;", (node) => node is SimpleIdentifier); 1407 unit, code, "v;", (node) => node is SimpleIdentifier);
1407 expect(vIdentifier.staticType, same(intType)); 1408 expect(vIdentifier.staticType, same(intType));
1408 expect(vIdentifier.propagatedType, same(null)); 1409 expect(vIdentifier.propagatedType, same(null));
1409 } 1410 }
1410 1411
1411 test_functionExpression_asInvocationArgument_notSubtypeOfStaticType() async { 1412 test_functionExpression_asInvocationArgument_notSubtypeOfStaticType() async {
1412 String code = r''' 1413 String code = r'''
1413 class A { 1414 class A {
1414 m(void f(int i)) {} 1415 m(void f(int i)) {}
1415 } 1416 }
1416 x() { 1417 x() {
1417 A a = new A(); 1418 A a = new A();
1418 a.m(() => 0); 1419 a.m(() => 0);
1419 }'''; 1420 }''';
1420 Source source = addSource(code); 1421 Source source = addSource(code);
1421 LibraryElement library = resolve2(source); 1422 LibraryElement library = resolve2(source);
1423 await computeAnalysisResult(source);
1422 await assertErrors( 1424 await assertErrors(
1423 source, [StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE]); 1425 source, [StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE]);
1424 verify([source]); 1426 verify([source]);
1425 CompilationUnit unit = resolveCompilationUnit(source, library); 1427 CompilationUnit unit = resolveCompilationUnit(source, library);
1426 // () => 0 1428 // () => 0
1427 FunctionExpression functionExpression = EngineTestCase.findNode( 1429 FunctionExpression functionExpression = EngineTestCase.findNode(
1428 unit, code, "() => 0)", (node) => node is FunctionExpression); 1430 unit, code, "() => 0)", (node) => node is FunctionExpression);
1429 expect((functionExpression.staticType as FunctionType).parameters.length, 1431 expect((functionExpression.staticType as FunctionType).parameters.length,
1430 same(0)); 1432 same(0));
1431 expect(functionExpression.propagatedType, same(null)); 1433 expect(functionExpression.propagatedType, same(null));
1432 } 1434 }
1433 1435
1434 test_functionExpression_asInvocationArgument_replaceIfMoreSpecific() async { 1436 test_functionExpression_asInvocationArgument_replaceIfMoreSpecific() async {
1435 String code = r''' 1437 String code = r'''
1436 class MyList<E> { 1438 class MyList<E> {
1437 forEach(f(E value)) {} 1439 forEach(f(E value)) {}
1438 } 1440 }
1439 f(MyList<String> list) { 1441 f(MyList<String> list) {
1440 list.forEach((Object v) { 1442 list.forEach((Object v) {
1441 v; 1443 v;
1442 }); 1444 });
1443 }'''; 1445 }''';
1444 Source source = addSource(code); 1446 Source source = addSource(code);
1445 LibraryElement library = resolve2(source); 1447 LibraryElement library = resolve2(source);
1446 await assertNoErrors(source); 1448 await computeAnalysisResult(source); await assertNoErrors(source);
1447 verify([source]); 1449 verify([source]);
1448 CompilationUnit unit = resolveCompilationUnit(source, library); 1450 CompilationUnit unit = resolveCompilationUnit(source, library);
1449 // v 1451 // v
1450 DartType stringType = typeProvider.stringType; 1452 DartType stringType = typeProvider.stringType;
1451 FormalParameter vParameter = EngineTestCase.findNode( 1453 FormalParameter vParameter = EngineTestCase.findNode(
1452 unit, code, "v)", (node) => node is SimpleFormalParameter); 1454 unit, code, "v)", (node) => node is SimpleFormalParameter);
1453 expect(vParameter.identifier.propagatedType, same(stringType)); 1455 expect(vParameter.identifier.propagatedType, same(stringType));
1454 expect(vParameter.identifier.staticType, same(typeProvider.objectType)); 1456 expect(vParameter.identifier.staticType, same(typeProvider.objectType));
1455 SimpleIdentifier vIdentifier = EngineTestCase.findNode( 1457 SimpleIdentifier vIdentifier = EngineTestCase.findNode(
1456 unit, code, "v;", (node) => node is SimpleIdentifier); 1458 unit, code, "v;", (node) => node is SimpleIdentifier);
1457 expect(vIdentifier.propagatedType, same(stringType)); 1459 expect(vIdentifier.propagatedType, same(stringType));
1458 } 1460 }
1459 1461
1460 test_Future_then() async { 1462 test_Future_then() async {
1461 String code = r''' 1463 String code = r'''
1462 import 'dart:async'; 1464 import 'dart:async';
1463 main(Future<int> firstFuture) { 1465 main(Future<int> firstFuture) {
1464 firstFuture.then((p1) { 1466 firstFuture.then((p1) {
1465 return 1.0; 1467 return 1.0;
1466 }).then((p2) { 1468 }).then((p2) {
1467 return new Future<String>.value('str'); 1469 return new Future<String>.value('str');
1468 }).then((p3) { 1470 }).then((p3) {
1469 }); 1471 });
1470 }'''; 1472 }''';
1471 Source source = addSource(code); 1473 Source source = addSource(code);
1472 LibraryElement library = resolve2(source); 1474 LibraryElement library = resolve2(source);
1473 await assertNoErrors(source); 1475 await computeAnalysisResult(source); await assertNoErrors(source);
1474 verify([source]); 1476 verify([source]);
1475 CompilationUnit unit = resolveCompilationUnit(source, library); 1477 CompilationUnit unit = resolveCompilationUnit(source, library);
1476 // p1 1478 // p1
1477 FormalParameter p1 = EngineTestCase.findNode( 1479 FormalParameter p1 = EngineTestCase.findNode(
1478 unit, code, "p1) {", (node) => node is SimpleFormalParameter); 1480 unit, code, "p1) {", (node) => node is SimpleFormalParameter);
1479 expect(p1.identifier.propagatedType, same(typeProvider.intType)); 1481 expect(p1.identifier.propagatedType, same(typeProvider.intType));
1480 // p2 1482 // p2
1481 FormalParameter p2 = EngineTestCase.findNode( 1483 FormalParameter p2 = EngineTestCase.findNode(
1482 unit, code, "p2) {", (node) => node is SimpleFormalParameter); 1484 unit, code, "p2) {", (node) => node is SimpleFormalParameter);
1483 expect(p2.identifier.propagatedType, same(typeProvider.doubleType)); 1485 expect(p2.identifier.propagatedType, same(typeProvider.doubleType));
1484 // p3 1486 // p3
1485 FormalParameter p3 = EngineTestCase.findNode( 1487 FormalParameter p3 = EngineTestCase.findNode(
1486 unit, code, "p3) {", (node) => node is SimpleFormalParameter); 1488 unit, code, "p3) {", (node) => node is SimpleFormalParameter);
1487 expect(p3.identifier.propagatedType, same(typeProvider.stringType)); 1489 expect(p3.identifier.propagatedType, same(typeProvider.stringType));
1488 } 1490 }
1489 1491
1490 test_initializer() async { 1492 test_initializer() async {
1491 Source source = addSource(r''' 1493 Source source = addSource(r'''
1492 f() { 1494 f() {
1493 var v = 0; 1495 var v = 0;
1494 return v; 1496 return v;
1495 }'''); 1497 }''');
1496 LibraryElement library = resolve2(source); 1498 LibraryElement library = resolve2(source);
1497 await assertNoErrors(source); 1499 await computeAnalysisResult(source); await assertNoErrors(source);
1498 verify([source]); 1500 verify([source]);
1499 CompilationUnit unit = resolveCompilationUnit(source, library); 1501 CompilationUnit unit = resolveCompilationUnit(source, library);
1500 FunctionDeclaration function = unit.declarations[0] as FunctionDeclaration; 1502 FunctionDeclaration function = unit.declarations[0] as FunctionDeclaration;
1501 BlockFunctionBody body = 1503 BlockFunctionBody body =
1502 function.functionExpression.body as BlockFunctionBody; 1504 function.functionExpression.body as BlockFunctionBody;
1503 NodeList<Statement> statements = body.block.statements; 1505 NodeList<Statement> statements = body.block.statements;
1504 // Type of 'v' in declaration. 1506 // Type of 'v' in declaration.
1505 { 1507 {
1506 VariableDeclarationStatement statement = 1508 VariableDeclarationStatement statement =
1507 statements[0] as VariableDeclarationStatement; 1509 statements[0] as VariableDeclarationStatement;
(...skipping 27 matching lines...) Expand all
1535 expect(variableName.propagatedType, same(typeProvider.stringType)); 1537 expect(variableName.propagatedType, same(typeProvider.stringType));
1536 } 1538 }
1537 1539
1538 test_initializer_hasStaticType() async { 1540 test_initializer_hasStaticType() async {
1539 Source source = addSource(r''' 1541 Source source = addSource(r'''
1540 f() { 1542 f() {
1541 int v = 0; 1543 int v = 0;
1542 return v; 1544 return v;
1543 }'''); 1545 }''');
1544 LibraryElement library = resolve2(source); 1546 LibraryElement library = resolve2(source);
1545 await assertNoErrors(source); 1547 await computeAnalysisResult(source); await assertNoErrors(source);
1546 verify([source]); 1548 verify([source]);
1547 CompilationUnit unit = resolveCompilationUnit(source, library); 1549 CompilationUnit unit = resolveCompilationUnit(source, library);
1548 FunctionDeclaration function = unit.declarations[0] as FunctionDeclaration; 1550 FunctionDeclaration function = unit.declarations[0] as FunctionDeclaration;
1549 BlockFunctionBody body = 1551 BlockFunctionBody body =
1550 function.functionExpression.body as BlockFunctionBody; 1552 function.functionExpression.body as BlockFunctionBody;
1551 NodeList<Statement> statements = body.block.statements; 1553 NodeList<Statement> statements = body.block.statements;
1552 // Type of 'v' in declaration. 1554 // Type of 'v' in declaration.
1553 { 1555 {
1554 VariableDeclarationStatement statement = 1556 VariableDeclarationStatement statement =
1555 statements[0] as VariableDeclarationStatement; 1557 statements[0] as VariableDeclarationStatement;
(...skipping 10 matching lines...) Expand all
1566 } 1568 }
1567 } 1569 }
1568 1570
1569 test_initializer_hasStaticType_parameterized() async { 1571 test_initializer_hasStaticType_parameterized() async {
1570 Source source = addSource(r''' 1572 Source source = addSource(r'''
1571 f() { 1573 f() {
1572 List<int> v = <int>[]; 1574 List<int> v = <int>[];
1573 return v; 1575 return v;
1574 }'''); 1576 }''');
1575 LibraryElement library = resolve2(source); 1577 LibraryElement library = resolve2(source);
1576 await assertNoErrors(source); 1578 await computeAnalysisResult(source); await assertNoErrors(source);
1577 verify([source]); 1579 verify([source]);
1578 CompilationUnit unit = resolveCompilationUnit(source, library); 1580 CompilationUnit unit = resolveCompilationUnit(source, library);
1579 FunctionDeclaration function = unit.declarations[0] as FunctionDeclaration; 1581 FunctionDeclaration function = unit.declarations[0] as FunctionDeclaration;
1580 BlockFunctionBody body = 1582 BlockFunctionBody body =
1581 function.functionExpression.body as BlockFunctionBody; 1583 function.functionExpression.body as BlockFunctionBody;
1582 NodeList<Statement> statements = body.block.statements; 1584 NodeList<Statement> statements = body.block.statements;
1583 // Type of 'v' in declaration. 1585 // Type of 'v' in declaration.
1584 { 1586 {
1585 VariableDeclarationStatement statement = 1587 VariableDeclarationStatement statement =
1586 statements[0] as VariableDeclarationStatement; 1588 statements[0] as VariableDeclarationStatement;
(...skipping 13 matching lines...) Expand all
1600 test_initializer_null() async { 1602 test_initializer_null() async {
1601 String code = r''' 1603 String code = r'''
1602 main() { 1604 main() {
1603 int v = null; 1605 int v = null;
1604 return v; // marker 1606 return v; // marker
1605 }'''; 1607 }''';
1606 CompilationUnit unit; 1608 CompilationUnit unit;
1607 { 1609 {
1608 Source source = addSource(code); 1610 Source source = addSource(code);
1609 LibraryElement library = resolve2(source); 1611 LibraryElement library = resolve2(source);
1610 await assertNoErrors(source); 1612 await computeAnalysisResult(source); await assertNoErrors(source);
1611 verify([source]); 1613 verify([source]);
1612 unit = resolveCompilationUnit(source, library); 1614 unit = resolveCompilationUnit(source, library);
1613 } 1615 }
1614 { 1616 {
1615 SimpleIdentifier identifier = EngineTestCase.findNode( 1617 SimpleIdentifier identifier = EngineTestCase.findNode(
1616 unit, code, "v = null;", (node) => node is SimpleIdentifier); 1618 unit, code, "v = null;", (node) => node is SimpleIdentifier);
1617 expect(identifier.staticType, same(typeProvider.intType)); 1619 expect(identifier.staticType, same(typeProvider.intType));
1618 expect(identifier.propagatedType, same(null)); 1620 expect(identifier.propagatedType, same(null));
1619 } 1621 }
1620 { 1622 {
(...skipping 23 matching lines...) Expand all
1644 expect(methodInvoke.methodName.propagatedElement, isNull); 1646 expect(methodInvoke.methodName.propagatedElement, isNull);
1645 } 1647 }
1646 1648
1647 test_is_conditional() async { 1649 test_is_conditional() async {
1648 Source source = addSource(r''' 1650 Source source = addSource(r'''
1649 class A {} 1651 class A {}
1650 A f(var p) { 1652 A f(var p) {
1651 return (p is A) ? p : null; 1653 return (p is A) ? p : null;
1652 }'''); 1654 }''');
1653 LibraryElement library = resolve2(source); 1655 LibraryElement library = resolve2(source);
1654 await assertNoErrors(source); 1656 await computeAnalysisResult(source); await assertNoErrors(source);
1655 verify([source]); 1657 verify([source]);
1656 CompilationUnit unit = resolveCompilationUnit(source, library); 1658 CompilationUnit unit = resolveCompilationUnit(source, library);
1657 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration; 1659 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration;
1658 InterfaceType typeA = 1660 InterfaceType typeA =
1659 resolutionMap.elementDeclaredByClassDeclaration(classA).type; 1661 resolutionMap.elementDeclaredByClassDeclaration(classA).type;
1660 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration; 1662 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration;
1661 BlockFunctionBody body = 1663 BlockFunctionBody body =
1662 function.functionExpression.body as BlockFunctionBody; 1664 function.functionExpression.body as BlockFunctionBody;
1663 ReturnStatement statement = body.block.statements[0] as ReturnStatement; 1665 ReturnStatement statement = body.block.statements[0] as ReturnStatement;
1664 ConditionalExpression conditional = 1666 ConditionalExpression conditional =
1665 statement.expression as ConditionalExpression; 1667 statement.expression as ConditionalExpression;
1666 SimpleIdentifier variableName = 1668 SimpleIdentifier variableName =
1667 conditional.thenExpression as SimpleIdentifier; 1669 conditional.thenExpression as SimpleIdentifier;
1668 expect(variableName.propagatedType, same(typeA)); 1670 expect(variableName.propagatedType, same(typeA));
1669 } 1671 }
1670 1672
1671 test_is_if() async { 1673 test_is_if() async {
1672 Source source = addSource(r''' 1674 Source source = addSource(r'''
1673 class A {} 1675 class A {}
1674 A f(var p) { 1676 A f(var p) {
1675 if (p is A) { 1677 if (p is A) {
1676 return p; 1678 return p;
1677 } else { 1679 } else {
1678 return null; 1680 return null;
1679 } 1681 }
1680 }'''); 1682 }''');
1681 LibraryElement library = resolve2(source); 1683 LibraryElement library = resolve2(source);
1682 await assertNoErrors(source); 1684 await computeAnalysisResult(source); await assertNoErrors(source);
1683 verify([source]); 1685 verify([source]);
1684 CompilationUnit unit = resolveCompilationUnit(source, library); 1686 CompilationUnit unit = resolveCompilationUnit(source, library);
1685 // prepare A 1687 // prepare A
1686 InterfaceType typeA; 1688 InterfaceType typeA;
1687 { 1689 {
1688 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration; 1690 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration;
1689 typeA = resolutionMap.elementDeclaredByClassDeclaration(classA).type; 1691 typeA = resolutionMap.elementDeclaredByClassDeclaration(classA).type;
1690 } 1692 }
1691 // verify "f" 1693 // verify "f"
1692 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration; 1694 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration;
(...skipping 19 matching lines...) Expand all
1712 Source source = addSource(r''' 1714 Source source = addSource(r'''
1713 class A {} 1715 class A {}
1714 A f(A p) { 1716 A f(A p) {
1715 if (p is String) { 1717 if (p is String) {
1716 return p; 1718 return p;
1717 } else { 1719 } else {
1718 return null; 1720 return null;
1719 } 1721 }
1720 }'''); 1722 }''');
1721 LibraryElement library = resolve2(source); 1723 LibraryElement library = resolve2(source);
1722 await assertNoErrors(source); 1724 await computeAnalysisResult(source); await assertNoErrors(source);
1723 verify([source]); 1725 verify([source]);
1724 CompilationUnit unit = resolveCompilationUnit(source, library); 1726 CompilationUnit unit = resolveCompilationUnit(source, library);
1725 // ClassDeclaration classA = (ClassDeclaration) unit.getDeclarations().get(0) ; 1727 // ClassDeclaration classA = (ClassDeclaration) unit.getDeclarations().get(0) ;
1726 // InterfaceType typeA = classA.getElement().getType(); 1728 // InterfaceType typeA = classA.getElement().getType();
1727 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration; 1729 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration;
1728 BlockFunctionBody body = 1730 BlockFunctionBody body =
1729 function.functionExpression.body as BlockFunctionBody; 1731 function.functionExpression.body as BlockFunctionBody;
1730 IfStatement ifStatement = body.block.statements[0] as IfStatement; 1732 IfStatement ifStatement = body.block.statements[0] as IfStatement;
1731 ReturnStatement statement = 1733 ReturnStatement statement =
1732 (ifStatement.thenStatement as Block).statements[0] as ReturnStatement; 1734 (ifStatement.thenStatement as Block).statements[0] as ReturnStatement;
1733 SimpleIdentifier variableName = statement.expression as SimpleIdentifier; 1735 SimpleIdentifier variableName = statement.expression as SimpleIdentifier;
1734 expect(variableName.propagatedType, same(null)); 1736 expect(variableName.propagatedType, same(null));
1735 } 1737 }
1736 1738
1737 test_is_if_logicalAnd() async { 1739 test_is_if_logicalAnd() async {
1738 Source source = addSource(r''' 1740 Source source = addSource(r'''
1739 class A {} 1741 class A {}
1740 A f(var p) { 1742 A f(var p) {
1741 if (p is A && p != null) { 1743 if (p is A && p != null) {
1742 return p; 1744 return p;
1743 } else { 1745 } else {
1744 return null; 1746 return null;
1745 } 1747 }
1746 }'''); 1748 }''');
1747 LibraryElement library = resolve2(source); 1749 LibraryElement library = resolve2(source);
1748 await assertNoErrors(source); 1750 await computeAnalysisResult(source); await assertNoErrors(source);
1749 verify([source]); 1751 verify([source]);
1750 CompilationUnit unit = resolveCompilationUnit(source, library); 1752 CompilationUnit unit = resolveCompilationUnit(source, library);
1751 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration; 1753 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration;
1752 InterfaceType typeA = 1754 InterfaceType typeA =
1753 resolutionMap.elementDeclaredByClassDeclaration(classA).type; 1755 resolutionMap.elementDeclaredByClassDeclaration(classA).type;
1754 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration; 1756 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration;
1755 BlockFunctionBody body = 1757 BlockFunctionBody body =
1756 function.functionExpression.body as BlockFunctionBody; 1758 function.functionExpression.body as BlockFunctionBody;
1757 IfStatement ifStatement = body.block.statements[0] as IfStatement; 1759 IfStatement ifStatement = body.block.statements[0] as IfStatement;
1758 ReturnStatement statement = 1760 ReturnStatement statement =
1759 (ifStatement.thenStatement as Block).statements[0] as ReturnStatement; 1761 (ifStatement.thenStatement as Block).statements[0] as ReturnStatement;
1760 SimpleIdentifier variableName = statement.expression as SimpleIdentifier; 1762 SimpleIdentifier variableName = statement.expression as SimpleIdentifier;
1761 expect(variableName.propagatedType, same(typeA)); 1763 expect(variableName.propagatedType, same(typeA));
1762 } 1764 }
1763 1765
1764 test_is_postConditional() async { 1766 test_is_postConditional() async {
1765 Source source = addSource(r''' 1767 Source source = addSource(r'''
1766 class A {} 1768 class A {}
1767 A f(var p) { 1769 A f(var p) {
1768 A a = (p is A) ? p : throw null; 1770 A a = (p is A) ? p : throw null;
1769 return p; 1771 return p;
1770 }'''); 1772 }''');
1771 LibraryElement library = resolve2(source); 1773 LibraryElement library = resolve2(source);
1772 await assertNoErrors(source); 1774 await computeAnalysisResult(source); await assertNoErrors(source);
1773 verify([source]); 1775 verify([source]);
1774 CompilationUnit unit = resolveCompilationUnit(source, library); 1776 CompilationUnit unit = resolveCompilationUnit(source, library);
1775 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration; 1777 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration;
1776 InterfaceType typeA = 1778 InterfaceType typeA =
1777 resolutionMap.elementDeclaredByClassDeclaration(classA).type; 1779 resolutionMap.elementDeclaredByClassDeclaration(classA).type;
1778 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration; 1780 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration;
1779 BlockFunctionBody body = 1781 BlockFunctionBody body =
1780 function.functionExpression.body as BlockFunctionBody; 1782 function.functionExpression.body as BlockFunctionBody;
1781 ReturnStatement statement = body.block.statements[1] as ReturnStatement; 1783 ReturnStatement statement = body.block.statements[1] as ReturnStatement;
1782 SimpleIdentifier variableName = statement.expression as SimpleIdentifier; 1784 SimpleIdentifier variableName = statement.expression as SimpleIdentifier;
1783 expect(variableName.propagatedType, same(typeA)); 1785 expect(variableName.propagatedType, same(typeA));
1784 } 1786 }
1785 1787
1786 test_is_postIf() async { 1788 test_is_postIf() async {
1787 Source source = addSource(r''' 1789 Source source = addSource(r'''
1788 class A {} 1790 class A {}
1789 A f(var p) { 1791 A f(var p) {
1790 if (p is A) { 1792 if (p is A) {
1791 A a = p; 1793 A a = p;
1792 } else { 1794 } else {
1793 return null; 1795 return null;
1794 } 1796 }
1795 return p; 1797 return p;
1796 }'''); 1798 }''');
1797 LibraryElement library = resolve2(source); 1799 LibraryElement library = resolve2(source);
1798 await assertNoErrors(source); 1800 await computeAnalysisResult(source); await assertNoErrors(source);
1799 verify([source]); 1801 verify([source]);
1800 CompilationUnit unit = resolveCompilationUnit(source, library); 1802 CompilationUnit unit = resolveCompilationUnit(source, library);
1801 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration; 1803 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration;
1802 InterfaceType typeA = 1804 InterfaceType typeA =
1803 resolutionMap.elementDeclaredByClassDeclaration(classA).type; 1805 resolutionMap.elementDeclaredByClassDeclaration(classA).type;
1804 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration; 1806 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration;
1805 BlockFunctionBody body = 1807 BlockFunctionBody body =
1806 function.functionExpression.body as BlockFunctionBody; 1808 function.functionExpression.body as BlockFunctionBody;
1807 ReturnStatement statement = body.block.statements[1] as ReturnStatement; 1809 ReturnStatement statement = body.block.statements[1] as ReturnStatement;
1808 SimpleIdentifier variableName = statement.expression as SimpleIdentifier; 1810 SimpleIdentifier variableName = statement.expression as SimpleIdentifier;
1809 expect(variableName.propagatedType, same(typeA)); 1811 expect(variableName.propagatedType, same(typeA));
1810 } 1812 }
1811 1813
1812 test_is_subclass() async { 1814 test_is_subclass() async {
1813 Source source = addSource(r''' 1815 Source source = addSource(r'''
1814 class A {} 1816 class A {}
1815 class B extends A { 1817 class B extends A {
1816 B m() => this; 1818 B m() => this;
1817 } 1819 }
1818 A f(A p) { 1820 A f(A p) {
1819 if (p is B) { 1821 if (p is B) {
1820 return p.m(); 1822 return p.m();
1821 } 1823 }
1822 return p; 1824 return p;
1823 }'''); 1825 }''');
1824 LibraryElement library = resolve2(source); 1826 LibraryElement library = resolve2(source);
1825 await assertNoErrors(source); 1827 await computeAnalysisResult(source); await assertNoErrors(source);
1826 CompilationUnit unit = resolveCompilationUnit(source, library); 1828 CompilationUnit unit = resolveCompilationUnit(source, library);
1827 FunctionDeclaration function = unit.declarations[2] as FunctionDeclaration; 1829 FunctionDeclaration function = unit.declarations[2] as FunctionDeclaration;
1828 BlockFunctionBody body = 1830 BlockFunctionBody body =
1829 function.functionExpression.body as BlockFunctionBody; 1831 function.functionExpression.body as BlockFunctionBody;
1830 IfStatement ifStatement = body.block.statements[0] as IfStatement; 1832 IfStatement ifStatement = body.block.statements[0] as IfStatement;
1831 ReturnStatement statement = 1833 ReturnStatement statement =
1832 (ifStatement.thenStatement as Block).statements[0] as ReturnStatement; 1834 (ifStatement.thenStatement as Block).statements[0] as ReturnStatement;
1833 MethodInvocation invocation = statement.expression as MethodInvocation; 1835 MethodInvocation invocation = statement.expression as MethodInvocation;
1834 expect(invocation.methodName.staticElement, isNotNull); 1836 expect(invocation.methodName.staticElement, isNotNull);
1835 expect(invocation.methodName.propagatedElement, isNull); 1837 expect(invocation.methodName.propagatedElement, isNull);
1836 } 1838 }
1837 1839
1838 test_is_while() async { 1840 test_is_while() async {
1839 Source source = addSource(r''' 1841 Source source = addSource(r'''
1840 class A {} 1842 class A {}
1841 A f(var p) { 1843 A f(var p) {
1842 while (p is A) { 1844 while (p is A) {
1843 return p; 1845 return p;
1844 } 1846 }
1845 return p; 1847 return p;
1846 }'''); 1848 }''');
1847 LibraryElement library = resolve2(source); 1849 LibraryElement library = resolve2(source);
1848 await assertNoErrors(source); 1850 await computeAnalysisResult(source); await assertNoErrors(source);
1849 verify([source]); 1851 verify([source]);
1850 CompilationUnit unit = resolveCompilationUnit(source, library); 1852 CompilationUnit unit = resolveCompilationUnit(source, library);
1851 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration; 1853 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration;
1852 InterfaceType typeA = 1854 InterfaceType typeA =
1853 resolutionMap.elementDeclaredByClassDeclaration(classA).type; 1855 resolutionMap.elementDeclaredByClassDeclaration(classA).type;
1854 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration; 1856 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration;
1855 BlockFunctionBody body = 1857 BlockFunctionBody body =
1856 function.functionExpression.body as BlockFunctionBody; 1858 function.functionExpression.body as BlockFunctionBody;
1857 WhileStatement whileStatement = body.block.statements[0] as WhileStatement; 1859 WhileStatement whileStatement = body.block.statements[0] as WhileStatement;
1858 ReturnStatement statement = 1860 ReturnStatement statement =
1859 (whileStatement.body as Block).statements[0] as ReturnStatement; 1861 (whileStatement.body as Block).statements[0] as ReturnStatement;
1860 SimpleIdentifier variableName = statement.expression as SimpleIdentifier; 1862 SimpleIdentifier variableName = statement.expression as SimpleIdentifier;
1861 expect(variableName.propagatedType, same(typeA)); 1863 expect(variableName.propagatedType, same(typeA));
1862 } 1864 }
1863 1865
1864 test_isNot_conditional() async { 1866 test_isNot_conditional() async {
1865 Source source = addSource(r''' 1867 Source source = addSource(r'''
1866 class A {} 1868 class A {}
1867 A f(var p) { 1869 A f(var p) {
1868 return (p is! A) ? null : p; 1870 return (p is! A) ? null : p;
1869 }'''); 1871 }''');
1870 LibraryElement library = resolve2(source); 1872 LibraryElement library = resolve2(source);
1871 await assertNoErrors(source); 1873 await computeAnalysisResult(source); await assertNoErrors(source);
1872 verify([source]); 1874 verify([source]);
1873 CompilationUnit unit = resolveCompilationUnit(source, library); 1875 CompilationUnit unit = resolveCompilationUnit(source, library);
1874 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration; 1876 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration;
1875 InterfaceType typeA = 1877 InterfaceType typeA =
1876 resolutionMap.elementDeclaredByClassDeclaration(classA).type; 1878 resolutionMap.elementDeclaredByClassDeclaration(classA).type;
1877 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration; 1879 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration;
1878 BlockFunctionBody body = 1880 BlockFunctionBody body =
1879 function.functionExpression.body as BlockFunctionBody; 1881 function.functionExpression.body as BlockFunctionBody;
1880 ReturnStatement statement = body.block.statements[0] as ReturnStatement; 1882 ReturnStatement statement = body.block.statements[0] as ReturnStatement;
1881 ConditionalExpression conditional = 1883 ConditionalExpression conditional =
1882 statement.expression as ConditionalExpression; 1884 statement.expression as ConditionalExpression;
1883 SimpleIdentifier variableName = 1885 SimpleIdentifier variableName =
1884 conditional.elseExpression as SimpleIdentifier; 1886 conditional.elseExpression as SimpleIdentifier;
1885 expect(variableName.propagatedType, same(typeA)); 1887 expect(variableName.propagatedType, same(typeA));
1886 } 1888 }
1887 1889
1888 test_isNot_if() async { 1890 test_isNot_if() async {
1889 Source source = addSource(r''' 1891 Source source = addSource(r'''
1890 class A {} 1892 class A {}
1891 A f(var p) { 1893 A f(var p) {
1892 if (p is! A) { 1894 if (p is! A) {
1893 return null; 1895 return null;
1894 } else { 1896 } else {
1895 return p; 1897 return p;
1896 } 1898 }
1897 }'''); 1899 }''');
1898 LibraryElement library = resolve2(source); 1900 LibraryElement library = resolve2(source);
1899 await assertNoErrors(source); 1901 await computeAnalysisResult(source); await assertNoErrors(source);
1900 verify([source]); 1902 verify([source]);
1901 CompilationUnit unit = resolveCompilationUnit(source, library); 1903 CompilationUnit unit = resolveCompilationUnit(source, library);
1902 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration; 1904 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration;
1903 InterfaceType typeA = 1905 InterfaceType typeA =
1904 resolutionMap.elementDeclaredByClassDeclaration(classA).type; 1906 resolutionMap.elementDeclaredByClassDeclaration(classA).type;
1905 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration; 1907 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration;
1906 BlockFunctionBody body = 1908 BlockFunctionBody body =
1907 function.functionExpression.body as BlockFunctionBody; 1909 function.functionExpression.body as BlockFunctionBody;
1908 IfStatement ifStatement = body.block.statements[0] as IfStatement; 1910 IfStatement ifStatement = body.block.statements[0] as IfStatement;
1909 ReturnStatement statement = 1911 ReturnStatement statement =
1910 (ifStatement.elseStatement as Block).statements[0] as ReturnStatement; 1912 (ifStatement.elseStatement as Block).statements[0] as ReturnStatement;
1911 SimpleIdentifier variableName = statement.expression as SimpleIdentifier; 1913 SimpleIdentifier variableName = statement.expression as SimpleIdentifier;
1912 expect(variableName.propagatedType, same(typeA)); 1914 expect(variableName.propagatedType, same(typeA));
1913 } 1915 }
1914 1916
1915 test_isNot_if_logicalOr() async { 1917 test_isNot_if_logicalOr() async {
1916 Source source = addSource(r''' 1918 Source source = addSource(r'''
1917 class A {} 1919 class A {}
1918 A f(var p) { 1920 A f(var p) {
1919 if (p is! A || null == p) { 1921 if (p is! A || null == p) {
1920 return null; 1922 return null;
1921 } else { 1923 } else {
1922 return p; 1924 return p;
1923 } 1925 }
1924 }'''); 1926 }''');
1925 LibraryElement library = resolve2(source); 1927 LibraryElement library = resolve2(source);
1926 await assertNoErrors(source); 1928 await computeAnalysisResult(source); await assertNoErrors(source);
1927 CompilationUnit unit = resolveCompilationUnit(source, library); 1929 CompilationUnit unit = resolveCompilationUnit(source, library);
1928 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration; 1930 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration;
1929 InterfaceType typeA = 1931 InterfaceType typeA =
1930 resolutionMap.elementDeclaredByClassDeclaration(classA).type; 1932 resolutionMap.elementDeclaredByClassDeclaration(classA).type;
1931 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration; 1933 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration;
1932 BlockFunctionBody body = 1934 BlockFunctionBody body =
1933 function.functionExpression.body as BlockFunctionBody; 1935 function.functionExpression.body as BlockFunctionBody;
1934 IfStatement ifStatement = body.block.statements[0] as IfStatement; 1936 IfStatement ifStatement = body.block.statements[0] as IfStatement;
1935 ReturnStatement statement = 1937 ReturnStatement statement =
1936 (ifStatement.elseStatement as Block).statements[0] as ReturnStatement; 1938 (ifStatement.elseStatement as Block).statements[0] as ReturnStatement;
1937 SimpleIdentifier variableName = statement.expression as SimpleIdentifier; 1939 SimpleIdentifier variableName = statement.expression as SimpleIdentifier;
1938 expect(variableName.propagatedType, same(typeA)); 1940 expect(variableName.propagatedType, same(typeA));
1939 } 1941 }
1940 1942
1941 test_isNot_postConditional() async { 1943 test_isNot_postConditional() async {
1942 Source source = addSource(r''' 1944 Source source = addSource(r'''
1943 class A {} 1945 class A {}
1944 A f(var p) { 1946 A f(var p) {
1945 A a = (p is! A) ? throw null : p; 1947 A a = (p is! A) ? throw null : p;
1946 return p; 1948 return p;
1947 }'''); 1949 }''');
1948 LibraryElement library = resolve2(source); 1950 LibraryElement library = resolve2(source);
1949 await assertNoErrors(source); 1951 await computeAnalysisResult(source); await assertNoErrors(source);
1950 verify([source]); 1952 verify([source]);
1951 CompilationUnit unit = resolveCompilationUnit(source, library); 1953 CompilationUnit unit = resolveCompilationUnit(source, library);
1952 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration; 1954 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration;
1953 InterfaceType typeA = 1955 InterfaceType typeA =
1954 resolutionMap.elementDeclaredByClassDeclaration(classA).type; 1956 resolutionMap.elementDeclaredByClassDeclaration(classA).type;
1955 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration; 1957 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration;
1956 BlockFunctionBody body = 1958 BlockFunctionBody body =
1957 function.functionExpression.body as BlockFunctionBody; 1959 function.functionExpression.body as BlockFunctionBody;
1958 ReturnStatement statement = body.block.statements[1] as ReturnStatement; 1960 ReturnStatement statement = body.block.statements[1] as ReturnStatement;
1959 SimpleIdentifier variableName = statement.expression as SimpleIdentifier; 1961 SimpleIdentifier variableName = statement.expression as SimpleIdentifier;
1960 expect(variableName.propagatedType, same(typeA)); 1962 expect(variableName.propagatedType, same(typeA));
1961 } 1963 }
1962 1964
1963 test_isNot_postIf() async { 1965 test_isNot_postIf() async {
1964 Source source = addSource(r''' 1966 Source source = addSource(r'''
1965 class A {} 1967 class A {}
1966 A f(var p) { 1968 A f(var p) {
1967 if (p is! A) { 1969 if (p is! A) {
1968 return null; 1970 return null;
1969 } 1971 }
1970 return p; 1972 return p;
1971 }'''); 1973 }''');
1972 LibraryElement library = resolve2(source); 1974 LibraryElement library = resolve2(source);
1973 await assertNoErrors(source); 1975 await computeAnalysisResult(source); await assertNoErrors(source);
1974 verify([source]); 1976 verify([source]);
1975 CompilationUnit unit = resolveCompilationUnit(source, library); 1977 CompilationUnit unit = resolveCompilationUnit(source, library);
1976 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration; 1978 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration;
1977 InterfaceType typeA = 1979 InterfaceType typeA =
1978 resolutionMap.elementDeclaredByClassDeclaration(classA).type; 1980 resolutionMap.elementDeclaredByClassDeclaration(classA).type;
1979 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration; 1981 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration;
1980 BlockFunctionBody body = 1982 BlockFunctionBody body =
1981 function.functionExpression.body as BlockFunctionBody; 1983 function.functionExpression.body as BlockFunctionBody;
1982 ReturnStatement statement = body.block.statements[1] as ReturnStatement; 1984 ReturnStatement statement = body.block.statements[1] as ReturnStatement;
1983 SimpleIdentifier variableName = statement.expression as SimpleIdentifier; 1985 SimpleIdentifier variableName = statement.expression as SimpleIdentifier;
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
2038 await assertTypeOfMarkedExpression(code, null, tB); 2040 await assertTypeOfMarkedExpression(code, null, tB);
2039 } 2041 }
2040 2042
2041 test_listLiteral_different() async { 2043 test_listLiteral_different() async {
2042 Source source = addSource(r''' 2044 Source source = addSource(r'''
2043 f() { 2045 f() {
2044 var v = [0, '1', 2]; 2046 var v = [0, '1', 2];
2045 return v[2]; 2047 return v[2];
2046 }'''); 2048 }''');
2047 LibraryElement library = resolve2(source); 2049 LibraryElement library = resolve2(source);
2048 await assertNoErrors(source); 2050 await computeAnalysisResult(source); await assertNoErrors(source);
2049 verify([source]); 2051 verify([source]);
2050 CompilationUnit unit = resolveCompilationUnit(source, library); 2052 CompilationUnit unit = resolveCompilationUnit(source, library);
2051 FunctionDeclaration function = unit.declarations[0] as FunctionDeclaration; 2053 FunctionDeclaration function = unit.declarations[0] as FunctionDeclaration;
2052 BlockFunctionBody body = 2054 BlockFunctionBody body =
2053 function.functionExpression.body as BlockFunctionBody; 2055 function.functionExpression.body as BlockFunctionBody;
2054 ReturnStatement statement = body.block.statements[1] as ReturnStatement; 2056 ReturnStatement statement = body.block.statements[1] as ReturnStatement;
2055 IndexExpression indexExpression = statement.expression as IndexExpression; 2057 IndexExpression indexExpression = statement.expression as IndexExpression;
2056 expect(indexExpression.propagatedType, isNull); 2058 expect(indexExpression.propagatedType, isNull);
2057 } 2059 }
2058 2060
2059 test_listLiteral_same() async { 2061 test_listLiteral_same() async {
2060 Source source = addSource(r''' 2062 Source source = addSource(r'''
2061 f() { 2063 f() {
2062 var v = [0, 1, 2]; 2064 var v = [0, 1, 2];
2063 return v[2]; 2065 return v[2];
2064 }'''); 2066 }''');
2065 LibraryElement library = resolve2(source); 2067 LibraryElement library = resolve2(source);
2066 await assertNoErrors(source); 2068 await computeAnalysisResult(source); await assertNoErrors(source);
2067 verify([source]); 2069 verify([source]);
2068 CompilationUnit unit = resolveCompilationUnit(source, library); 2070 CompilationUnit unit = resolveCompilationUnit(source, library);
2069 FunctionDeclaration function = unit.declarations[0] as FunctionDeclaration; 2071 FunctionDeclaration function = unit.declarations[0] as FunctionDeclaration;
2070 BlockFunctionBody body = 2072 BlockFunctionBody body =
2071 function.functionExpression.body as BlockFunctionBody; 2073 function.functionExpression.body as BlockFunctionBody;
2072 ReturnStatement statement = body.block.statements[1] as ReturnStatement; 2074 ReturnStatement statement = body.block.statements[1] as ReturnStatement;
2073 IndexExpression indexExpression = statement.expression as IndexExpression; 2075 IndexExpression indexExpression = statement.expression as IndexExpression;
2074 expect(indexExpression.propagatedType, isNull); 2076 expect(indexExpression.propagatedType, isNull);
2075 Expression v = indexExpression.target; 2077 Expression v = indexExpression.target;
2076 InterfaceType propagatedType = v.propagatedType as InterfaceType; 2078 InterfaceType propagatedType = v.propagatedType as InterfaceType;
2077 expect(propagatedType.element, same(typeProvider.listType.element)); 2079 expect(propagatedType.element, same(typeProvider.listType.element));
2078 List<DartType> typeArguments = propagatedType.typeArguments; 2080 List<DartType> typeArguments = propagatedType.typeArguments;
2079 expect(typeArguments, hasLength(1)); 2081 expect(typeArguments, hasLength(1));
2080 expect(typeArguments[0], same(typeProvider.dynamicType)); 2082 expect(typeArguments[0], same(typeProvider.dynamicType));
2081 } 2083 }
2082 2084
2083 test_mapLiteral_different() async { 2085 test_mapLiteral_different() async {
2084 Source source = addSource(r''' 2086 Source source = addSource(r'''
2085 f() { 2087 f() {
2086 var v = {'0' : 0, 1 : '1', '2' : 2}; 2088 var v = {'0' : 0, 1 : '1', '2' : 2};
2087 return v; 2089 return v;
2088 }'''); 2090 }''');
2089 LibraryElement library = resolve2(source); 2091 LibraryElement library = resolve2(source);
2090 await assertNoErrors(source); 2092 await computeAnalysisResult(source); await assertNoErrors(source);
2091 verify([source]); 2093 verify([source]);
2092 CompilationUnit unit = resolveCompilationUnit(source, library); 2094 CompilationUnit unit = resolveCompilationUnit(source, library);
2093 FunctionDeclaration function = unit.declarations[0] as FunctionDeclaration; 2095 FunctionDeclaration function = unit.declarations[0] as FunctionDeclaration;
2094 BlockFunctionBody body = 2096 BlockFunctionBody body =
2095 function.functionExpression.body as BlockFunctionBody; 2097 function.functionExpression.body as BlockFunctionBody;
2096 ReturnStatement statement = body.block.statements[1] as ReturnStatement; 2098 ReturnStatement statement = body.block.statements[1] as ReturnStatement;
2097 SimpleIdentifier identifier = statement.expression as SimpleIdentifier; 2099 SimpleIdentifier identifier = statement.expression as SimpleIdentifier;
2098 InterfaceType propagatedType = identifier.propagatedType as InterfaceType; 2100 InterfaceType propagatedType = identifier.propagatedType as InterfaceType;
2099 expect(propagatedType.element, same(typeProvider.mapType.element)); 2101 expect(propagatedType.element, same(typeProvider.mapType.element));
2100 List<DartType> typeArguments = propagatedType.typeArguments; 2102 List<DartType> typeArguments = propagatedType.typeArguments;
2101 expect(typeArguments, hasLength(2)); 2103 expect(typeArguments, hasLength(2));
2102 expect(typeArguments[0], same(typeProvider.dynamicType)); 2104 expect(typeArguments[0], same(typeProvider.dynamicType));
2103 expect(typeArguments[1], same(typeProvider.dynamicType)); 2105 expect(typeArguments[1], same(typeProvider.dynamicType));
2104 } 2106 }
2105 2107
2106 test_mapLiteral_same() async { 2108 test_mapLiteral_same() async {
2107 Source source = addSource(r''' 2109 Source source = addSource(r'''
2108 f() { 2110 f() {
2109 var v = {'a' : 0, 'b' : 1, 'c' : 2}; 2111 var v = {'a' : 0, 'b' : 1, 'c' : 2};
2110 return v; 2112 return v;
2111 }'''); 2113 }''');
2112 LibraryElement library = resolve2(source); 2114 LibraryElement library = resolve2(source);
2113 await assertNoErrors(source); 2115 await computeAnalysisResult(source); await assertNoErrors(source);
2114 verify([source]); 2116 verify([source]);
2115 CompilationUnit unit = resolveCompilationUnit(source, library); 2117 CompilationUnit unit = resolveCompilationUnit(source, library);
2116 FunctionDeclaration function = unit.declarations[0] as FunctionDeclaration; 2118 FunctionDeclaration function = unit.declarations[0] as FunctionDeclaration;
2117 BlockFunctionBody body = 2119 BlockFunctionBody body =
2118 function.functionExpression.body as BlockFunctionBody; 2120 function.functionExpression.body as BlockFunctionBody;
2119 ReturnStatement statement = body.block.statements[1] as ReturnStatement; 2121 ReturnStatement statement = body.block.statements[1] as ReturnStatement;
2120 SimpleIdentifier identifier = statement.expression as SimpleIdentifier; 2122 SimpleIdentifier identifier = statement.expression as SimpleIdentifier;
2121 InterfaceType propagatedType = identifier.propagatedType as InterfaceType; 2123 InterfaceType propagatedType = identifier.propagatedType as InterfaceType;
2122 expect(propagatedType.element, same(typeProvider.mapType.element)); 2124 expect(propagatedType.element, same(typeProvider.mapType.element));
2123 List<DartType> typeArguments = propagatedType.typeArguments; 2125 List<DartType> typeArguments = propagatedType.typeArguments;
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
2229 } 2231 }
2230 } 2232 }
2231 2233
2232 void g() { 2234 void g() {
2233 Base x = null; 2235 Base x = null;
2234 if (x is Derived) { 2236 if (x is Derived) {
2235 print(x.y); // GOOD 2237 print(x.y); // GOOD
2236 } 2238 }
2237 x = null; 2239 x = null;
2238 }'''); 2240 }''');
2239 await assertNoErrors(source); 2241 await computeAnalysisResult(source); await assertNoErrors(source);
2240 } 2242 }
2241 2243
2242 test_objectAccessInference_disabled_for_library_prefix() async { 2244 test_objectAccessInference_disabled_for_library_prefix() async {
2243 String name = 'hashCode'; 2245 String name = 'hashCode';
2244 addNamedSource( 2246 addNamedSource(
2245 '/helper.dart', 2247 '/helper.dart',
2246 ''' 2248 '''
2247 library helper; 2249 library helper;
2248 dynamic get $name => 42; 2250 dynamic get $name => 42;
2249 '''); 2251 ''');
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
2413 var v7 = query('select#id'); 2415 var v7 = query('select#id');
2414 // invocation of method 2416 // invocation of method
2415 var m1 = document.query('div'); 2417 var m1 = document.query('div');
2416 // unsupported currently 2418 // unsupported currently
2417 var b1 = query('noSuchTag'); 2419 var b1 = query('noSuchTag');
2418 var b2 = query('DART_EDITOR_NO_SUCH_TYPE'); 2420 var b2 = query('DART_EDITOR_NO_SUCH_TYPE');
2419 var b3 = query('body div'); 2421 var b3 = query('body div');
2420 return [v1, v2, v3, v4, v5, v6, v7, m1, b1, b2, b3]; 2422 return [v1, v2, v3, v4, v5, v6, v7, m1, b1, b2, b3];
2421 }'''); 2423 }''');
2422 LibraryElement library = resolve2(source); 2424 LibraryElement library = resolve2(source);
2423 await assertNoErrors(source); 2425 await computeAnalysisResult(source); await assertNoErrors(source);
2424 verify([source]); 2426 verify([source]);
2425 CompilationUnit unit = resolveCompilationUnit(source, library); 2427 CompilationUnit unit = resolveCompilationUnit(source, library);
2426 FunctionDeclaration main = unit.declarations[0] as FunctionDeclaration; 2428 FunctionDeclaration main = unit.declarations[0] as FunctionDeclaration;
2427 BlockFunctionBody body = main.functionExpression.body as BlockFunctionBody; 2429 BlockFunctionBody body = main.functionExpression.body as BlockFunctionBody;
2428 ReturnStatement statement = body.block.statements[11] as ReturnStatement; 2430 ReturnStatement statement = body.block.statements[11] as ReturnStatement;
2429 NodeList<Expression> elements = 2431 NodeList<Expression> elements =
2430 (statement.expression as ListLiteral).elements; 2432 (statement.expression as ListLiteral).elements;
2431 expect(resolutionMap.propagatedTypeForExpression(elements[0]).name, 2433 expect(resolutionMap.propagatedTypeForExpression(elements[0]).name,
2432 "AnchorElement"); 2434 "AnchorElement");
2433 expect(resolutionMap.propagatedTypeForExpression(elements[1]).name, 2435 expect(resolutionMap.propagatedTypeForExpression(elements[1]).name,
(...skipping 1223 matching lines...) Expand 10 before | Expand all | Expand 10 after
3657 */ 3659 */
3658 class _StaleElement extends ElementImpl { 3660 class _StaleElement extends ElementImpl {
3659 _StaleElement() : super("_StaleElement", -1); 3661 _StaleElement() : super("_StaleElement", -1);
3660 3662
3661 @override 3663 @override
3662 get kind => throw "_StaleElement's kind shouldn't be accessed"; 3664 get kind => throw "_StaleElement's kind shouldn't be accessed";
3663 3665
3664 @override 3666 @override
3665 /*=T*/ accept/*<T>*/(_) => throw "_StaleElement shouldn't be visited"; 3667 /*=T*/ accept/*<T>*/(_) => throw "_StaleElement shouldn't be visited";
3666 } 3668 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698