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

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: Rollback await(ing) of assertErrors(). Format. 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 assertErrors( 175 await computeAnalysisResult(source);
176 source, [ResolverErrorCode.BREAK_LABEL_ON_SWITCH_MEMBER]); 176 assertErrors(source, [ResolverErrorCode.BREAK_LABEL_ON_SWITCH_MEMBER]);
177 verify([source]); 177 verify([source]);
178 } 178 }
179 179
180 test_continueLabelOnSwitch() async { 180 test_continueLabelOnSwitch() async {
181 Source source = addSource(r''' 181 Source source = addSource(r'''
182 class A { 182 class A {
183 void m(int i) { 183 void m(int i) {
184 l: switch (i) { 184 l: switch (i) {
185 case 0: 185 case 0:
186 continue l; 186 continue l;
187 } 187 }
188 } 188 }
189 }'''); 189 }''');
190 await assertErrors(source, [ResolverErrorCode.CONTINUE_LABEL_ON_SWITCH]); 190 await computeAnalysisResult(source);
191 assertErrors(source, [ResolverErrorCode.CONTINUE_LABEL_ON_SWITCH]);
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);
221 assertErrors(source, [ParserErrorCode.GETTER_IN_FUNCTION]);
220 } 222 }
221 } 223 }
222 224
223 /** 225 /**
224 * Tests for generic method and function resolution that do not use strong mode. 226 * Tests for generic method and function resolution that do not use strong mode.
225 */ 227 */
226 @reflectiveTest 228 @reflectiveTest
227 class GenericMethodResolverTest extends StaticTypeAnalyzer2TestShared { 229 class GenericMethodResolverTest extends StaticTypeAnalyzer2TestShared {
228 test_genericMethod_propagatedType_promotion() async { 230 test_genericMethod_propagatedType_promotion() async {
229 // Regression test for: 231 // Regression test for:
(...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after
615 @reflectiveTest 617 @reflectiveTest
616 class StrictModeTest extends ResolverTestCase { 618 class StrictModeTest extends ResolverTestCase {
617 fail_for() async { 619 fail_for() async {
618 Source source = addSource(r''' 620 Source source = addSource(r'''
619 int f(List<int> list) { 621 int f(List<int> list) {
620 num sum = 0; 622 num sum = 0;
621 for (num i = 0; i < list.length; i++) { 623 for (num i = 0; i < list.length; i++) {
622 sum += list[i]; 624 sum += list[i];
623 } 625 }
624 }'''); 626 }''');
625 await assertErrors(source, [StaticTypeWarningCode.UNDEFINED_OPERATOR]); 627 await computeAnalysisResult(source);
628 assertErrors(source, [StaticTypeWarningCode.UNDEFINED_OPERATOR]);
626 } 629 }
627 630
628 @override 631 @override
629 void setUp() { 632 void setUp() {
630 AnalysisOptionsImpl options = new AnalysisOptionsImpl(); 633 AnalysisOptionsImpl options = new AnalysisOptionsImpl();
631 options.hint = false; 634 options.hint = false;
632 resetWithOptions(options); 635 resetWithOptions(options);
633 } 636 }
634 637
635 test_assert_is() async { 638 test_assert_is() async {
636 Source source = addSource(r''' 639 Source source = addSource(r'''
637 int f(num n) { 640 int f(num n) {
638 assert (n is int); 641 assert (n is int);
639 return n & 0x0F; 642 return n & 0x0F;
640 }'''); 643 }''');
641 await assertErrors(source, [StaticTypeWarningCode.UNDEFINED_OPERATOR]); 644 await computeAnalysisResult(source);
645 assertErrors(source, [StaticTypeWarningCode.UNDEFINED_OPERATOR]);
642 } 646 }
643 647
644 test_conditional_and_is() async { 648 test_conditional_and_is() async {
645 Source source = addSource(r''' 649 Source source = addSource(r'''
646 int f(num n) { 650 int f(num n) {
647 return (n is int && n > 0) ? n & 0x0F : 0; 651 return (n is int && n > 0) ? n & 0x0F : 0;
648 }'''); 652 }''');
649 await assertNoErrors(source); 653 await computeAnalysisResult(source);
654 assertNoErrors(source);
650 } 655 }
651 656
652 test_conditional_is() async { 657 test_conditional_is() async {
653 Source source = addSource(r''' 658 Source source = addSource(r'''
654 int f(num n) { 659 int f(num n) {
655 return (n is int) ? n & 0x0F : 0; 660 return (n is int) ? n & 0x0F : 0;
656 }'''); 661 }''');
657 await assertNoErrors(source); 662 await computeAnalysisResult(source);
663 assertNoErrors(source);
658 } 664 }
659 665
660 test_conditional_isNot() async { 666 test_conditional_isNot() async {
661 Source source = addSource(r''' 667 Source source = addSource(r'''
662 int f(num n) { 668 int f(num n) {
663 return (n is! int) ? 0 : n & 0x0F; 669 return (n is! int) ? 0 : n & 0x0F;
664 }'''); 670 }''');
665 await assertErrors(source, [StaticTypeWarningCode.UNDEFINED_OPERATOR]); 671 await computeAnalysisResult(source);
672 assertErrors(source, [StaticTypeWarningCode.UNDEFINED_OPERATOR]);
666 } 673 }
667 674
668 test_conditional_or_is() async { 675 test_conditional_or_is() async {
669 Source source = addSource(r''' 676 Source source = addSource(r'''
670 int f(num n) { 677 int f(num n) {
671 return (n is! int || n < 0) ? 0 : n & 0x0F; 678 return (n is! int || n < 0) ? 0 : n & 0x0F;
672 }'''); 679 }''');
673 await assertErrors(source, [StaticTypeWarningCode.UNDEFINED_OPERATOR]); 680 await computeAnalysisResult(source);
681 assertErrors(source, [StaticTypeWarningCode.UNDEFINED_OPERATOR]);
674 } 682 }
675 683
676 test_forEach() async { 684 test_forEach() async {
677 Source source = addSource(r''' 685 Source source = addSource(r'''
678 int f(List<int> list) { 686 int f(List<int> list) {
679 num sum = 0; 687 num sum = 0;
680 for (num n in list) { 688 for (num n in list) {
681 sum += n & 0x0F; 689 sum += n & 0x0F;
682 } 690 }
683 }'''); 691 }''');
684 await assertErrors(source, [StaticTypeWarningCode.UNDEFINED_OPERATOR]); 692 await computeAnalysisResult(source);
693 assertErrors(source, [StaticTypeWarningCode.UNDEFINED_OPERATOR]);
685 } 694 }
686 695
687 test_if_and_is() async { 696 test_if_and_is() async {
688 Source source = addSource(r''' 697 Source source = addSource(r'''
689 int f(num n) { 698 int f(num n) {
690 if (n is int && n > 0) { 699 if (n is int && n > 0) {
691 return n & 0x0F; 700 return n & 0x0F;
692 } 701 }
693 return 0; 702 return 0;
694 }'''); 703 }''');
695 await assertNoErrors(source); 704 await computeAnalysisResult(source);
705 assertNoErrors(source);
696 } 706 }
697 707
698 test_if_is() async { 708 test_if_is() async {
699 Source source = addSource(r''' 709 Source source = addSource(r'''
700 int f(num n) { 710 int f(num n) {
701 if (n is int) { 711 if (n is int) {
702 return n & 0x0F; 712 return n & 0x0F;
703 } 713 }
704 return 0; 714 return 0;
705 }'''); 715 }''');
706 await assertNoErrors(source); 716 await computeAnalysisResult(source);
717 assertNoErrors(source);
707 } 718 }
708 719
709 test_if_isNot() async { 720 test_if_isNot() async {
710 Source source = addSource(r''' 721 Source source = addSource(r'''
711 int f(num n) { 722 int f(num n) {
712 if (n is! int) { 723 if (n is! int) {
713 return 0; 724 return 0;
714 } else { 725 } else {
715 return n & 0x0F; 726 return n & 0x0F;
716 } 727 }
717 }'''); 728 }''');
718 await assertErrors(source, [StaticTypeWarningCode.UNDEFINED_OPERATOR]); 729 await computeAnalysisResult(source);
730 assertErrors(source, [StaticTypeWarningCode.UNDEFINED_OPERATOR]);
719 } 731 }
720 732
721 test_if_isNot_abrupt() async { 733 test_if_isNot_abrupt() async {
722 Source source = addSource(r''' 734 Source source = addSource(r'''
723 int f(num n) { 735 int f(num n) {
724 if (n is! int) { 736 if (n is! int) {
725 return 0; 737 return 0;
726 } 738 }
727 return n & 0x0F; 739 return n & 0x0F;
728 }'''); 740 }''');
729 await assertErrors(source, [StaticTypeWarningCode.UNDEFINED_OPERATOR]); 741 await computeAnalysisResult(source);
742 assertErrors(source, [StaticTypeWarningCode.UNDEFINED_OPERATOR]);
730 } 743 }
731 744
732 test_if_or_is() async { 745 test_if_or_is() async {
733 Source source = addSource(r''' 746 Source source = addSource(r'''
734 int f(num n) { 747 int f(num n) {
735 if (n is! int || n < 0) { 748 if (n is! int || n < 0) {
736 return 0; 749 return 0;
737 } else { 750 } else {
738 return n & 0x0F; 751 return n & 0x0F;
739 } 752 }
740 }'''); 753 }''');
741 await assertErrors(source, [StaticTypeWarningCode.UNDEFINED_OPERATOR]); 754 await computeAnalysisResult(source);
755 assertErrors(source, [StaticTypeWarningCode.UNDEFINED_OPERATOR]);
742 } 756 }
743 757
744 test_localVar() async { 758 test_localVar() async {
745 Source source = addSource(r''' 759 Source source = addSource(r'''
746 int f() { 760 int f() {
747 num n = 1234; 761 num n = 1234;
748 return n & 0x0F; 762 return n & 0x0F;
749 }'''); 763 }''');
750 await assertErrors(source, [StaticTypeWarningCode.UNDEFINED_OPERATOR]); 764 await computeAnalysisResult(source);
765 assertErrors(source, [StaticTypeWarningCode.UNDEFINED_OPERATOR]);
751 } 766 }
752 } 767 }
753 768
754 @reflectiveTest 769 @reflectiveTest
755 class SubtypeManagerTest { 770 class SubtypeManagerTest {
756 /** 771 /**
757 * The inheritance manager being tested. 772 * The inheritance manager being tested.
758 */ 773 */
759 SubtypeManager _subtypeManager; 774 SubtypeManager _subtypeManager;
760 775
(...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after
1070 bool get g => true; 1085 bool get g => true;
1071 } 1086 }
1072 A f(var p) { 1087 A f(var p) {
1073 if ((p as A).g) { 1088 if ((p as A).g) {
1074 return p; 1089 return p;
1075 } else { 1090 } else {
1076 return null; 1091 return null;
1077 } 1092 }
1078 }'''); 1093 }''');
1079 LibraryElement library = resolve2(source); 1094 LibraryElement library = resolve2(source);
1080 await assertNoErrors(source); 1095 await computeAnalysisResult(source);
1096 assertNoErrors(source);
1081 verify([source]); 1097 verify([source]);
1082 CompilationUnit unit = resolveCompilationUnit(source, library); 1098 CompilationUnit unit = resolveCompilationUnit(source, library);
1083 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration; 1099 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration;
1084 InterfaceType typeA = 1100 InterfaceType typeA =
1085 resolutionMap.elementDeclaredByClassDeclaration(classA).type; 1101 resolutionMap.elementDeclaredByClassDeclaration(classA).type;
1086 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration; 1102 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration;
1087 BlockFunctionBody body = 1103 BlockFunctionBody body =
1088 function.functionExpression.body as BlockFunctionBody; 1104 function.functionExpression.body as BlockFunctionBody;
1089 IfStatement ifStatement = body.block.statements[0] as IfStatement; 1105 IfStatement ifStatement = body.block.statements[0] as IfStatement;
1090 ReturnStatement statement = 1106 ReturnStatement statement =
1091 (ifStatement.thenStatement as Block).statements[0] as ReturnStatement; 1107 (ifStatement.thenStatement as Block).statements[0] as ReturnStatement;
1092 SimpleIdentifier variableName = statement.expression as SimpleIdentifier; 1108 SimpleIdentifier variableName = statement.expression as SimpleIdentifier;
1093 expect(variableName.propagatedType, same(typeA)); 1109 expect(variableName.propagatedType, same(typeA));
1094 } 1110 }
1095 1111
1096 test_assert() async { 1112 test_assert() async {
1097 Source source = addSource(r''' 1113 Source source = addSource(r'''
1098 class A {} 1114 class A {}
1099 A f(var p) { 1115 A f(var p) {
1100 assert (p is A); 1116 assert (p is A);
1101 return p; 1117 return p;
1102 }'''); 1118 }''');
1103 LibraryElement library = resolve2(source); 1119 LibraryElement library = resolve2(source);
1104 await assertNoErrors(source); 1120 await computeAnalysisResult(source);
1121 assertNoErrors(source);
1105 verify([source]); 1122 verify([source]);
1106 CompilationUnit unit = resolveCompilationUnit(source, library); 1123 CompilationUnit unit = resolveCompilationUnit(source, library);
1107 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration; 1124 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration;
1108 InterfaceType typeA = 1125 InterfaceType typeA =
1109 resolutionMap.elementDeclaredByClassDeclaration(classA).type; 1126 resolutionMap.elementDeclaredByClassDeclaration(classA).type;
1110 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration; 1127 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration;
1111 BlockFunctionBody body = 1128 BlockFunctionBody body =
1112 function.functionExpression.body as BlockFunctionBody; 1129 function.functionExpression.body as BlockFunctionBody;
1113 ReturnStatement statement = body.block.statements[1] as ReturnStatement; 1130 ReturnStatement statement = body.block.statements[1] as ReturnStatement;
1114 SimpleIdentifier variableName = statement.expression as SimpleIdentifier; 1131 SimpleIdentifier variableName = statement.expression as SimpleIdentifier;
1115 expect(variableName.propagatedType, same(typeA)); 1132 expect(variableName.propagatedType, same(typeA));
1116 } 1133 }
1117 1134
1118 test_assignment() async { 1135 test_assignment() async {
1119 Source source = addSource(r''' 1136 Source source = addSource(r'''
1120 f() { 1137 f() {
1121 var v; 1138 var v;
1122 v = 0; 1139 v = 0;
1123 return v; 1140 return v;
1124 }'''); 1141 }''');
1125 LibraryElement library = resolve2(source); 1142 LibraryElement library = resolve2(source);
1126 await assertNoErrors(source); 1143 await computeAnalysisResult(source);
1144 assertNoErrors(source);
1127 verify([source]); 1145 verify([source]);
1128 CompilationUnit unit = resolveCompilationUnit(source, library); 1146 CompilationUnit unit = resolveCompilationUnit(source, library);
1129 FunctionDeclaration function = unit.declarations[0] as FunctionDeclaration; 1147 FunctionDeclaration function = unit.declarations[0] as FunctionDeclaration;
1130 BlockFunctionBody body = 1148 BlockFunctionBody body =
1131 function.functionExpression.body as BlockFunctionBody; 1149 function.functionExpression.body as BlockFunctionBody;
1132 ReturnStatement statement = body.block.statements[2] as ReturnStatement; 1150 ReturnStatement statement = body.block.statements[2] as ReturnStatement;
1133 SimpleIdentifier variableName = statement.expression as SimpleIdentifier; 1151 SimpleIdentifier variableName = statement.expression as SimpleIdentifier;
1134 expect(variableName.propagatedType, same(typeProvider.intType)); 1152 expect(variableName.propagatedType, same(typeProvider.intType));
1135 } 1153 }
1136 1154
1137 test_assignment_afterInitializer() async { 1155 test_assignment_afterInitializer() async {
1138 Source source = addSource(r''' 1156 Source source = addSource(r'''
1139 f() { 1157 f() {
1140 var v = 0; 1158 var v = 0;
1141 v = 1.0; 1159 v = 1.0;
1142 return v; 1160 return v;
1143 }'''); 1161 }''');
1144 LibraryElement library = resolve2(source); 1162 LibraryElement library = resolve2(source);
1145 await assertNoErrors(source); 1163 await computeAnalysisResult(source);
1164 assertNoErrors(source);
1146 verify([source]); 1165 verify([source]);
1147 CompilationUnit unit = resolveCompilationUnit(source, library); 1166 CompilationUnit unit = resolveCompilationUnit(source, library);
1148 FunctionDeclaration function = unit.declarations[0] as FunctionDeclaration; 1167 FunctionDeclaration function = unit.declarations[0] as FunctionDeclaration;
1149 BlockFunctionBody body = 1168 BlockFunctionBody body =
1150 function.functionExpression.body as BlockFunctionBody; 1169 function.functionExpression.body as BlockFunctionBody;
1151 ReturnStatement statement = body.block.statements[2] as ReturnStatement; 1170 ReturnStatement statement = body.block.statements[2] as ReturnStatement;
1152 SimpleIdentifier variableName = statement.expression as SimpleIdentifier; 1171 SimpleIdentifier variableName = statement.expression as SimpleIdentifier;
1153 expect(variableName.propagatedType, same(typeProvider.doubleType)); 1172 expect(variableName.propagatedType, same(typeProvider.doubleType));
1154 } 1173 }
1155 1174
1156 test_assignment_null() async { 1175 test_assignment_null() async {
1157 String code = r''' 1176 String code = r'''
1158 main() { 1177 main() {
1159 int v; // declare 1178 int v; // declare
1160 v = null; 1179 v = null;
1161 return v; // return 1180 return v; // return
1162 }'''; 1181 }''';
1163 CompilationUnit unit; 1182 CompilationUnit unit;
1164 { 1183 {
1165 Source source = addSource(code); 1184 Source source = addSource(code);
1166 LibraryElement library = resolve2(source); 1185 LibraryElement library = resolve2(source);
1167 await assertNoErrors(source); 1186 await computeAnalysisResult(source);
1187 assertNoErrors(source);
1168 verify([source]); 1188 verify([source]);
1169 unit = resolveCompilationUnit(source, library); 1189 unit = resolveCompilationUnit(source, library);
1170 } 1190 }
1171 { 1191 {
1172 SimpleIdentifier identifier = EngineTestCase.findNode( 1192 SimpleIdentifier identifier = EngineTestCase.findNode(
1173 unit, code, "v; // declare", (node) => node is SimpleIdentifier); 1193 unit, code, "v; // declare", (node) => node is SimpleIdentifier);
1174 expect(identifier.staticType, same(typeProvider.intType)); 1194 expect(identifier.staticType, same(typeProvider.intType));
1175 expect(identifier.propagatedType, same(null)); 1195 expect(identifier.propagatedType, same(null));
1176 } 1196 }
1177 { 1197 {
(...skipping 11 matching lines...) Expand all
1189 } 1209 }
1190 1210
1191 test_CanvasElement_getContext() async { 1211 test_CanvasElement_getContext() async {
1192 String code = r''' 1212 String code = r'''
1193 import 'dart:html'; 1213 import 'dart:html';
1194 main(CanvasElement canvas) { 1214 main(CanvasElement canvas) {
1195 var context = canvas.getContext('2d'); 1215 var context = canvas.getContext('2d');
1196 }'''; 1216 }''';
1197 Source source = addSource(code); 1217 Source source = addSource(code);
1198 LibraryElement library = resolve2(source); 1218 LibraryElement library = resolve2(source);
1199 await assertNoErrors(source); 1219 await computeAnalysisResult(source);
1220 assertNoErrors(source);
1200 verify([source]); 1221 verify([source]);
1201 CompilationUnit unit = resolveCompilationUnit(source, library); 1222 CompilationUnit unit = resolveCompilationUnit(source, library);
1202 SimpleIdentifier identifier = EngineTestCase.findNode( 1223 SimpleIdentifier identifier = EngineTestCase.findNode(
1203 unit, code, "context", (node) => node is SimpleIdentifier); 1224 unit, code, "context", (node) => node is SimpleIdentifier);
1204 expect(resolutionMap.propagatedTypeForExpression(identifier).name, 1225 expect(resolutionMap.propagatedTypeForExpression(identifier).name,
1205 "CanvasRenderingContext2D"); 1226 "CanvasRenderingContext2D");
1206 } 1227 }
1207 1228
1208 test_forEach() async { 1229 test_forEach() async {
1209 String code = r''' 1230 String code = r'''
1210 main() { 1231 main() {
1211 var list = <String> []; 1232 var list = <String> [];
1212 for (var e in list) { 1233 for (var e in list) {
1213 e; 1234 e;
1214 } 1235 }
1215 }'''; 1236 }''';
1216 Source source = addSource(code); 1237 Source source = addSource(code);
1217 LibraryElement library = resolve2(source); 1238 LibraryElement library = resolve2(source);
1218 await assertNoErrors(source); 1239 await computeAnalysisResult(source);
1240 assertNoErrors(source);
1219 verify([source]); 1241 verify([source]);
1220 CompilationUnit unit = resolveCompilationUnit(source, library); 1242 CompilationUnit unit = resolveCompilationUnit(source, library);
1221 InterfaceType stringType = typeProvider.stringType; 1243 InterfaceType stringType = typeProvider.stringType;
1222 // in the declaration 1244 // in the declaration
1223 { 1245 {
1224 SimpleIdentifier identifier = EngineTestCase.findNode( 1246 SimpleIdentifier identifier = EngineTestCase.findNode(
1225 unit, code, "e in", (node) => node is SimpleIdentifier); 1247 unit, code, "e in", (node) => node is SimpleIdentifier);
1226 expect(identifier.propagatedType, same(stringType)); 1248 expect(identifier.propagatedType, same(stringType));
1227 } 1249 }
1228 // in the loop body 1250 // in the loop body
1229 { 1251 {
1230 SimpleIdentifier identifier = EngineTestCase.findNode( 1252 SimpleIdentifier identifier = EngineTestCase.findNode(
1231 unit, code, "e;", (node) => node is SimpleIdentifier); 1253 unit, code, "e;", (node) => node is SimpleIdentifier);
1232 expect(identifier.propagatedType, same(stringType)); 1254 expect(identifier.propagatedType, same(stringType));
1233 } 1255 }
1234 } 1256 }
1235 1257
1236 test_forEach_async() async { 1258 test_forEach_async() async {
1237 String code = r''' 1259 String code = r'''
1238 import 'dart:async'; 1260 import 'dart:async';
1239 f(Stream<String> stream) async { 1261 f(Stream<String> stream) async {
1240 await for (var e in stream) { 1262 await for (var e in stream) {
1241 e; 1263 e;
1242 } 1264 }
1243 }'''; 1265 }''';
1244 Source source = addSource(code); 1266 Source source = addSource(code);
1245 LibraryElement library = resolve2(source); 1267 LibraryElement library = resolve2(source);
1246 await assertNoErrors(source); 1268 await computeAnalysisResult(source);
1269 assertNoErrors(source);
1247 verify([source]); 1270 verify([source]);
1248 CompilationUnit unit = resolveCompilationUnit(source, library); 1271 CompilationUnit unit = resolveCompilationUnit(source, library);
1249 InterfaceType stringType = typeProvider.stringType; 1272 InterfaceType stringType = typeProvider.stringType;
1250 // in the declaration 1273 // in the declaration
1251 { 1274 {
1252 SimpleIdentifier identifier = EngineTestCase.findNode( 1275 SimpleIdentifier identifier = EngineTestCase.findNode(
1253 unit, code, "e in", (node) => node is SimpleIdentifier); 1276 unit, code, "e in", (node) => node is SimpleIdentifier);
1254 expect(identifier.propagatedType, same(stringType)); 1277 expect(identifier.propagatedType, same(stringType));
1255 } 1278 }
1256 // in the loop body 1279 // in the loop body
(...skipping 11 matching lines...) Expand all
1268 String code = r''' 1291 String code = r'''
1269 import 'dart:async'; 1292 import 'dart:async';
1270 abstract class MyCustomStream<T> implements Stream<List<T>> {} 1293 abstract class MyCustomStream<T> implements Stream<List<T>> {}
1271 f(MyCustomStream<String> stream) async { 1294 f(MyCustomStream<String> stream) async {
1272 await for (var e in stream) { 1295 await for (var e in stream) {
1273 e; 1296 e;
1274 } 1297 }
1275 }'''; 1298 }''';
1276 Source source = addSource(code); 1299 Source source = addSource(code);
1277 LibraryElement library = resolve2(source); 1300 LibraryElement library = resolve2(source);
1278 await assertNoErrors(source); 1301 await computeAnalysisResult(source);
1302 assertNoErrors(source);
1279 verify([source]); 1303 verify([source]);
1280 CompilationUnit unit = resolveCompilationUnit(source, library); 1304 CompilationUnit unit = resolveCompilationUnit(source, library);
1281 InterfaceType listOfStringType = 1305 InterfaceType listOfStringType =
1282 typeProvider.listType.instantiate([typeProvider.stringType]); 1306 typeProvider.listType.instantiate([typeProvider.stringType]);
1283 // in the declaration 1307 // in the declaration
1284 { 1308 {
1285 SimpleIdentifier identifier = EngineTestCase.findNode( 1309 SimpleIdentifier identifier = EngineTestCase.findNode(
1286 unit, code, "e in", (node) => node is SimpleIdentifier); 1310 unit, code, "e in", (node) => node is SimpleIdentifier);
1287 expect(identifier.propagatedType, equals(listOfStringType)); 1311 expect(identifier.propagatedType, equals(listOfStringType));
1288 } 1312 }
(...skipping 11 matching lines...) Expand all
1300 forEach(f(K key, V value)) {} 1324 forEach(f(K key, V value)) {}
1301 } 1325 }
1302 f(MyMap<int, String> m) { 1326 f(MyMap<int, String> m) {
1303 m.forEach((k, v) { 1327 m.forEach((k, v) {
1304 k; 1328 k;
1305 v; 1329 v;
1306 }); 1330 });
1307 }'''; 1331 }''';
1308 Source source = addSource(code); 1332 Source source = addSource(code);
1309 LibraryElement library = resolve2(source); 1333 LibraryElement library = resolve2(source);
1310 await assertNoErrors(source); 1334 await computeAnalysisResult(source);
1335 assertNoErrors(source);
1311 verify([source]); 1336 verify([source]);
1312 CompilationUnit unit = resolveCompilationUnit(source, library); 1337 CompilationUnit unit = resolveCompilationUnit(source, library);
1313 // k 1338 // k
1314 DartType intType = typeProvider.intType; 1339 DartType intType = typeProvider.intType;
1315 FormalParameter kParameter = EngineTestCase.findNode( 1340 FormalParameter kParameter = EngineTestCase.findNode(
1316 unit, code, "k, ", (node) => node is SimpleFormalParameter); 1341 unit, code, "k, ", (node) => node is SimpleFormalParameter);
1317 expect(kParameter.identifier.propagatedType, same(intType)); 1342 expect(kParameter.identifier.propagatedType, same(intType));
1318 SimpleIdentifier kIdentifier = EngineTestCase.findNode( 1343 SimpleIdentifier kIdentifier = EngineTestCase.findNode(
1319 unit, code, "k;", (node) => node is SimpleIdentifier); 1344 unit, code, "k;", (node) => node is SimpleIdentifier);
1320 expect(kIdentifier.propagatedType, same(intType)); 1345 expect(kIdentifier.propagatedType, same(intType));
(...skipping 13 matching lines...) Expand all
1334 String code = r''' 1359 String code = r'''
1335 class MyMap<K, V> { 1360 class MyMap<K, V> {
1336 forEach(f(K key, V value)) {} 1361 forEach(f(K key, V value)) {}
1337 } 1362 }
1338 f(MyMap<int, String> m) { 1363 f(MyMap<int, String> m) {
1339 var m2 = m; 1364 var m2 = m;
1340 m2.forEach((k, v) {}); 1365 m2.forEach((k, v) {});
1341 }'''; 1366 }''';
1342 Source source = addSource(code); 1367 Source source = addSource(code);
1343 LibraryElement library = resolve2(source); 1368 LibraryElement library = resolve2(source);
1344 await assertNoErrors(source); 1369 await computeAnalysisResult(source);
1370 assertNoErrors(source);
1345 verify([source]); 1371 verify([source]);
1346 CompilationUnit unit = resolveCompilationUnit(source, library); 1372 CompilationUnit unit = resolveCompilationUnit(source, library);
1347 // k 1373 // k
1348 DartType intType = typeProvider.intType; 1374 DartType intType = typeProvider.intType;
1349 FormalParameter kParameter = EngineTestCase.findNode( 1375 FormalParameter kParameter = EngineTestCase.findNode(
1350 unit, code, "k, ", (node) => node is SimpleFormalParameter); 1376 unit, code, "k, ", (node) => node is SimpleFormalParameter);
1351 expect(kParameter.identifier.propagatedType, same(intType)); 1377 expect(kParameter.identifier.propagatedType, same(intType));
1352 // v 1378 // v
1353 DartType stringType = typeProvider.stringType; 1379 DartType stringType = typeProvider.stringType;
1354 FormalParameter vParameter = EngineTestCase.findNode( 1380 FormalParameter vParameter = EngineTestCase.findNode(
1355 unit, code, "v)", (node) => node is SimpleFormalParameter); 1381 unit, code, "v)", (node) => node is SimpleFormalParameter);
1356 expect(vParameter.identifier.propagatedType, same(stringType)); 1382 expect(vParameter.identifier.propagatedType, same(stringType));
1357 } 1383 }
1358 1384
1359 test_functionExpression_asInvocationArgument_functionExpressionInvocation() as ync { 1385 test_functionExpression_asInvocationArgument_functionExpressionInvocation() as ync {
1360 String code = r''' 1386 String code = r'''
1361 main() { 1387 main() {
1362 (f(String value)) {} ((v) { 1388 (f(String value)) {} ((v) {
1363 v; 1389 v;
1364 }); 1390 });
1365 }'''; 1391 }''';
1366 Source source = addSource(code); 1392 Source source = addSource(code);
1367 LibraryElement library = resolve2(source); 1393 LibraryElement library = resolve2(source);
1368 await assertNoErrors(source); 1394 await computeAnalysisResult(source);
1395 assertNoErrors(source);
1369 verify([source]); 1396 verify([source]);
1370 CompilationUnit unit = resolveCompilationUnit(source, library); 1397 CompilationUnit unit = resolveCompilationUnit(source, library);
1371 // v 1398 // v
1372 DartType dynamicType = typeProvider.dynamicType; 1399 DartType dynamicType = typeProvider.dynamicType;
1373 DartType stringType = typeProvider.stringType; 1400 DartType stringType = typeProvider.stringType;
1374 FormalParameter vParameter = EngineTestCase.findNode( 1401 FormalParameter vParameter = EngineTestCase.findNode(
1375 unit, code, "v)", (node) => node is FormalParameter); 1402 unit, code, "v)", (node) => node is FormalParameter);
1376 expect(vParameter.identifier.propagatedType, same(stringType)); 1403 expect(vParameter.identifier.propagatedType, same(stringType));
1377 expect(vParameter.identifier.staticType, same(dynamicType)); 1404 expect(vParameter.identifier.staticType, same(dynamicType));
1378 SimpleIdentifier vIdentifier = EngineTestCase.findNode( 1405 SimpleIdentifier vIdentifier = EngineTestCase.findNode(
1379 unit, code, "v;", (node) => node is SimpleIdentifier); 1406 unit, code, "v;", (node) => node is SimpleIdentifier);
1380 expect(vIdentifier.propagatedType, same(stringType)); 1407 expect(vIdentifier.propagatedType, same(stringType));
1381 expect(vIdentifier.staticType, same(dynamicType)); 1408 expect(vIdentifier.staticType, same(dynamicType));
1382 } 1409 }
1383 1410
1384 test_functionExpression_asInvocationArgument_keepIfLessSpecific() async { 1411 test_functionExpression_asInvocationArgument_keepIfLessSpecific() async {
1385 String code = r''' 1412 String code = r'''
1386 class MyList { 1413 class MyList {
1387 forEach(f(Object value)) {} 1414 forEach(f(Object value)) {}
1388 } 1415 }
1389 f(MyList list) { 1416 f(MyList list) {
1390 list.forEach((int v) { 1417 list.forEach((int v) {
1391 v; 1418 v;
1392 }); 1419 });
1393 }'''; 1420 }''';
1394 Source source = addSource(code); 1421 Source source = addSource(code);
1395 LibraryElement library = resolve2(source); 1422 LibraryElement library = resolve2(source);
1396 await assertNoErrors(source); 1423 await computeAnalysisResult(source);
1424 assertNoErrors(source);
1397 verify([source]); 1425 verify([source]);
1398 CompilationUnit unit = resolveCompilationUnit(source, library); 1426 CompilationUnit unit = resolveCompilationUnit(source, library);
1399 // v 1427 // v
1400 DartType intType = typeProvider.intType; 1428 DartType intType = typeProvider.intType;
1401 FormalParameter vParameter = EngineTestCase.findNode( 1429 FormalParameter vParameter = EngineTestCase.findNode(
1402 unit, code, "v)", (node) => node is SimpleFormalParameter); 1430 unit, code, "v)", (node) => node is SimpleFormalParameter);
1403 expect(vParameter.identifier.propagatedType, same(null)); 1431 expect(vParameter.identifier.propagatedType, same(null));
1404 expect(vParameter.identifier.staticType, same(intType)); 1432 expect(vParameter.identifier.staticType, same(intType));
1405 SimpleIdentifier vIdentifier = EngineTestCase.findNode( 1433 SimpleIdentifier vIdentifier = EngineTestCase.findNode(
1406 unit, code, "v;", (node) => node is SimpleIdentifier); 1434 unit, code, "v;", (node) => node is SimpleIdentifier);
1407 expect(vIdentifier.staticType, same(intType)); 1435 expect(vIdentifier.staticType, same(intType));
1408 expect(vIdentifier.propagatedType, same(null)); 1436 expect(vIdentifier.propagatedType, same(null));
1409 } 1437 }
1410 1438
1411 test_functionExpression_asInvocationArgument_notSubtypeOfStaticType() async { 1439 test_functionExpression_asInvocationArgument_notSubtypeOfStaticType() async {
1412 String code = r''' 1440 String code = r'''
1413 class A { 1441 class A {
1414 m(void f(int i)) {} 1442 m(void f(int i)) {}
1415 } 1443 }
1416 x() { 1444 x() {
1417 A a = new A(); 1445 A a = new A();
1418 a.m(() => 0); 1446 a.m(() => 0);
1419 }'''; 1447 }''';
1420 Source source = addSource(code); 1448 Source source = addSource(code);
1421 LibraryElement library = resolve2(source); 1449 LibraryElement library = resolve2(source);
1422 await assertErrors( 1450 await computeAnalysisResult(source);
1423 source, [StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE]); 1451 assertErrors(source, [StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE]);
1424 verify([source]); 1452 verify([source]);
1425 CompilationUnit unit = resolveCompilationUnit(source, library); 1453 CompilationUnit unit = resolveCompilationUnit(source, library);
1426 // () => 0 1454 // () => 0
1427 FunctionExpression functionExpression = EngineTestCase.findNode( 1455 FunctionExpression functionExpression = EngineTestCase.findNode(
1428 unit, code, "() => 0)", (node) => node is FunctionExpression); 1456 unit, code, "() => 0)", (node) => node is FunctionExpression);
1429 expect((functionExpression.staticType as FunctionType).parameters.length, 1457 expect((functionExpression.staticType as FunctionType).parameters.length,
1430 same(0)); 1458 same(0));
1431 expect(functionExpression.propagatedType, same(null)); 1459 expect(functionExpression.propagatedType, same(null));
1432 } 1460 }
1433 1461
1434 test_functionExpression_asInvocationArgument_replaceIfMoreSpecific() async { 1462 test_functionExpression_asInvocationArgument_replaceIfMoreSpecific() async {
1435 String code = r''' 1463 String code = r'''
1436 class MyList<E> { 1464 class MyList<E> {
1437 forEach(f(E value)) {} 1465 forEach(f(E value)) {}
1438 } 1466 }
1439 f(MyList<String> list) { 1467 f(MyList<String> list) {
1440 list.forEach((Object v) { 1468 list.forEach((Object v) {
1441 v; 1469 v;
1442 }); 1470 });
1443 }'''; 1471 }''';
1444 Source source = addSource(code); 1472 Source source = addSource(code);
1445 LibraryElement library = resolve2(source); 1473 LibraryElement library = resolve2(source);
1446 await assertNoErrors(source); 1474 await computeAnalysisResult(source);
1475 assertNoErrors(source);
1447 verify([source]); 1476 verify([source]);
1448 CompilationUnit unit = resolveCompilationUnit(source, library); 1477 CompilationUnit unit = resolveCompilationUnit(source, library);
1449 // v 1478 // v
1450 DartType stringType = typeProvider.stringType; 1479 DartType stringType = typeProvider.stringType;
1451 FormalParameter vParameter = EngineTestCase.findNode( 1480 FormalParameter vParameter = EngineTestCase.findNode(
1452 unit, code, "v)", (node) => node is SimpleFormalParameter); 1481 unit, code, "v)", (node) => node is SimpleFormalParameter);
1453 expect(vParameter.identifier.propagatedType, same(stringType)); 1482 expect(vParameter.identifier.propagatedType, same(stringType));
1454 expect(vParameter.identifier.staticType, same(typeProvider.objectType)); 1483 expect(vParameter.identifier.staticType, same(typeProvider.objectType));
1455 SimpleIdentifier vIdentifier = EngineTestCase.findNode( 1484 SimpleIdentifier vIdentifier = EngineTestCase.findNode(
1456 unit, code, "v;", (node) => node is SimpleIdentifier); 1485 unit, code, "v;", (node) => node is SimpleIdentifier);
1457 expect(vIdentifier.propagatedType, same(stringType)); 1486 expect(vIdentifier.propagatedType, same(stringType));
1458 } 1487 }
1459 1488
1460 test_Future_then() async { 1489 test_Future_then() async {
1461 String code = r''' 1490 String code = r'''
1462 import 'dart:async'; 1491 import 'dart:async';
1463 main(Future<int> firstFuture) { 1492 main(Future<int> firstFuture) {
1464 firstFuture.then((p1) { 1493 firstFuture.then((p1) {
1465 return 1.0; 1494 return 1.0;
1466 }).then((p2) { 1495 }).then((p2) {
1467 return new Future<String>.value('str'); 1496 return new Future<String>.value('str');
1468 }).then((p3) { 1497 }).then((p3) {
1469 }); 1498 });
1470 }'''; 1499 }''';
1471 Source source = addSource(code); 1500 Source source = addSource(code);
1472 LibraryElement library = resolve2(source); 1501 LibraryElement library = resolve2(source);
1473 await assertNoErrors(source); 1502 await computeAnalysisResult(source);
1503 assertNoErrors(source);
1474 verify([source]); 1504 verify([source]);
1475 CompilationUnit unit = resolveCompilationUnit(source, library); 1505 CompilationUnit unit = resolveCompilationUnit(source, library);
1476 // p1 1506 // p1
1477 FormalParameter p1 = EngineTestCase.findNode( 1507 FormalParameter p1 = EngineTestCase.findNode(
1478 unit, code, "p1) {", (node) => node is SimpleFormalParameter); 1508 unit, code, "p1) {", (node) => node is SimpleFormalParameter);
1479 expect(p1.identifier.propagatedType, same(typeProvider.intType)); 1509 expect(p1.identifier.propagatedType, same(typeProvider.intType));
1480 // p2 1510 // p2
1481 FormalParameter p2 = EngineTestCase.findNode( 1511 FormalParameter p2 = EngineTestCase.findNode(
1482 unit, code, "p2) {", (node) => node is SimpleFormalParameter); 1512 unit, code, "p2) {", (node) => node is SimpleFormalParameter);
1483 expect(p2.identifier.propagatedType, same(typeProvider.doubleType)); 1513 expect(p2.identifier.propagatedType, same(typeProvider.doubleType));
1484 // p3 1514 // p3
1485 FormalParameter p3 = EngineTestCase.findNode( 1515 FormalParameter p3 = EngineTestCase.findNode(
1486 unit, code, "p3) {", (node) => node is SimpleFormalParameter); 1516 unit, code, "p3) {", (node) => node is SimpleFormalParameter);
1487 expect(p3.identifier.propagatedType, same(typeProvider.stringType)); 1517 expect(p3.identifier.propagatedType, same(typeProvider.stringType));
1488 } 1518 }
1489 1519
1490 test_initializer() async { 1520 test_initializer() async {
1491 Source source = addSource(r''' 1521 Source source = addSource(r'''
1492 f() { 1522 f() {
1493 var v = 0; 1523 var v = 0;
1494 return v; 1524 return v;
1495 }'''); 1525 }''');
1496 LibraryElement library = resolve2(source); 1526 LibraryElement library = resolve2(source);
1497 await assertNoErrors(source); 1527 await computeAnalysisResult(source);
1528 assertNoErrors(source);
1498 verify([source]); 1529 verify([source]);
1499 CompilationUnit unit = resolveCompilationUnit(source, library); 1530 CompilationUnit unit = resolveCompilationUnit(source, library);
1500 FunctionDeclaration function = unit.declarations[0] as FunctionDeclaration; 1531 FunctionDeclaration function = unit.declarations[0] as FunctionDeclaration;
1501 BlockFunctionBody body = 1532 BlockFunctionBody body =
1502 function.functionExpression.body as BlockFunctionBody; 1533 function.functionExpression.body as BlockFunctionBody;
1503 NodeList<Statement> statements = body.block.statements; 1534 NodeList<Statement> statements = body.block.statements;
1504 // Type of 'v' in declaration. 1535 // Type of 'v' in declaration.
1505 { 1536 {
1506 VariableDeclarationStatement statement = 1537 VariableDeclarationStatement statement =
1507 statements[0] as VariableDeclarationStatement; 1538 statements[0] as VariableDeclarationStatement;
(...skipping 27 matching lines...) Expand all
1535 expect(variableName.propagatedType, same(typeProvider.stringType)); 1566 expect(variableName.propagatedType, same(typeProvider.stringType));
1536 } 1567 }
1537 1568
1538 test_initializer_hasStaticType() async { 1569 test_initializer_hasStaticType() async {
1539 Source source = addSource(r''' 1570 Source source = addSource(r'''
1540 f() { 1571 f() {
1541 int v = 0; 1572 int v = 0;
1542 return v; 1573 return v;
1543 }'''); 1574 }''');
1544 LibraryElement library = resolve2(source); 1575 LibraryElement library = resolve2(source);
1545 await assertNoErrors(source); 1576 await computeAnalysisResult(source);
1577 assertNoErrors(source);
1546 verify([source]); 1578 verify([source]);
1547 CompilationUnit unit = resolveCompilationUnit(source, library); 1579 CompilationUnit unit = resolveCompilationUnit(source, library);
1548 FunctionDeclaration function = unit.declarations[0] as FunctionDeclaration; 1580 FunctionDeclaration function = unit.declarations[0] as FunctionDeclaration;
1549 BlockFunctionBody body = 1581 BlockFunctionBody body =
1550 function.functionExpression.body as BlockFunctionBody; 1582 function.functionExpression.body as BlockFunctionBody;
1551 NodeList<Statement> statements = body.block.statements; 1583 NodeList<Statement> statements = body.block.statements;
1552 // Type of 'v' in declaration. 1584 // Type of 'v' in declaration.
1553 { 1585 {
1554 VariableDeclarationStatement statement = 1586 VariableDeclarationStatement statement =
1555 statements[0] as VariableDeclarationStatement; 1587 statements[0] as VariableDeclarationStatement;
(...skipping 10 matching lines...) Expand all
1566 } 1598 }
1567 } 1599 }
1568 1600
1569 test_initializer_hasStaticType_parameterized() async { 1601 test_initializer_hasStaticType_parameterized() async {
1570 Source source = addSource(r''' 1602 Source source = addSource(r'''
1571 f() { 1603 f() {
1572 List<int> v = <int>[]; 1604 List<int> v = <int>[];
1573 return v; 1605 return v;
1574 }'''); 1606 }''');
1575 LibraryElement library = resolve2(source); 1607 LibraryElement library = resolve2(source);
1576 await assertNoErrors(source); 1608 await computeAnalysisResult(source);
1609 assertNoErrors(source);
1577 verify([source]); 1610 verify([source]);
1578 CompilationUnit unit = resolveCompilationUnit(source, library); 1611 CompilationUnit unit = resolveCompilationUnit(source, library);
1579 FunctionDeclaration function = unit.declarations[0] as FunctionDeclaration; 1612 FunctionDeclaration function = unit.declarations[0] as FunctionDeclaration;
1580 BlockFunctionBody body = 1613 BlockFunctionBody body =
1581 function.functionExpression.body as BlockFunctionBody; 1614 function.functionExpression.body as BlockFunctionBody;
1582 NodeList<Statement> statements = body.block.statements; 1615 NodeList<Statement> statements = body.block.statements;
1583 // Type of 'v' in declaration. 1616 // Type of 'v' in declaration.
1584 { 1617 {
1585 VariableDeclarationStatement statement = 1618 VariableDeclarationStatement statement =
1586 statements[0] as VariableDeclarationStatement; 1619 statements[0] as VariableDeclarationStatement;
(...skipping 13 matching lines...) Expand all
1600 test_initializer_null() async { 1633 test_initializer_null() async {
1601 String code = r''' 1634 String code = r'''
1602 main() { 1635 main() {
1603 int v = null; 1636 int v = null;
1604 return v; // marker 1637 return v; // marker
1605 }'''; 1638 }''';
1606 CompilationUnit unit; 1639 CompilationUnit unit;
1607 { 1640 {
1608 Source source = addSource(code); 1641 Source source = addSource(code);
1609 LibraryElement library = resolve2(source); 1642 LibraryElement library = resolve2(source);
1610 await assertNoErrors(source); 1643 await computeAnalysisResult(source);
1644 assertNoErrors(source);
1611 verify([source]); 1645 verify([source]);
1612 unit = resolveCompilationUnit(source, library); 1646 unit = resolveCompilationUnit(source, library);
1613 } 1647 }
1614 { 1648 {
1615 SimpleIdentifier identifier = EngineTestCase.findNode( 1649 SimpleIdentifier identifier = EngineTestCase.findNode(
1616 unit, code, "v = null;", (node) => node is SimpleIdentifier); 1650 unit, code, "v = null;", (node) => node is SimpleIdentifier);
1617 expect(identifier.staticType, same(typeProvider.intType)); 1651 expect(identifier.staticType, same(typeProvider.intType));
1618 expect(identifier.propagatedType, same(null)); 1652 expect(identifier.propagatedType, same(null));
1619 } 1653 }
1620 { 1654 {
(...skipping 23 matching lines...) Expand all
1644 expect(methodInvoke.methodName.propagatedElement, isNull); 1678 expect(methodInvoke.methodName.propagatedElement, isNull);
1645 } 1679 }
1646 1680
1647 test_is_conditional() async { 1681 test_is_conditional() async {
1648 Source source = addSource(r''' 1682 Source source = addSource(r'''
1649 class A {} 1683 class A {}
1650 A f(var p) { 1684 A f(var p) {
1651 return (p is A) ? p : null; 1685 return (p is A) ? p : null;
1652 }'''); 1686 }''');
1653 LibraryElement library = resolve2(source); 1687 LibraryElement library = resolve2(source);
1654 await assertNoErrors(source); 1688 await computeAnalysisResult(source);
1689 assertNoErrors(source);
1655 verify([source]); 1690 verify([source]);
1656 CompilationUnit unit = resolveCompilationUnit(source, library); 1691 CompilationUnit unit = resolveCompilationUnit(source, library);
1657 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration; 1692 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration;
1658 InterfaceType typeA = 1693 InterfaceType typeA =
1659 resolutionMap.elementDeclaredByClassDeclaration(classA).type; 1694 resolutionMap.elementDeclaredByClassDeclaration(classA).type;
1660 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration; 1695 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration;
1661 BlockFunctionBody body = 1696 BlockFunctionBody body =
1662 function.functionExpression.body as BlockFunctionBody; 1697 function.functionExpression.body as BlockFunctionBody;
1663 ReturnStatement statement = body.block.statements[0] as ReturnStatement; 1698 ReturnStatement statement = body.block.statements[0] as ReturnStatement;
1664 ConditionalExpression conditional = 1699 ConditionalExpression conditional =
1665 statement.expression as ConditionalExpression; 1700 statement.expression as ConditionalExpression;
1666 SimpleIdentifier variableName = 1701 SimpleIdentifier variableName =
1667 conditional.thenExpression as SimpleIdentifier; 1702 conditional.thenExpression as SimpleIdentifier;
1668 expect(variableName.propagatedType, same(typeA)); 1703 expect(variableName.propagatedType, same(typeA));
1669 } 1704 }
1670 1705
1671 test_is_if() async { 1706 test_is_if() async {
1672 Source source = addSource(r''' 1707 Source source = addSource(r'''
1673 class A {} 1708 class A {}
1674 A f(var p) { 1709 A f(var p) {
1675 if (p is A) { 1710 if (p is A) {
1676 return p; 1711 return p;
1677 } else { 1712 } else {
1678 return null; 1713 return null;
1679 } 1714 }
1680 }'''); 1715 }''');
1681 LibraryElement library = resolve2(source); 1716 LibraryElement library = resolve2(source);
1682 await assertNoErrors(source); 1717 await computeAnalysisResult(source);
1718 assertNoErrors(source);
1683 verify([source]); 1719 verify([source]);
1684 CompilationUnit unit = resolveCompilationUnit(source, library); 1720 CompilationUnit unit = resolveCompilationUnit(source, library);
1685 // prepare A 1721 // prepare A
1686 InterfaceType typeA; 1722 InterfaceType typeA;
1687 { 1723 {
1688 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration; 1724 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration;
1689 typeA = resolutionMap.elementDeclaredByClassDeclaration(classA).type; 1725 typeA = resolutionMap.elementDeclaredByClassDeclaration(classA).type;
1690 } 1726 }
1691 // verify "f" 1727 // verify "f"
1692 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration; 1728 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration;
(...skipping 19 matching lines...) Expand all
1712 Source source = addSource(r''' 1748 Source source = addSource(r'''
1713 class A {} 1749 class A {}
1714 A f(A p) { 1750 A f(A p) {
1715 if (p is String) { 1751 if (p is String) {
1716 return p; 1752 return p;
1717 } else { 1753 } else {
1718 return null; 1754 return null;
1719 } 1755 }
1720 }'''); 1756 }''');
1721 LibraryElement library = resolve2(source); 1757 LibraryElement library = resolve2(source);
1722 await assertNoErrors(source); 1758 await computeAnalysisResult(source);
1759 assertNoErrors(source);
1723 verify([source]); 1760 verify([source]);
1724 CompilationUnit unit = resolveCompilationUnit(source, library); 1761 CompilationUnit unit = resolveCompilationUnit(source, library);
1725 // ClassDeclaration classA = (ClassDeclaration) unit.getDeclarations().get(0) ; 1762 // ClassDeclaration classA = (ClassDeclaration) unit.getDeclarations().get(0) ;
1726 // InterfaceType typeA = classA.getElement().getType(); 1763 // InterfaceType typeA = classA.getElement().getType();
1727 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration; 1764 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration;
1728 BlockFunctionBody body = 1765 BlockFunctionBody body =
1729 function.functionExpression.body as BlockFunctionBody; 1766 function.functionExpression.body as BlockFunctionBody;
1730 IfStatement ifStatement = body.block.statements[0] as IfStatement; 1767 IfStatement ifStatement = body.block.statements[0] as IfStatement;
1731 ReturnStatement statement = 1768 ReturnStatement statement =
1732 (ifStatement.thenStatement as Block).statements[0] as ReturnStatement; 1769 (ifStatement.thenStatement as Block).statements[0] as ReturnStatement;
1733 SimpleIdentifier variableName = statement.expression as SimpleIdentifier; 1770 SimpleIdentifier variableName = statement.expression as SimpleIdentifier;
1734 expect(variableName.propagatedType, same(null)); 1771 expect(variableName.propagatedType, same(null));
1735 } 1772 }
1736 1773
1737 test_is_if_logicalAnd() async { 1774 test_is_if_logicalAnd() async {
1738 Source source = addSource(r''' 1775 Source source = addSource(r'''
1739 class A {} 1776 class A {}
1740 A f(var p) { 1777 A f(var p) {
1741 if (p is A && p != null) { 1778 if (p is A && p != null) {
1742 return p; 1779 return p;
1743 } else { 1780 } else {
1744 return null; 1781 return null;
1745 } 1782 }
1746 }'''); 1783 }''');
1747 LibraryElement library = resolve2(source); 1784 LibraryElement library = resolve2(source);
1748 await assertNoErrors(source); 1785 await computeAnalysisResult(source);
1786 assertNoErrors(source);
1749 verify([source]); 1787 verify([source]);
1750 CompilationUnit unit = resolveCompilationUnit(source, library); 1788 CompilationUnit unit = resolveCompilationUnit(source, library);
1751 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration; 1789 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration;
1752 InterfaceType typeA = 1790 InterfaceType typeA =
1753 resolutionMap.elementDeclaredByClassDeclaration(classA).type; 1791 resolutionMap.elementDeclaredByClassDeclaration(classA).type;
1754 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration; 1792 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration;
1755 BlockFunctionBody body = 1793 BlockFunctionBody body =
1756 function.functionExpression.body as BlockFunctionBody; 1794 function.functionExpression.body as BlockFunctionBody;
1757 IfStatement ifStatement = body.block.statements[0] as IfStatement; 1795 IfStatement ifStatement = body.block.statements[0] as IfStatement;
1758 ReturnStatement statement = 1796 ReturnStatement statement =
1759 (ifStatement.thenStatement as Block).statements[0] as ReturnStatement; 1797 (ifStatement.thenStatement as Block).statements[0] as ReturnStatement;
1760 SimpleIdentifier variableName = statement.expression as SimpleIdentifier; 1798 SimpleIdentifier variableName = statement.expression as SimpleIdentifier;
1761 expect(variableName.propagatedType, same(typeA)); 1799 expect(variableName.propagatedType, same(typeA));
1762 } 1800 }
1763 1801
1764 test_is_postConditional() async { 1802 test_is_postConditional() async {
1765 Source source = addSource(r''' 1803 Source source = addSource(r'''
1766 class A {} 1804 class A {}
1767 A f(var p) { 1805 A f(var p) {
1768 A a = (p is A) ? p : throw null; 1806 A a = (p is A) ? p : throw null;
1769 return p; 1807 return p;
1770 }'''); 1808 }''');
1771 LibraryElement library = resolve2(source); 1809 LibraryElement library = resolve2(source);
1772 await assertNoErrors(source); 1810 await computeAnalysisResult(source);
1811 assertNoErrors(source);
1773 verify([source]); 1812 verify([source]);
1774 CompilationUnit unit = resolveCompilationUnit(source, library); 1813 CompilationUnit unit = resolveCompilationUnit(source, library);
1775 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration; 1814 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration;
1776 InterfaceType typeA = 1815 InterfaceType typeA =
1777 resolutionMap.elementDeclaredByClassDeclaration(classA).type; 1816 resolutionMap.elementDeclaredByClassDeclaration(classA).type;
1778 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration; 1817 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration;
1779 BlockFunctionBody body = 1818 BlockFunctionBody body =
1780 function.functionExpression.body as BlockFunctionBody; 1819 function.functionExpression.body as BlockFunctionBody;
1781 ReturnStatement statement = body.block.statements[1] as ReturnStatement; 1820 ReturnStatement statement = body.block.statements[1] as ReturnStatement;
1782 SimpleIdentifier variableName = statement.expression as SimpleIdentifier; 1821 SimpleIdentifier variableName = statement.expression as SimpleIdentifier;
1783 expect(variableName.propagatedType, same(typeA)); 1822 expect(variableName.propagatedType, same(typeA));
1784 } 1823 }
1785 1824
1786 test_is_postIf() async { 1825 test_is_postIf() async {
1787 Source source = addSource(r''' 1826 Source source = addSource(r'''
1788 class A {} 1827 class A {}
1789 A f(var p) { 1828 A f(var p) {
1790 if (p is A) { 1829 if (p is A) {
1791 A a = p; 1830 A a = p;
1792 } else { 1831 } else {
1793 return null; 1832 return null;
1794 } 1833 }
1795 return p; 1834 return p;
1796 }'''); 1835 }''');
1797 LibraryElement library = resolve2(source); 1836 LibraryElement library = resolve2(source);
1798 await assertNoErrors(source); 1837 await computeAnalysisResult(source);
1838 assertNoErrors(source);
1799 verify([source]); 1839 verify([source]);
1800 CompilationUnit unit = resolveCompilationUnit(source, library); 1840 CompilationUnit unit = resolveCompilationUnit(source, library);
1801 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration; 1841 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration;
1802 InterfaceType typeA = 1842 InterfaceType typeA =
1803 resolutionMap.elementDeclaredByClassDeclaration(classA).type; 1843 resolutionMap.elementDeclaredByClassDeclaration(classA).type;
1804 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration; 1844 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration;
1805 BlockFunctionBody body = 1845 BlockFunctionBody body =
1806 function.functionExpression.body as BlockFunctionBody; 1846 function.functionExpression.body as BlockFunctionBody;
1807 ReturnStatement statement = body.block.statements[1] as ReturnStatement; 1847 ReturnStatement statement = body.block.statements[1] as ReturnStatement;
1808 SimpleIdentifier variableName = statement.expression as SimpleIdentifier; 1848 SimpleIdentifier variableName = statement.expression as SimpleIdentifier;
1809 expect(variableName.propagatedType, same(typeA)); 1849 expect(variableName.propagatedType, same(typeA));
1810 } 1850 }
1811 1851
1812 test_is_subclass() async { 1852 test_is_subclass() async {
1813 Source source = addSource(r''' 1853 Source source = addSource(r'''
1814 class A {} 1854 class A {}
1815 class B extends A { 1855 class B extends A {
1816 B m() => this; 1856 B m() => this;
1817 } 1857 }
1818 A f(A p) { 1858 A f(A p) {
1819 if (p is B) { 1859 if (p is B) {
1820 return p.m(); 1860 return p.m();
1821 } 1861 }
1822 return p; 1862 return p;
1823 }'''); 1863 }''');
1824 LibraryElement library = resolve2(source); 1864 LibraryElement library = resolve2(source);
1825 await assertNoErrors(source); 1865 await computeAnalysisResult(source);
1866 assertNoErrors(source);
1826 CompilationUnit unit = resolveCompilationUnit(source, library); 1867 CompilationUnit unit = resolveCompilationUnit(source, library);
1827 FunctionDeclaration function = unit.declarations[2] as FunctionDeclaration; 1868 FunctionDeclaration function = unit.declarations[2] as FunctionDeclaration;
1828 BlockFunctionBody body = 1869 BlockFunctionBody body =
1829 function.functionExpression.body as BlockFunctionBody; 1870 function.functionExpression.body as BlockFunctionBody;
1830 IfStatement ifStatement = body.block.statements[0] as IfStatement; 1871 IfStatement ifStatement = body.block.statements[0] as IfStatement;
1831 ReturnStatement statement = 1872 ReturnStatement statement =
1832 (ifStatement.thenStatement as Block).statements[0] as ReturnStatement; 1873 (ifStatement.thenStatement as Block).statements[0] as ReturnStatement;
1833 MethodInvocation invocation = statement.expression as MethodInvocation; 1874 MethodInvocation invocation = statement.expression as MethodInvocation;
1834 expect(invocation.methodName.staticElement, isNotNull); 1875 expect(invocation.methodName.staticElement, isNotNull);
1835 expect(invocation.methodName.propagatedElement, isNull); 1876 expect(invocation.methodName.propagatedElement, isNull);
1836 } 1877 }
1837 1878
1838 test_is_while() async { 1879 test_is_while() async {
1839 Source source = addSource(r''' 1880 Source source = addSource(r'''
1840 class A {} 1881 class A {}
1841 A f(var p) { 1882 A f(var p) {
1842 while (p is A) { 1883 while (p is A) {
1843 return p; 1884 return p;
1844 } 1885 }
1845 return p; 1886 return p;
1846 }'''); 1887 }''');
1847 LibraryElement library = resolve2(source); 1888 LibraryElement library = resolve2(source);
1848 await assertNoErrors(source); 1889 await computeAnalysisResult(source);
1890 assertNoErrors(source);
1849 verify([source]); 1891 verify([source]);
1850 CompilationUnit unit = resolveCompilationUnit(source, library); 1892 CompilationUnit unit = resolveCompilationUnit(source, library);
1851 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration; 1893 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration;
1852 InterfaceType typeA = 1894 InterfaceType typeA =
1853 resolutionMap.elementDeclaredByClassDeclaration(classA).type; 1895 resolutionMap.elementDeclaredByClassDeclaration(classA).type;
1854 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration; 1896 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration;
1855 BlockFunctionBody body = 1897 BlockFunctionBody body =
1856 function.functionExpression.body as BlockFunctionBody; 1898 function.functionExpression.body as BlockFunctionBody;
1857 WhileStatement whileStatement = body.block.statements[0] as WhileStatement; 1899 WhileStatement whileStatement = body.block.statements[0] as WhileStatement;
1858 ReturnStatement statement = 1900 ReturnStatement statement =
1859 (whileStatement.body as Block).statements[0] as ReturnStatement; 1901 (whileStatement.body as Block).statements[0] as ReturnStatement;
1860 SimpleIdentifier variableName = statement.expression as SimpleIdentifier; 1902 SimpleIdentifier variableName = statement.expression as SimpleIdentifier;
1861 expect(variableName.propagatedType, same(typeA)); 1903 expect(variableName.propagatedType, same(typeA));
1862 } 1904 }
1863 1905
1864 test_isNot_conditional() async { 1906 test_isNot_conditional() async {
1865 Source source = addSource(r''' 1907 Source source = addSource(r'''
1866 class A {} 1908 class A {}
1867 A f(var p) { 1909 A f(var p) {
1868 return (p is! A) ? null : p; 1910 return (p is! A) ? null : p;
1869 }'''); 1911 }''');
1870 LibraryElement library = resolve2(source); 1912 LibraryElement library = resolve2(source);
1871 await assertNoErrors(source); 1913 await computeAnalysisResult(source);
1914 assertNoErrors(source);
1872 verify([source]); 1915 verify([source]);
1873 CompilationUnit unit = resolveCompilationUnit(source, library); 1916 CompilationUnit unit = resolveCompilationUnit(source, library);
1874 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration; 1917 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration;
1875 InterfaceType typeA = 1918 InterfaceType typeA =
1876 resolutionMap.elementDeclaredByClassDeclaration(classA).type; 1919 resolutionMap.elementDeclaredByClassDeclaration(classA).type;
1877 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration; 1920 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration;
1878 BlockFunctionBody body = 1921 BlockFunctionBody body =
1879 function.functionExpression.body as BlockFunctionBody; 1922 function.functionExpression.body as BlockFunctionBody;
1880 ReturnStatement statement = body.block.statements[0] as ReturnStatement; 1923 ReturnStatement statement = body.block.statements[0] as ReturnStatement;
1881 ConditionalExpression conditional = 1924 ConditionalExpression conditional =
1882 statement.expression as ConditionalExpression; 1925 statement.expression as ConditionalExpression;
1883 SimpleIdentifier variableName = 1926 SimpleIdentifier variableName =
1884 conditional.elseExpression as SimpleIdentifier; 1927 conditional.elseExpression as SimpleIdentifier;
1885 expect(variableName.propagatedType, same(typeA)); 1928 expect(variableName.propagatedType, same(typeA));
1886 } 1929 }
1887 1930
1888 test_isNot_if() async { 1931 test_isNot_if() async {
1889 Source source = addSource(r''' 1932 Source source = addSource(r'''
1890 class A {} 1933 class A {}
1891 A f(var p) { 1934 A f(var p) {
1892 if (p is! A) { 1935 if (p is! A) {
1893 return null; 1936 return null;
1894 } else { 1937 } else {
1895 return p; 1938 return p;
1896 } 1939 }
1897 }'''); 1940 }''');
1898 LibraryElement library = resolve2(source); 1941 LibraryElement library = resolve2(source);
1899 await assertNoErrors(source); 1942 await computeAnalysisResult(source);
1943 assertNoErrors(source);
1900 verify([source]); 1944 verify([source]);
1901 CompilationUnit unit = resolveCompilationUnit(source, library); 1945 CompilationUnit unit = resolveCompilationUnit(source, library);
1902 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration; 1946 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration;
1903 InterfaceType typeA = 1947 InterfaceType typeA =
1904 resolutionMap.elementDeclaredByClassDeclaration(classA).type; 1948 resolutionMap.elementDeclaredByClassDeclaration(classA).type;
1905 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration; 1949 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration;
1906 BlockFunctionBody body = 1950 BlockFunctionBody body =
1907 function.functionExpression.body as BlockFunctionBody; 1951 function.functionExpression.body as BlockFunctionBody;
1908 IfStatement ifStatement = body.block.statements[0] as IfStatement; 1952 IfStatement ifStatement = body.block.statements[0] as IfStatement;
1909 ReturnStatement statement = 1953 ReturnStatement statement =
1910 (ifStatement.elseStatement as Block).statements[0] as ReturnStatement; 1954 (ifStatement.elseStatement as Block).statements[0] as ReturnStatement;
1911 SimpleIdentifier variableName = statement.expression as SimpleIdentifier; 1955 SimpleIdentifier variableName = statement.expression as SimpleIdentifier;
1912 expect(variableName.propagatedType, same(typeA)); 1956 expect(variableName.propagatedType, same(typeA));
1913 } 1957 }
1914 1958
1915 test_isNot_if_logicalOr() async { 1959 test_isNot_if_logicalOr() async {
1916 Source source = addSource(r''' 1960 Source source = addSource(r'''
1917 class A {} 1961 class A {}
1918 A f(var p) { 1962 A f(var p) {
1919 if (p is! A || null == p) { 1963 if (p is! A || null == p) {
1920 return null; 1964 return null;
1921 } else { 1965 } else {
1922 return p; 1966 return p;
1923 } 1967 }
1924 }'''); 1968 }''');
1925 LibraryElement library = resolve2(source); 1969 LibraryElement library = resolve2(source);
1926 await assertNoErrors(source); 1970 await computeAnalysisResult(source);
1971 assertNoErrors(source);
1927 CompilationUnit unit = resolveCompilationUnit(source, library); 1972 CompilationUnit unit = resolveCompilationUnit(source, library);
1928 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration; 1973 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration;
1929 InterfaceType typeA = 1974 InterfaceType typeA =
1930 resolutionMap.elementDeclaredByClassDeclaration(classA).type; 1975 resolutionMap.elementDeclaredByClassDeclaration(classA).type;
1931 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration; 1976 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration;
1932 BlockFunctionBody body = 1977 BlockFunctionBody body =
1933 function.functionExpression.body as BlockFunctionBody; 1978 function.functionExpression.body as BlockFunctionBody;
1934 IfStatement ifStatement = body.block.statements[0] as IfStatement; 1979 IfStatement ifStatement = body.block.statements[0] as IfStatement;
1935 ReturnStatement statement = 1980 ReturnStatement statement =
1936 (ifStatement.elseStatement as Block).statements[0] as ReturnStatement; 1981 (ifStatement.elseStatement as Block).statements[0] as ReturnStatement;
1937 SimpleIdentifier variableName = statement.expression as SimpleIdentifier; 1982 SimpleIdentifier variableName = statement.expression as SimpleIdentifier;
1938 expect(variableName.propagatedType, same(typeA)); 1983 expect(variableName.propagatedType, same(typeA));
1939 } 1984 }
1940 1985
1941 test_isNot_postConditional() async { 1986 test_isNot_postConditional() async {
1942 Source source = addSource(r''' 1987 Source source = addSource(r'''
1943 class A {} 1988 class A {}
1944 A f(var p) { 1989 A f(var p) {
1945 A a = (p is! A) ? throw null : p; 1990 A a = (p is! A) ? throw null : p;
1946 return p; 1991 return p;
1947 }'''); 1992 }''');
1948 LibraryElement library = resolve2(source); 1993 LibraryElement library = resolve2(source);
1949 await assertNoErrors(source); 1994 await computeAnalysisResult(source);
1995 assertNoErrors(source);
1950 verify([source]); 1996 verify([source]);
1951 CompilationUnit unit = resolveCompilationUnit(source, library); 1997 CompilationUnit unit = resolveCompilationUnit(source, library);
1952 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration; 1998 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration;
1953 InterfaceType typeA = 1999 InterfaceType typeA =
1954 resolutionMap.elementDeclaredByClassDeclaration(classA).type; 2000 resolutionMap.elementDeclaredByClassDeclaration(classA).type;
1955 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration; 2001 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration;
1956 BlockFunctionBody body = 2002 BlockFunctionBody body =
1957 function.functionExpression.body as BlockFunctionBody; 2003 function.functionExpression.body as BlockFunctionBody;
1958 ReturnStatement statement = body.block.statements[1] as ReturnStatement; 2004 ReturnStatement statement = body.block.statements[1] as ReturnStatement;
1959 SimpleIdentifier variableName = statement.expression as SimpleIdentifier; 2005 SimpleIdentifier variableName = statement.expression as SimpleIdentifier;
1960 expect(variableName.propagatedType, same(typeA)); 2006 expect(variableName.propagatedType, same(typeA));
1961 } 2007 }
1962 2008
1963 test_isNot_postIf() async { 2009 test_isNot_postIf() async {
1964 Source source = addSource(r''' 2010 Source source = addSource(r'''
1965 class A {} 2011 class A {}
1966 A f(var p) { 2012 A f(var p) {
1967 if (p is! A) { 2013 if (p is! A) {
1968 return null; 2014 return null;
1969 } 2015 }
1970 return p; 2016 return p;
1971 }'''); 2017 }''');
1972 LibraryElement library = resolve2(source); 2018 LibraryElement library = resolve2(source);
1973 await assertNoErrors(source); 2019 await computeAnalysisResult(source);
2020 assertNoErrors(source);
1974 verify([source]); 2021 verify([source]);
1975 CompilationUnit unit = resolveCompilationUnit(source, library); 2022 CompilationUnit unit = resolveCompilationUnit(source, library);
1976 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration; 2023 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration;
1977 InterfaceType typeA = 2024 InterfaceType typeA =
1978 resolutionMap.elementDeclaredByClassDeclaration(classA).type; 2025 resolutionMap.elementDeclaredByClassDeclaration(classA).type;
1979 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration; 2026 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration;
1980 BlockFunctionBody body = 2027 BlockFunctionBody body =
1981 function.functionExpression.body as BlockFunctionBody; 2028 function.functionExpression.body as BlockFunctionBody;
1982 ReturnStatement statement = body.block.statements[1] as ReturnStatement; 2029 ReturnStatement statement = body.block.statements[1] as ReturnStatement;
1983 SimpleIdentifier variableName = statement.expression as SimpleIdentifier; 2030 SimpleIdentifier variableName = statement.expression as SimpleIdentifier;
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
2038 await assertTypeOfMarkedExpression(code, null, tB); 2085 await assertTypeOfMarkedExpression(code, null, tB);
2039 } 2086 }
2040 2087
2041 test_listLiteral_different() async { 2088 test_listLiteral_different() async {
2042 Source source = addSource(r''' 2089 Source source = addSource(r'''
2043 f() { 2090 f() {
2044 var v = [0, '1', 2]; 2091 var v = [0, '1', 2];
2045 return v[2]; 2092 return v[2];
2046 }'''); 2093 }''');
2047 LibraryElement library = resolve2(source); 2094 LibraryElement library = resolve2(source);
2048 await assertNoErrors(source); 2095 await computeAnalysisResult(source);
2096 assertNoErrors(source);
2049 verify([source]); 2097 verify([source]);
2050 CompilationUnit unit = resolveCompilationUnit(source, library); 2098 CompilationUnit unit = resolveCompilationUnit(source, library);
2051 FunctionDeclaration function = unit.declarations[0] as FunctionDeclaration; 2099 FunctionDeclaration function = unit.declarations[0] as FunctionDeclaration;
2052 BlockFunctionBody body = 2100 BlockFunctionBody body =
2053 function.functionExpression.body as BlockFunctionBody; 2101 function.functionExpression.body as BlockFunctionBody;
2054 ReturnStatement statement = body.block.statements[1] as ReturnStatement; 2102 ReturnStatement statement = body.block.statements[1] as ReturnStatement;
2055 IndexExpression indexExpression = statement.expression as IndexExpression; 2103 IndexExpression indexExpression = statement.expression as IndexExpression;
2056 expect(indexExpression.propagatedType, isNull); 2104 expect(indexExpression.propagatedType, isNull);
2057 } 2105 }
2058 2106
2059 test_listLiteral_same() async { 2107 test_listLiteral_same() async {
2060 Source source = addSource(r''' 2108 Source source = addSource(r'''
2061 f() { 2109 f() {
2062 var v = [0, 1, 2]; 2110 var v = [0, 1, 2];
2063 return v[2]; 2111 return v[2];
2064 }'''); 2112 }''');
2065 LibraryElement library = resolve2(source); 2113 LibraryElement library = resolve2(source);
2066 await assertNoErrors(source); 2114 await computeAnalysisResult(source);
2115 assertNoErrors(source);
2067 verify([source]); 2116 verify([source]);
2068 CompilationUnit unit = resolveCompilationUnit(source, library); 2117 CompilationUnit unit = resolveCompilationUnit(source, library);
2069 FunctionDeclaration function = unit.declarations[0] as FunctionDeclaration; 2118 FunctionDeclaration function = unit.declarations[0] as FunctionDeclaration;
2070 BlockFunctionBody body = 2119 BlockFunctionBody body =
2071 function.functionExpression.body as BlockFunctionBody; 2120 function.functionExpression.body as BlockFunctionBody;
2072 ReturnStatement statement = body.block.statements[1] as ReturnStatement; 2121 ReturnStatement statement = body.block.statements[1] as ReturnStatement;
2073 IndexExpression indexExpression = statement.expression as IndexExpression; 2122 IndexExpression indexExpression = statement.expression as IndexExpression;
2074 expect(indexExpression.propagatedType, isNull); 2123 expect(indexExpression.propagatedType, isNull);
2075 Expression v = indexExpression.target; 2124 Expression v = indexExpression.target;
2076 InterfaceType propagatedType = v.propagatedType as InterfaceType; 2125 InterfaceType propagatedType = v.propagatedType as InterfaceType;
2077 expect(propagatedType.element, same(typeProvider.listType.element)); 2126 expect(propagatedType.element, same(typeProvider.listType.element));
2078 List<DartType> typeArguments = propagatedType.typeArguments; 2127 List<DartType> typeArguments = propagatedType.typeArguments;
2079 expect(typeArguments, hasLength(1)); 2128 expect(typeArguments, hasLength(1));
2080 expect(typeArguments[0], same(typeProvider.dynamicType)); 2129 expect(typeArguments[0], same(typeProvider.dynamicType));
2081 } 2130 }
2082 2131
2083 test_mapLiteral_different() async { 2132 test_mapLiteral_different() async {
2084 Source source = addSource(r''' 2133 Source source = addSource(r'''
2085 f() { 2134 f() {
2086 var v = {'0' : 0, 1 : '1', '2' : 2}; 2135 var v = {'0' : 0, 1 : '1', '2' : 2};
2087 return v; 2136 return v;
2088 }'''); 2137 }''');
2089 LibraryElement library = resolve2(source); 2138 LibraryElement library = resolve2(source);
2090 await assertNoErrors(source); 2139 await computeAnalysisResult(source);
2140 assertNoErrors(source);
2091 verify([source]); 2141 verify([source]);
2092 CompilationUnit unit = resolveCompilationUnit(source, library); 2142 CompilationUnit unit = resolveCompilationUnit(source, library);
2093 FunctionDeclaration function = unit.declarations[0] as FunctionDeclaration; 2143 FunctionDeclaration function = unit.declarations[0] as FunctionDeclaration;
2094 BlockFunctionBody body = 2144 BlockFunctionBody body =
2095 function.functionExpression.body as BlockFunctionBody; 2145 function.functionExpression.body as BlockFunctionBody;
2096 ReturnStatement statement = body.block.statements[1] as ReturnStatement; 2146 ReturnStatement statement = body.block.statements[1] as ReturnStatement;
2097 SimpleIdentifier identifier = statement.expression as SimpleIdentifier; 2147 SimpleIdentifier identifier = statement.expression as SimpleIdentifier;
2098 InterfaceType propagatedType = identifier.propagatedType as InterfaceType; 2148 InterfaceType propagatedType = identifier.propagatedType as InterfaceType;
2099 expect(propagatedType.element, same(typeProvider.mapType.element)); 2149 expect(propagatedType.element, same(typeProvider.mapType.element));
2100 List<DartType> typeArguments = propagatedType.typeArguments; 2150 List<DartType> typeArguments = propagatedType.typeArguments;
2101 expect(typeArguments, hasLength(2)); 2151 expect(typeArguments, hasLength(2));
2102 expect(typeArguments[0], same(typeProvider.dynamicType)); 2152 expect(typeArguments[0], same(typeProvider.dynamicType));
2103 expect(typeArguments[1], same(typeProvider.dynamicType)); 2153 expect(typeArguments[1], same(typeProvider.dynamicType));
2104 } 2154 }
2105 2155
2106 test_mapLiteral_same() async { 2156 test_mapLiteral_same() async {
2107 Source source = addSource(r''' 2157 Source source = addSource(r'''
2108 f() { 2158 f() {
2109 var v = {'a' : 0, 'b' : 1, 'c' : 2}; 2159 var v = {'a' : 0, 'b' : 1, 'c' : 2};
2110 return v; 2160 return v;
2111 }'''); 2161 }''');
2112 LibraryElement library = resolve2(source); 2162 LibraryElement library = resolve2(source);
2113 await assertNoErrors(source); 2163 await computeAnalysisResult(source);
2164 assertNoErrors(source);
2114 verify([source]); 2165 verify([source]);
2115 CompilationUnit unit = resolveCompilationUnit(source, library); 2166 CompilationUnit unit = resolveCompilationUnit(source, library);
2116 FunctionDeclaration function = unit.declarations[0] as FunctionDeclaration; 2167 FunctionDeclaration function = unit.declarations[0] as FunctionDeclaration;
2117 BlockFunctionBody body = 2168 BlockFunctionBody body =
2118 function.functionExpression.body as BlockFunctionBody; 2169 function.functionExpression.body as BlockFunctionBody;
2119 ReturnStatement statement = body.block.statements[1] as ReturnStatement; 2170 ReturnStatement statement = body.block.statements[1] as ReturnStatement;
2120 SimpleIdentifier identifier = statement.expression as SimpleIdentifier; 2171 SimpleIdentifier identifier = statement.expression as SimpleIdentifier;
2121 InterfaceType propagatedType = identifier.propagatedType as InterfaceType; 2172 InterfaceType propagatedType = identifier.propagatedType as InterfaceType;
2122 expect(propagatedType.element, same(typeProvider.mapType.element)); 2173 expect(propagatedType.element, same(typeProvider.mapType.element));
2123 List<DartType> typeArguments = propagatedType.typeArguments; 2174 List<DartType> typeArguments = propagatedType.typeArguments;
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
2229 } 2280 }
2230 } 2281 }
2231 2282
2232 void g() { 2283 void g() {
2233 Base x = null; 2284 Base x = null;
2234 if (x is Derived) { 2285 if (x is Derived) {
2235 print(x.y); // GOOD 2286 print(x.y); // GOOD
2236 } 2287 }
2237 x = null; 2288 x = null;
2238 }'''); 2289 }''');
2239 await assertNoErrors(source); 2290 await computeAnalysisResult(source);
2291 assertNoErrors(source);
2240 } 2292 }
2241 2293
2242 test_objectAccessInference_disabled_for_library_prefix() async { 2294 test_objectAccessInference_disabled_for_library_prefix() async {
2243 String name = 'hashCode'; 2295 String name = 'hashCode';
2244 addNamedSource( 2296 addNamedSource(
2245 '/helper.dart', 2297 '/helper.dart',
2246 ''' 2298 '''
2247 library helper; 2299 library helper;
2248 dynamic get $name => 42; 2300 dynamic get $name => 42;
2249 '''); 2301 ''');
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
2413 var v7 = query('select#id'); 2465 var v7 = query('select#id');
2414 // invocation of method 2466 // invocation of method
2415 var m1 = document.query('div'); 2467 var m1 = document.query('div');
2416 // unsupported currently 2468 // unsupported currently
2417 var b1 = query('noSuchTag'); 2469 var b1 = query('noSuchTag');
2418 var b2 = query('DART_EDITOR_NO_SUCH_TYPE'); 2470 var b2 = query('DART_EDITOR_NO_SUCH_TYPE');
2419 var b3 = query('body div'); 2471 var b3 = query('body div');
2420 return [v1, v2, v3, v4, v5, v6, v7, m1, b1, b2, b3]; 2472 return [v1, v2, v3, v4, v5, v6, v7, m1, b1, b2, b3];
2421 }'''); 2473 }''');
2422 LibraryElement library = resolve2(source); 2474 LibraryElement library = resolve2(source);
2423 await assertNoErrors(source); 2475 await computeAnalysisResult(source);
2476 assertNoErrors(source);
2424 verify([source]); 2477 verify([source]);
2425 CompilationUnit unit = resolveCompilationUnit(source, library); 2478 CompilationUnit unit = resolveCompilationUnit(source, library);
2426 FunctionDeclaration main = unit.declarations[0] as FunctionDeclaration; 2479 FunctionDeclaration main = unit.declarations[0] as FunctionDeclaration;
2427 BlockFunctionBody body = main.functionExpression.body as BlockFunctionBody; 2480 BlockFunctionBody body = main.functionExpression.body as BlockFunctionBody;
2428 ReturnStatement statement = body.block.statements[11] as ReturnStatement; 2481 ReturnStatement statement = body.block.statements[11] as ReturnStatement;
2429 NodeList<Expression> elements = 2482 NodeList<Expression> elements =
2430 (statement.expression as ListLiteral).elements; 2483 (statement.expression as ListLiteral).elements;
2431 expect(resolutionMap.propagatedTypeForExpression(elements[0]).name, 2484 expect(resolutionMap.propagatedTypeForExpression(elements[0]).name,
2432 "AnchorElement"); 2485 "AnchorElement");
2433 expect(resolutionMap.propagatedTypeForExpression(elements[1]).name, 2486 expect(resolutionMap.propagatedTypeForExpression(elements[1]).name,
(...skipping 1223 matching lines...) Expand 10 before | Expand all | Expand 10 after
3657 */ 3710 */
3658 class _StaleElement extends ElementImpl { 3711 class _StaleElement extends ElementImpl {
3659 _StaleElement() : super("_StaleElement", -1); 3712 _StaleElement() : super("_StaleElement", -1);
3660 3713
3661 @override 3714 @override
3662 get kind => throw "_StaleElement's kind shouldn't be accessed"; 3715 get kind => throw "_StaleElement's kind shouldn't be accessed";
3663 3716
3664 @override 3717 @override
3665 /*=T*/ accept/*<T>*/(_) => throw "_StaleElement shouldn't be visited"; 3718 /*=T*/ accept/*<T>*/(_) => throw "_StaleElement shouldn't be visited";
3666 } 3719 }
OLDNEW
« no previous file with comments | « pkg/analyzer/test/generated/non_hint_code_test.dart ('k') | pkg/analyzer/test/generated/resolver_test_case.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698