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

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

Issue 2196363003: Make analyzer strong-mode clean (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 4 years, 4 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) 2016, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2016, 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.strong_mode_test; 5 library analyzer.test.generated.strong_mode_test;
6 6
7 import 'package:analyzer/dart/ast/ast.dart'; 7 import 'package:analyzer/dart/ast/ast.dart';
8 import 'package:analyzer/dart/element/element.dart'; 8 import 'package:analyzer/dart/element/element.dart';
9 import 'package:analyzer/dart/element/type.dart'; 9 import 'package:analyzer/dart/element/type.dart';
10 import 'package:analyzer/src/dart/element/element.dart'; 10 import 'package:analyzer/src/dart/element/element.dart';
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
215 BlockFunctionBody body = test.body; 215 BlockFunctionBody body = test.body;
216 YieldStatement stmt = body.block.statements[0]; 216 YieldStatement stmt = body.block.statements[0];
217 Expression exp = stmt.expression; 217 Expression exp = stmt.expression;
218 typeTest(exp.staticType); 218 typeTest(exp.staticType);
219 } 219 }
220 220
221 check("g0", _isListOf(_isDynamic)); 221 check("g0", _isListOf(_isDynamic));
222 check("g1", _isStreamOf([_isDynamic])); 222 check("g1", _isStreamOf([_isDynamic]));
223 223
224 check("g2", _isListOf(_isInt)); 224 check("g2", _isListOf(_isInt));
225 check("g3", _isStreamOf([_isListOf(_isInt)])); 225 check("g3", _isStreamOf([(DartType type) => _isListOf(_isInt)(type)]));
226 } 226 }
227 227
228 void test_async_star_propagation() { 228 void test_async_star_propagation() {
229 String code = r''' 229 String code = r'''
230 import "dart:async"; 230 import "dart:async";
231 231
232 Stream g0() async* { yield []; } 232 Stream g0() async* { yield []; }
233 Stream g1() async* { yield* new Stream(); } 233 Stream g1() async* { yield* new Stream(); }
234 234
235 Stream<List<int>> g2() async* { yield []; } 235 Stream<List<int>> g2() async* { yield []; }
236 Stream<List<int>> g3() async* { yield* new Stream(); } 236 Stream<List<int>> g3() async* { yield* new Stream(); }
237 '''; 237 ''';
238 CompilationUnit unit = resolveSource(code); 238 CompilationUnit unit = resolveSource(code);
239 239
240 void check(String name, Asserter<InterfaceType> typeTest) { 240 void check(String name, Asserter<InterfaceType> typeTest) {
241 FunctionDeclaration test = AstFinder.getTopLevelFunction(unit, name); 241 FunctionDeclaration test = AstFinder.getTopLevelFunction(unit, name);
242 BlockFunctionBody body = test.functionExpression.body; 242 BlockFunctionBody body = test.functionExpression.body;
243 YieldStatement stmt = body.block.statements[0]; 243 YieldStatement stmt = body.block.statements[0];
244 Expression exp = stmt.expression; 244 Expression exp = stmt.expression;
245 typeTest(exp.staticType); 245 typeTest(exp.staticType);
246 } 246 }
247 247
248 check("g0", _isListOf(_isDynamic)); 248 check("g0", _isListOf(_isDynamic));
249 check("g1", _isStreamOf([_isDynamic])); 249 check("g1", _isStreamOf([_isDynamic]));
250 250
251 check("g2", _isListOf(_isInt)); 251 check("g2", _isListOf(_isInt));
252 check("g3", _isStreamOf([_isListOf(_isInt)])); 252 check("g3", _isStreamOf([(DartType type) => _isListOf(_isInt)(type)]));
253 } 253 }
254 254
255 void test_cascadeExpression() { 255 void test_cascadeExpression() {
256 String code = r''' 256 String code = r'''
257 class A<T> { 257 class A<T> {
258 List<T> map(T a, List<T> mapper(T x)) => mapper(a); 258 List<T> map(T a, List<T> mapper(T x)) => mapper(a);
259 } 259 }
260 260
261 void main () { 261 void main () {
262 A<int> a = new A()..map(0, (x) => [x]); 262 A<int> a = new A()..map(0, (x) => [x]);
(...skipping 428 matching lines...) Expand 10 before | Expand all | Expand 10 after
691 var map = { 42: [] }; 691 var map = { 42: [] };
692 } 692 }
693 class C extends A { 693 class C extends A {
694 get map => { 43: [] }; 694 get map => { 43: [] };
695 } 695 }
696 '''; 696 ''';
697 CompilationUnit unit = resolveSource(code); 697 CompilationUnit unit = resolveSource(code);
698 698
699 Asserter<InterfaceType> assertListOfInt = _isListOf(_isInt); 699 Asserter<InterfaceType> assertListOfInt = _isListOf(_isInt);
700 Asserter<InterfaceType> assertMapOfIntToListOfInt = 700 Asserter<InterfaceType> assertMapOfIntToListOfInt =
701 _isMapOf(_isInt, assertListOfInt); 701 _isMapOf(_isInt, (DartType type) => assertListOfInt(type));
702 702
703 VariableDeclaration mapB = AstFinder.getFieldInClass(unit, "B", "map"); 703 VariableDeclaration mapB = AstFinder.getFieldInClass(unit, "B", "map");
704 MethodDeclaration mapC = AstFinder.getMethodInClass(unit, "C", "map"); 704 MethodDeclaration mapC = AstFinder.getMethodInClass(unit, "C", "map");
705 assertMapOfIntToListOfInt(mapB.element.type); 705 assertMapOfIntToListOfInt(mapB.element.type);
706 assertMapOfIntToListOfInt(mapC.element.returnType); 706 assertMapOfIntToListOfInt(mapC.element.returnType);
707 707
708 MapLiteral mapLiteralB = mapB.initializer; 708 MapLiteral mapLiteralB = mapB.initializer;
709 MapLiteral mapLiteralC = (mapC.body as ExpressionFunctionBody).expression; 709 MapLiteral mapLiteralC = (mapC.body as ExpressionFunctionBody).expression;
710 assertMapOfIntToListOfInt(mapLiteralB.staticType); 710 assertMapOfIntToListOfInt(mapLiteralB.staticType);
711 assertMapOfIntToListOfInt(mapLiteralC.staticType); 711 assertMapOfIntToListOfInt(mapLiteralC.staticType);
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after
948 List<Statement> statements = 948 List<Statement> statements =
949 AstFinder.getStatementsInTopLevelFunction(unit, "main"); 949 AstFinder.getStatementsInTopLevelFunction(unit, "main");
950 ListLiteral literal(int i) { 950 ListLiteral literal(int i) {
951 VariableDeclarationStatement stmt = statements[i]; 951 VariableDeclarationStatement stmt = statements[i];
952 VariableDeclaration decl = stmt.variables.variables[0]; 952 VariableDeclaration decl = stmt.variables.variables[0];
953 ListLiteral exp = decl.initializer; 953 ListLiteral exp = decl.initializer;
954 return exp; 954 return exp;
955 } 955 }
956 956
957 Asserter<InterfaceType> assertListOfInt = _isListOf(_isInt); 957 Asserter<InterfaceType> assertListOfInt = _isListOf(_isInt);
958 Asserter<InterfaceType> assertListOfListOfInt = _isListOf(assertListOfInt); 958 Asserter<InterfaceType> assertListOfListOfInt =
959 _isListOf((DartType type) => assertListOfInt(type));
959 960
960 assertListOfListOfInt(literal(0).staticType); 961 assertListOfListOfInt(literal(0).staticType);
961 assertListOfListOfInt(literal(1).staticType); 962 assertListOfListOfInt(literal(1).staticType);
962 assertListOfListOfInt(literal(2).staticType); 963 assertListOfListOfInt(literal(2).staticType);
963 assertListOfListOfInt(literal(3).staticType); 964 assertListOfListOfInt(literal(3).staticType);
964 965
965 assertListOfInt(literal(1).elements[0].staticType); 966 assertListOfInt(literal(1).elements[0].staticType);
966 assertListOfInt(literal(2).elements[0].staticType); 967 assertListOfInt(literal(2).elements[0].staticType);
967 assertListOfInt(literal(3).elements[0].staticType); 968 assertListOfInt(literal(3).elements[0].staticType);
968 } 969 }
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
1088 AstFinder.getStatementsInTopLevelFunction(unit, "main"); 1089 AstFinder.getStatementsInTopLevelFunction(unit, "main");
1089 MapLiteral literal(int i) { 1090 MapLiteral literal(int i) {
1090 VariableDeclarationStatement stmt = statements[i]; 1091 VariableDeclarationStatement stmt = statements[i];
1091 VariableDeclaration decl = stmt.variables.variables[0]; 1092 VariableDeclaration decl = stmt.variables.variables[0];
1092 MapLiteral exp = decl.initializer; 1093 MapLiteral exp = decl.initializer;
1093 return exp; 1094 return exp;
1094 } 1095 }
1095 1096
1096 Asserter<InterfaceType> assertListOfString = _isListOf(_isString); 1097 Asserter<InterfaceType> assertListOfString = _isListOf(_isString);
1097 Asserter<InterfaceType> assertMapOfIntToListOfString = 1098 Asserter<InterfaceType> assertMapOfIntToListOfString =
1098 _isMapOf(_isInt, assertListOfString); 1099 _isMapOf(_isInt, (DartType type) => assertListOfString(type));
1099 1100
1100 assertMapOfIntToListOfString(literal(0).staticType); 1101 assertMapOfIntToListOfString(literal(0).staticType);
1101 assertMapOfIntToListOfString(literal(1).staticType); 1102 assertMapOfIntToListOfString(literal(1).staticType);
1102 assertMapOfIntToListOfString(literal(2).staticType); 1103 assertMapOfIntToListOfString(literal(2).staticType);
1103 assertMapOfIntToListOfString(literal(3).staticType); 1104 assertMapOfIntToListOfString(literal(3).staticType);
1104 assertMapOfIntToListOfString(literal(4).staticType); 1105 assertMapOfIntToListOfString(literal(4).staticType);
1105 1106
1106 assertListOfString(literal(1).entries[0].value.staticType); 1107 assertListOfString(literal(1).entries[0].value.staticType);
1107 assertListOfString(literal(2).entries[0].value.staticType); 1108 assertListOfString(literal(2).entries[0].value.staticType);
1108 assertListOfString(literal(3).entries[0].value.staticType); 1109 assertListOfString(literal(3).entries[0].value.staticType);
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
1242 BlockFunctionBody body = test.body; 1243 BlockFunctionBody body = test.body;
1243 YieldStatement stmt = body.block.statements[0]; 1244 YieldStatement stmt = body.block.statements[0];
1244 Expression exp = stmt.expression; 1245 Expression exp = stmt.expression;
1245 typeTest(exp.staticType); 1246 typeTest(exp.staticType);
1246 } 1247 }
1247 1248
1248 check("f0", _isListOf(_isDynamic)); 1249 check("f0", _isListOf(_isDynamic));
1249 check("f1", _isListOf(_isDynamic)); 1250 check("f1", _isListOf(_isDynamic));
1250 1251
1251 check("f2", _isListOf(_isInt)); 1252 check("f2", _isListOf(_isInt));
1252 check("f3", _isListOf(_isListOf(_isInt))); 1253 check("f3", _isListOf((DartType type) => _isListOf(_isInt)(type)));
1253 } 1254 }
1254 1255
1255 void test_sync_star_propagation() { 1256 void test_sync_star_propagation() {
1256 String code = r''' 1257 String code = r'''
1257 import "dart:async"; 1258 import "dart:async";
1258 1259
1259 Iterable f0() sync* { yield []; } 1260 Iterable f0() sync* { yield []; }
1260 Iterable f1() sync* { yield* new List(); } 1261 Iterable f1() sync* { yield* new List(); }
1261 1262
1262 Iterable<List<int>> f2() sync* { yield []; } 1263 Iterable<List<int>> f2() sync* { yield []; }
1263 Iterable<List<int>> f3() sync* { yield* new List(); } 1264 Iterable<List<int>> f3() sync* { yield* new List(); }
1264 '''; 1265 ''';
1265 CompilationUnit unit = resolveSource(code); 1266 CompilationUnit unit = resolveSource(code);
1266 1267
1267 void check(String name, Asserter<InterfaceType> typeTest) { 1268 void check(String name, Asserter<InterfaceType> typeTest) {
1268 FunctionDeclaration test = AstFinder.getTopLevelFunction(unit, name); 1269 FunctionDeclaration test = AstFinder.getTopLevelFunction(unit, name);
1269 BlockFunctionBody body = test.functionExpression.body; 1270 BlockFunctionBody body = test.functionExpression.body;
1270 YieldStatement stmt = body.block.statements[0]; 1271 YieldStatement stmt = body.block.statements[0];
1271 Expression exp = stmt.expression; 1272 Expression exp = stmt.expression;
1272 typeTest(exp.staticType); 1273 typeTest(exp.staticType);
1273 } 1274 }
1274 1275
1275 check("f0", _isListOf(_isDynamic)); 1276 check("f0", _isListOf(_isDynamic));
1276 check("f1", _isListOf(_isDynamic)); 1277 check("f1", _isListOf(_isDynamic));
1277 1278
1278 check("f2", _isListOf(_isInt)); 1279 check("f2", _isListOf(_isInt));
1279 check("f3", _isListOf(_isListOf(_isInt))); 1280 check("f3", _isListOf((DartType type) => _isListOf(_isInt)(type)));
1280 } 1281 }
1281 } 1282 }
1282 1283
1283 /** 1284 /**
1284 * Strong mode static analyzer end to end tests 1285 * Strong mode static analyzer end to end tests
1285 */ 1286 */
1286 @reflectiveTest 1287 @reflectiveTest
1287 class StrongModeStaticTypeAnalyzer2Test extends StaticTypeAnalyzer2TestShared { 1288 class StrongModeStaticTypeAnalyzer2Test extends StaticTypeAnalyzer2TestShared {
1288 void fail_genericMethod_tearoff_instantiated() { 1289 void fail_genericMethod_tearoff_instantiated() {
1289 resolveTestUnit(r''' 1290 resolveTestUnit(r'''
(...skipping 1017 matching lines...) Expand 10 before | Expand all | Expand 10 after
2307 main() { 2308 main() {
2308 var v = x; 2309 var v = x;
2309 v; // marker 2310 v; // marker
2310 } 2311 }
2311 int x = 3; 2312 int x = 3;
2312 '''; 2313 ''';
2313 assertPropagatedAssignedType(code, typeProvider.intType, null); 2314 assertPropagatedAssignedType(code, typeProvider.intType, null);
2314 assertTypeOfMarkedExpression(code, typeProvider.intType, null); 2315 assertTypeOfMarkedExpression(code, typeProvider.intType, null);
2315 } 2316 }
2316 } 2317 }
OLDNEW
« no previous file with comments | « pkg/analyzer/test/generated/sdk_test.dart ('k') | pkg/analyzer/test/src/context/builder_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698