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

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

Issue 2643403004: Don't use same(typeProvider.xxx) in resolver_test. (Closed)
Patch Set: Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 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:async'; 7 import 'dart:async';
8 import 'dart:collection'; 8 import 'dart:collection';
9 9
10 import 'package:analyzer/dart/ast/ast.dart'; 10 import 'package:analyzer/dart/ast/ast.dart';
(...skipping 1132 matching lines...) Expand 10 before | Expand all | Expand 10 after
1143 var v; 1143 var v;
1144 v = 0; 1144 v = 0;
1145 return v; 1145 return v;
1146 }'''); 1146 }''');
1147 CompilationUnit unit = await _computeResolvedUnit(source); 1147 CompilationUnit unit = await _computeResolvedUnit(source);
1148 FunctionDeclaration function = unit.declarations[0] as FunctionDeclaration; 1148 FunctionDeclaration function = unit.declarations[0] as FunctionDeclaration;
1149 BlockFunctionBody body = 1149 BlockFunctionBody body =
1150 function.functionExpression.body as BlockFunctionBody; 1150 function.functionExpression.body as BlockFunctionBody;
1151 ReturnStatement statement = body.block.statements[2] as ReturnStatement; 1151 ReturnStatement statement = body.block.statements[2] as ReturnStatement;
1152 SimpleIdentifier variableName = statement.expression as SimpleIdentifier; 1152 SimpleIdentifier variableName = statement.expression as SimpleIdentifier;
1153 expect(variableName.propagatedType, same(typeProvider.intType)); 1153 expect(variableName.propagatedType, typeProvider.intType);
1154 } 1154 }
1155 1155
1156 test_assignment_afterInitializer() async { 1156 test_assignment_afterInitializer() async {
1157 Source source = addSource(r''' 1157 Source source = addSource(r'''
1158 f() { 1158 f() {
1159 var v = 0; 1159 var v = 0;
1160 v = 1.0; 1160 v = 1.0;
1161 return v; 1161 return v;
1162 }'''); 1162 }''');
1163 CompilationUnit unit = await _computeResolvedUnit(source); 1163 CompilationUnit unit = await _computeResolvedUnit(source);
1164 FunctionDeclaration function = unit.declarations[0] as FunctionDeclaration; 1164 FunctionDeclaration function = unit.declarations[0] as FunctionDeclaration;
1165 BlockFunctionBody body = 1165 BlockFunctionBody body =
1166 function.functionExpression.body as BlockFunctionBody; 1166 function.functionExpression.body as BlockFunctionBody;
1167 ReturnStatement statement = body.block.statements[2] as ReturnStatement; 1167 ReturnStatement statement = body.block.statements[2] as ReturnStatement;
1168 SimpleIdentifier variableName = statement.expression as SimpleIdentifier; 1168 SimpleIdentifier variableName = statement.expression as SimpleIdentifier;
1169 expect(variableName.propagatedType, same(typeProvider.doubleType)); 1169 expect(variableName.propagatedType, typeProvider.doubleType);
1170 } 1170 }
1171 1171
1172 test_assignment_null() async { 1172 test_assignment_null() async {
1173 String code = r''' 1173 String code = r'''
1174 main() { 1174 main() {
1175 int v; // declare 1175 int v; // declare
1176 v = null; 1176 v = null;
1177 return v; // return 1177 return v; // return
1178 }'''; 1178 }''';
1179 CompilationUnit unit; 1179 CompilationUnit unit;
1180 { 1180 {
1181 Source source = addSource(code); 1181 Source source = addSource(code);
1182 TestAnalysisResult analysisResult = await computeAnalysisResult(source); 1182 TestAnalysisResult analysisResult = await computeAnalysisResult(source);
1183 assertNoErrors(source); 1183 assertNoErrors(source);
1184 verify([source]); 1184 verify([source]);
1185 unit = analysisResult.unit; 1185 unit = analysisResult.unit;
1186 } 1186 }
1187 { 1187 {
1188 SimpleIdentifier identifier = EngineTestCase.findNode( 1188 SimpleIdentifier identifier = EngineTestCase.findNode(
1189 unit, code, "v; // declare", (node) => node is SimpleIdentifier); 1189 unit, code, "v; // declare", (node) => node is SimpleIdentifier);
1190 expect(identifier.staticType, same(typeProvider.intType)); 1190 expect(identifier.staticType, typeProvider.intType);
1191 expect(identifier.propagatedType, same(null)); 1191 expect(identifier.propagatedType, isNull);
1192 } 1192 }
1193 { 1193 {
1194 SimpleIdentifier identifier = EngineTestCase.findNode( 1194 SimpleIdentifier identifier = EngineTestCase.findNode(
1195 unit, code, "v = null;", (node) => node is SimpleIdentifier); 1195 unit, code, "v = null;", (node) => node is SimpleIdentifier);
1196 expect(identifier.staticType, same(typeProvider.intType)); 1196 expect(identifier.staticType, typeProvider.intType);
1197 expect(identifier.propagatedType, same(null)); 1197 expect(identifier.propagatedType, isNull);
1198 } 1198 }
1199 { 1199 {
1200 SimpleIdentifier identifier = EngineTestCase.findNode( 1200 SimpleIdentifier identifier = EngineTestCase.findNode(
1201 unit, code, "v; // return", (node) => node is SimpleIdentifier); 1201 unit, code, "v; // return", (node) => node is SimpleIdentifier);
1202 expect(identifier.staticType, same(typeProvider.intType)); 1202 expect(identifier.staticType, typeProvider.intType);
1203 expect(identifier.propagatedType, same(null)); 1203 expect(identifier.propagatedType, isNull);
1204 } 1204 }
1205 } 1205 }
1206 1206
1207 test_assignment_throwExpression() async { 1207 test_assignment_throwExpression() async {
1208 Source source = addSource(r''' 1208 Source source = addSource(r'''
1209 f() { 1209 f() {
1210 var v = 1; 1210 var v = 1;
1211 v = throw 2; 1211 v = throw 2;
1212 return v; 1212 return v;
1213 }'''); 1213 }''');
1214 CompilationUnit unit = await _computeResolvedUnit(source, noErrors: false); 1214 CompilationUnit unit = await _computeResolvedUnit(source, noErrors: false);
1215 FunctionDeclaration function = unit.declarations[0] as FunctionDeclaration; 1215 FunctionDeclaration function = unit.declarations[0] as FunctionDeclaration;
1216 BlockFunctionBody body = 1216 BlockFunctionBody body =
1217 function.functionExpression.body as BlockFunctionBody; 1217 function.functionExpression.body as BlockFunctionBody;
1218 ReturnStatement statement = body.block.statements[2] as ReturnStatement; 1218 ReturnStatement statement = body.block.statements[2] as ReturnStatement;
1219 SimpleIdentifier variableName = statement.expression as SimpleIdentifier; 1219 SimpleIdentifier variableName = statement.expression as SimpleIdentifier;
1220 expect(variableName.propagatedType, same(typeProvider.intType)); 1220 expect(variableName.propagatedType, typeProvider.intType);
1221 } 1221 }
1222 1222
1223 test_CanvasElement_getContext() async { 1223 test_CanvasElement_getContext() async {
1224 String code = r''' 1224 String code = r'''
1225 import 'dart:html'; 1225 import 'dart:html';
1226 main(CanvasElement canvas) { 1226 main(CanvasElement canvas) {
1227 var context = canvas.getContext('2d'); 1227 var context = canvas.getContext('2d');
1228 }'''; 1228 }''';
1229 Source source = addSource(code); 1229 Source source = addSource(code);
1230 CompilationUnit unit = await _computeResolvedUnit(source); 1230 CompilationUnit unit = await _computeResolvedUnit(source);
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
1321 } 1321 }
1322 f(MyMap<int, String> m) { 1322 f(MyMap<int, String> m) {
1323 m.forEach((k, v) { 1323 m.forEach((k, v) {
1324 k; 1324 k;
1325 v; 1325 v;
1326 }); 1326 });
1327 }'''; 1327 }''';
1328 Source source = addSource(code); 1328 Source source = addSource(code);
1329 CompilationUnit unit = await _computeResolvedUnit(source); 1329 CompilationUnit unit = await _computeResolvedUnit(source);
1330 // k 1330 // k
1331 DartType intType = typeProvider.intType;
1332 FormalParameter kParameter = EngineTestCase.findNode( 1331 FormalParameter kParameter = EngineTestCase.findNode(
1333 unit, code, "k, ", (node) => node is SimpleFormalParameter); 1332 unit, code, "k, ", (node) => node is SimpleFormalParameter);
1334 expect(kParameter.identifier.propagatedType, same(intType)); 1333 expect(kParameter.identifier.propagatedType, typeProvider.intType);
1335 SimpleIdentifier kIdentifier = EngineTestCase.findNode( 1334 SimpleIdentifier kIdentifier = EngineTestCase.findNode(
1336 unit, code, "k;", (node) => node is SimpleIdentifier); 1335 unit, code, "k;", (node) => node is SimpleIdentifier);
1337 expect(kIdentifier.propagatedType, same(intType)); 1336 expect(kIdentifier.propagatedType, typeProvider.intType);
1338 expect(kIdentifier.staticType, same(typeProvider.dynamicType)); 1337 expect(kIdentifier.staticType, typeProvider.dynamicType);
1339 // v 1338 // v
1340 DartType stringType = typeProvider.stringType;
1341 FormalParameter vParameter = EngineTestCase.findNode( 1339 FormalParameter vParameter = EngineTestCase.findNode(
1342 unit, code, "v)", (node) => node is SimpleFormalParameter); 1340 unit, code, "v)", (node) => node is SimpleFormalParameter);
1343 expect(vParameter.identifier.propagatedType, same(stringType)); 1341 expect(vParameter.identifier.propagatedType, typeProvider.stringType);
1344 SimpleIdentifier vIdentifier = EngineTestCase.findNode( 1342 SimpleIdentifier vIdentifier = EngineTestCase.findNode(
1345 unit, code, "v;", (node) => node is SimpleIdentifier); 1343 unit, code, "v;", (node) => node is SimpleIdentifier);
1346 expect(vIdentifier.propagatedType, same(stringType)); 1344 expect(vIdentifier.propagatedType, typeProvider.stringType);
1347 expect(vIdentifier.staticType, same(typeProvider.dynamicType)); 1345 expect(vIdentifier.staticType, typeProvider.dynamicType);
1348 } 1346 }
1349 1347
1350 test_functionExpression_asInvocationArgument_fromInferredInvocation() async { 1348 test_functionExpression_asInvocationArgument_fromInferredInvocation() async {
1351 String code = r''' 1349 String code = r'''
1352 class MyMap<K, V> { 1350 class MyMap<K, V> {
1353 forEach(f(K key, V value)) {} 1351 forEach(f(K key, V value)) {}
1354 } 1352 }
1355 f(MyMap<int, String> m) { 1353 f(MyMap<int, String> m) {
1356 var m2 = m; 1354 var m2 = m;
1357 m2.forEach((k, v) {}); 1355 m2.forEach((k, v) {});
1358 }'''; 1356 }''';
1359 Source source = addSource(code); 1357 Source source = addSource(code);
1360 CompilationUnit unit = await _computeResolvedUnit(source); 1358 CompilationUnit unit = await _computeResolvedUnit(source);
1361 // k 1359 // k
1362 DartType intType = typeProvider.intType;
1363 FormalParameter kParameter = EngineTestCase.findNode( 1360 FormalParameter kParameter = EngineTestCase.findNode(
1364 unit, code, "k, ", (node) => node is SimpleFormalParameter); 1361 unit, code, "k, ", (node) => node is SimpleFormalParameter);
1365 expect(kParameter.identifier.propagatedType, same(intType)); 1362 expect(kParameter.identifier.propagatedType, typeProvider.intType);
1366 // v 1363 // v
1367 DartType stringType = typeProvider.stringType;
1368 FormalParameter vParameter = EngineTestCase.findNode( 1364 FormalParameter vParameter = EngineTestCase.findNode(
1369 unit, code, "v)", (node) => node is SimpleFormalParameter); 1365 unit, code, "v)", (node) => node is SimpleFormalParameter);
1370 expect(vParameter.identifier.propagatedType, same(stringType)); 1366 expect(vParameter.identifier.propagatedType, typeProvider.stringType);
1371 } 1367 }
1372 1368
1373 test_functionExpression_asInvocationArgument_functionExpressionInvocation() as ync { 1369 test_functionExpression_asInvocationArgument_functionExpressionInvocation() as ync {
1374 String code = r''' 1370 String code = r'''
1375 main() { 1371 main() {
1376 (f(String value)) {} ((v) { 1372 (f(String value)) {} ((v) {
1377 v; 1373 v;
1378 }); 1374 });
1379 }'''; 1375 }''';
1380 Source source = addSource(code); 1376 Source source = addSource(code);
1381 CompilationUnit unit = await _computeResolvedUnit(source); 1377 CompilationUnit unit = await _computeResolvedUnit(source);
1382 // v 1378 // v
1383 DartType dynamicType = typeProvider.dynamicType;
1384 DartType stringType = typeProvider.stringType;
1385 FormalParameter vParameter = EngineTestCase.findNode( 1379 FormalParameter vParameter = EngineTestCase.findNode(
1386 unit, code, "v)", (node) => node is FormalParameter); 1380 unit, code, "v)", (node) => node is FormalParameter);
1387 expect(vParameter.identifier.propagatedType, same(stringType)); 1381 expect(vParameter.identifier.propagatedType, typeProvider.stringType);
1388 expect(vParameter.identifier.staticType, same(dynamicType)); 1382 expect(vParameter.identifier.staticType, typeProvider.dynamicType);
1389 SimpleIdentifier vIdentifier = EngineTestCase.findNode( 1383 SimpleIdentifier vIdentifier = EngineTestCase.findNode(
1390 unit, code, "v;", (node) => node is SimpleIdentifier); 1384 unit, code, "v;", (node) => node is SimpleIdentifier);
1391 expect(vIdentifier.propagatedType, same(stringType)); 1385 expect(vIdentifier.propagatedType, typeProvider.stringType);
1392 expect(vIdentifier.staticType, same(dynamicType)); 1386 expect(vIdentifier.staticType, typeProvider.dynamicType);
1393 } 1387 }
1394 1388
1395 test_functionExpression_asInvocationArgument_keepIfLessSpecific() async { 1389 test_functionExpression_asInvocationArgument_keepIfLessSpecific() async {
1396 String code = r''' 1390 String code = r'''
1397 class MyList { 1391 class MyList {
1398 forEach(f(Object value)) {} 1392 forEach(f(Object value)) {}
1399 } 1393 }
1400 f(MyList list) { 1394 f(MyList list) {
1401 list.forEach((int v) { 1395 list.forEach((int v) {
1402 v; 1396 v;
1403 }); 1397 });
1404 }'''; 1398 }''';
1405 Source source = addSource(code); 1399 Source source = addSource(code);
1406 CompilationUnit unit = await _computeResolvedUnit(source); 1400 CompilationUnit unit = await _computeResolvedUnit(source);
1407 // v 1401 // v
1408 DartType intType = typeProvider.intType;
1409 FormalParameter vParameter = EngineTestCase.findNode( 1402 FormalParameter vParameter = EngineTestCase.findNode(
1410 unit, code, "v)", (node) => node is SimpleFormalParameter); 1403 unit, code, "v)", (node) => node is SimpleFormalParameter);
1411 expect(vParameter.identifier.propagatedType, same(null)); 1404 expect(vParameter.identifier.propagatedType, isNull);
1412 expect(vParameter.identifier.staticType, same(intType)); 1405 expect(vParameter.identifier.staticType, typeProvider.intType);
1413 SimpleIdentifier vIdentifier = EngineTestCase.findNode( 1406 SimpleIdentifier vIdentifier = EngineTestCase.findNode(
1414 unit, code, "v;", (node) => node is SimpleIdentifier); 1407 unit, code, "v;", (node) => node is SimpleIdentifier);
1415 expect(vIdentifier.staticType, same(intType)); 1408 expect(vIdentifier.staticType, typeProvider.intType);
1416 expect(vIdentifier.propagatedType, same(null)); 1409 expect(vIdentifier.propagatedType, isNull);
1417 } 1410 }
1418 1411
1419 test_functionExpression_asInvocationArgument_notSubtypeOfStaticType() async { 1412 test_functionExpression_asInvocationArgument_notSubtypeOfStaticType() async {
1420 String code = r''' 1413 String code = r'''
1421 class A { 1414 class A {
1422 m(void f(int i)) {} 1415 m(void f(int i)) {}
1423 } 1416 }
1424 x() { 1417 x() {
1425 A a = new A(); 1418 A a = new A();
1426 a.m(() => 0); 1419 a.m(() => 0);
1427 }'''; 1420 }''';
1428 Source source = addSource(code); 1421 Source source = addSource(code);
1429 CompilationUnit unit = await _computeResolvedUnit(source, noErrors: false); 1422 CompilationUnit unit = await _computeResolvedUnit(source, noErrors: false);
1430 assertErrors(source, [StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE]); 1423 assertErrors(source, [StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE]);
1431 // () => 0 1424 // () => 0
1432 FunctionExpression functionExpression = EngineTestCase.findNode( 1425 FunctionExpression functionExpression = EngineTestCase.findNode(
1433 unit, code, "() => 0)", (node) => node is FunctionExpression); 1426 unit, code, "() => 0)", (node) => node is FunctionExpression);
1434 expect((functionExpression.staticType as FunctionType).parameters.length, 1427 expect((functionExpression.staticType as FunctionType).parameters.length,
1435 same(0)); 1428 same(0));
1436 expect(functionExpression.propagatedType, same(null)); 1429 expect(functionExpression.propagatedType, isNull);
1437 } 1430 }
1438 1431
1439 test_functionExpression_asInvocationArgument_replaceIfMoreSpecific() async { 1432 test_functionExpression_asInvocationArgument_replaceIfMoreSpecific() async {
1440 String code = r''' 1433 String code = r'''
1441 class MyList<E> { 1434 class MyList<E> {
1442 forEach(f(E value)) {} 1435 forEach(f(E value)) {}
1443 } 1436 }
1444 f(MyList<String> list) { 1437 f(MyList<String> list) {
1445 list.forEach((Object v) { 1438 list.forEach((Object v) {
1446 v; 1439 v;
1447 }); 1440 });
1448 }'''; 1441 }''';
1449 Source source = addSource(code); 1442 Source source = addSource(code);
1450 CompilationUnit unit = await _computeResolvedUnit(source); 1443 CompilationUnit unit = await _computeResolvedUnit(source);
1451 // v 1444 // v
1452 DartType stringType = typeProvider.stringType;
1453 FormalParameter vParameter = EngineTestCase.findNode( 1445 FormalParameter vParameter = EngineTestCase.findNode(
1454 unit, code, "v)", (node) => node is SimpleFormalParameter); 1446 unit, code, "v)", (node) => node is SimpleFormalParameter);
1455 expect(vParameter.identifier.propagatedType, same(stringType)); 1447 expect(vParameter.identifier.propagatedType, typeProvider.stringType);
1456 expect(vParameter.identifier.staticType, same(typeProvider.objectType)); 1448 expect(vParameter.identifier.staticType, typeProvider.objectType);
1457 SimpleIdentifier vIdentifier = EngineTestCase.findNode( 1449 SimpleIdentifier vIdentifier = EngineTestCase.findNode(
1458 unit, code, "v;", (node) => node is SimpleIdentifier); 1450 unit, code, "v;", (node) => node is SimpleIdentifier);
1459 expect(vIdentifier.propagatedType, same(stringType)); 1451 expect(vIdentifier.propagatedType, typeProvider.stringType);
1460 } 1452 }
1461 1453
1462 test_Future_then() async { 1454 test_Future_then() async {
1463 String code = r''' 1455 String code = r'''
1464 import 'dart:async'; 1456 import 'dart:async';
1465 main(Future<int> firstFuture) { 1457 main(Future<int> firstFuture) {
1466 firstFuture.then((p1) { 1458 firstFuture.then((p1) {
1467 return 1.0; 1459 return 1.0;
1468 }).then((p2) { 1460 }).then((p2) {
1469 return new Future<String>.value('str'); 1461 return new Future<String>.value('str');
1470 }).then((p3) { 1462 }).then((p3) {
1471 }); 1463 });
1472 }'''; 1464 }''';
1473 Source source = addSource(code); 1465 Source source = addSource(code);
1474 CompilationUnit unit = await _computeResolvedUnit(source); 1466 CompilationUnit unit = await _computeResolvedUnit(source);
1475 // p1 1467 // p1
1476 FormalParameter p1 = EngineTestCase.findNode( 1468 FormalParameter p1 = EngineTestCase.findNode(
1477 unit, code, "p1) {", (node) => node is SimpleFormalParameter); 1469 unit, code, "p1) {", (node) => node is SimpleFormalParameter);
1478 expect(p1.identifier.propagatedType, same(typeProvider.intType)); 1470 expect(p1.identifier.propagatedType, typeProvider.intType);
1479 // p2 1471 // p2
1480 FormalParameter p2 = EngineTestCase.findNode( 1472 FormalParameter p2 = EngineTestCase.findNode(
1481 unit, code, "p2) {", (node) => node is SimpleFormalParameter); 1473 unit, code, "p2) {", (node) => node is SimpleFormalParameter);
1482 expect(p2.identifier.propagatedType, same(typeProvider.doubleType)); 1474 expect(p2.identifier.propagatedType, typeProvider.doubleType);
1483 // p3 1475 // p3
1484 FormalParameter p3 = EngineTestCase.findNode( 1476 FormalParameter p3 = EngineTestCase.findNode(
1485 unit, code, "p3) {", (node) => node is SimpleFormalParameter); 1477 unit, code, "p3) {", (node) => node is SimpleFormalParameter);
1486 expect(p3.identifier.propagatedType, same(typeProvider.stringType)); 1478 expect(p3.identifier.propagatedType, typeProvider.stringType);
1487 } 1479 }
1488 1480
1489 test_initializer() async { 1481 test_initializer() async {
1490 Source source = addSource(r''' 1482 Source source = addSource(r'''
1491 f() { 1483 f() {
1492 var v = 0; 1484 var v = 0;
1493 return v; 1485 return v;
1494 }'''); 1486 }''');
1495 CompilationUnit unit = await _computeResolvedUnit(source); 1487 CompilationUnit unit = await _computeResolvedUnit(source);
1496 FunctionDeclaration function = unit.declarations[0] as FunctionDeclaration; 1488 FunctionDeclaration function = unit.declarations[0] as FunctionDeclaration;
1497 BlockFunctionBody body = 1489 BlockFunctionBody body =
1498 function.functionExpression.body as BlockFunctionBody; 1490 function.functionExpression.body as BlockFunctionBody;
1499 NodeList<Statement> statements = body.block.statements; 1491 NodeList<Statement> statements = body.block.statements;
1500 // Type of 'v' in declaration. 1492 // Type of 'v' in declaration.
1501 { 1493 {
1502 VariableDeclarationStatement statement = 1494 VariableDeclarationStatement statement =
1503 statements[0] as VariableDeclarationStatement; 1495 statements[0] as VariableDeclarationStatement;
1504 SimpleIdentifier variableName = statement.variables.variables[0].name; 1496 SimpleIdentifier variableName = statement.variables.variables[0].name;
1505 expect(variableName.staticType, same(typeProvider.dynamicType)); 1497 expect(variableName.staticType, typeProvider.dynamicType);
1506 expect(variableName.propagatedType, same(typeProvider.intType)); 1498 expect(variableName.propagatedType, typeProvider.intType);
1507 } 1499 }
1508 // Type of 'v' in reference. 1500 // Type of 'v' in reference.
1509 { 1501 {
1510 ReturnStatement statement = statements[1] as ReturnStatement; 1502 ReturnStatement statement = statements[1] as ReturnStatement;
1511 SimpleIdentifier variableName = statement.expression as SimpleIdentifier; 1503 SimpleIdentifier variableName = statement.expression as SimpleIdentifier;
1512 expect(variableName.propagatedType, same(typeProvider.intType)); 1504 expect(variableName.propagatedType, typeProvider.intType);
1513 } 1505 }
1514 } 1506 }
1515 1507
1516 test_initializer_dereference() async { 1508 test_initializer_dereference() async {
1517 Source source = addSource(r''' 1509 Source source = addSource(r'''
1518 f() { 1510 f() {
1519 var v = 'String'; 1511 var v = 'String';
1520 v. 1512 v.
1521 }'''); 1513 }''');
1522 CompilationUnit unit = await _computeResolvedUnit(source, noErrors: false); 1514 CompilationUnit unit = await _computeResolvedUnit(source, noErrors: false);
1523 FunctionDeclaration function = unit.declarations[0] as FunctionDeclaration; 1515 FunctionDeclaration function = unit.declarations[0] as FunctionDeclaration;
1524 BlockFunctionBody body = 1516 BlockFunctionBody body =
1525 function.functionExpression.body as BlockFunctionBody; 1517 function.functionExpression.body as BlockFunctionBody;
1526 ExpressionStatement statement = 1518 ExpressionStatement statement =
1527 body.block.statements[1] as ExpressionStatement; 1519 body.block.statements[1] as ExpressionStatement;
1528 PrefixedIdentifier invocation = statement.expression as PrefixedIdentifier; 1520 PrefixedIdentifier invocation = statement.expression as PrefixedIdentifier;
1529 SimpleIdentifier variableName = invocation.prefix; 1521 SimpleIdentifier variableName = invocation.prefix;
1530 expect(variableName.propagatedType, same(typeProvider.stringType)); 1522 expect(variableName.propagatedType, typeProvider.stringType);
1531 } 1523 }
1532 1524
1533 test_initializer_hasStaticType() async { 1525 test_initializer_hasStaticType() async {
1534 Source source = addSource(r''' 1526 Source source = addSource(r'''
1535 f() { 1527 f() {
1536 int v = 0; 1528 int v = 0;
1537 return v; 1529 return v;
1538 }'''); 1530 }''');
1539 CompilationUnit unit = await _computeResolvedUnit(source); 1531 CompilationUnit unit = await _computeResolvedUnit(source);
1540 FunctionDeclaration function = unit.declarations[0] as FunctionDeclaration; 1532 FunctionDeclaration function = unit.declarations[0] as FunctionDeclaration;
1541 BlockFunctionBody body = 1533 BlockFunctionBody body =
1542 function.functionExpression.body as BlockFunctionBody; 1534 function.functionExpression.body as BlockFunctionBody;
1543 NodeList<Statement> statements = body.block.statements; 1535 NodeList<Statement> statements = body.block.statements;
1544 // Type of 'v' in declaration. 1536 // Type of 'v' in declaration.
1545 { 1537 {
1546 VariableDeclarationStatement statement = 1538 VariableDeclarationStatement statement =
1547 statements[0] as VariableDeclarationStatement; 1539 statements[0] as VariableDeclarationStatement;
1548 SimpleIdentifier variableName = statement.variables.variables[0].name; 1540 SimpleIdentifier variableName = statement.variables.variables[0].name;
1549 expect(variableName.staticType, same(typeProvider.intType)); 1541 expect(variableName.staticType, typeProvider.intType);
1550 expect(variableName.propagatedType, isNull); 1542 expect(variableName.propagatedType, isNull);
1551 } 1543 }
1552 // Type of 'v' in reference. 1544 // Type of 'v' in reference.
1553 { 1545 {
1554 ReturnStatement statement = statements[1] as ReturnStatement; 1546 ReturnStatement statement = statements[1] as ReturnStatement;
1555 SimpleIdentifier variableName = statement.expression as SimpleIdentifier; 1547 SimpleIdentifier variableName = statement.expression as SimpleIdentifier;
1556 expect(variableName.staticType, same(typeProvider.intType)); 1548 expect(variableName.staticType, typeProvider.intType);
1557 expect(variableName.propagatedType, isNull); 1549 expect(variableName.propagatedType, isNull);
1558 } 1550 }
1559 } 1551 }
1560 1552
1561 test_initializer_hasStaticType_parameterized() async { 1553 test_initializer_hasStaticType_parameterized() async {
1562 Source source = addSource(r''' 1554 Source source = addSource(r'''
1563 f() { 1555 f() {
1564 List<int> v = <int>[]; 1556 List<int> v = <int>[];
1565 return v; 1557 return v;
1566 }'''); 1558 }''');
(...skipping 26 matching lines...) Expand all
1593 return v; // marker 1585 return v; // marker
1594 }'''; 1586 }''';
1595 CompilationUnit unit; 1587 CompilationUnit unit;
1596 { 1588 {
1597 Source source = addSource(code); 1589 Source source = addSource(code);
1598 unit = await _computeResolvedUnit(source); 1590 unit = await _computeResolvedUnit(source);
1599 } 1591 }
1600 { 1592 {
1601 SimpleIdentifier identifier = EngineTestCase.findNode( 1593 SimpleIdentifier identifier = EngineTestCase.findNode(
1602 unit, code, "v = null;", (node) => node is SimpleIdentifier); 1594 unit, code, "v = null;", (node) => node is SimpleIdentifier);
1603 expect(identifier.staticType, same(typeProvider.intType)); 1595 expect(identifier.staticType, typeProvider.intType);
1604 expect(identifier.propagatedType, same(null)); 1596 expect(identifier.propagatedType, isNull);
1605 } 1597 }
1606 { 1598 {
1607 SimpleIdentifier identifier = EngineTestCase.findNode( 1599 SimpleIdentifier identifier = EngineTestCase.findNode(
1608 unit, code, "v; // marker", (node) => node is SimpleIdentifier); 1600 unit, code, "v; // marker", (node) => node is SimpleIdentifier);
1609 expect(identifier.staticType, same(typeProvider.intType)); 1601 expect(identifier.staticType, typeProvider.intType);
1610 expect(identifier.propagatedType, same(null)); 1602 expect(identifier.propagatedType, isNull);
1611 } 1603 }
1612 } 1604 }
1613 1605
1614 test_initializer_throwExpression() async { 1606 test_initializer_throwExpression() async {
1615 Source source = addSource(r''' 1607 Source source = addSource(r'''
1616 f() { 1608 f() {
1617 var v = throw 2; 1609 var v = throw 2;
1618 return v; 1610 return v;
1619 }'''); 1611 }''');
1620 CompilationUnit unit = await _computeResolvedUnit(source, noErrors: false); 1612 CompilationUnit unit = await _computeResolvedUnit(source, noErrors: false);
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
1714 } 1706 }
1715 }'''); 1707 }''');
1716 CompilationUnit unit = await _computeResolvedUnit(source); 1708 CompilationUnit unit = await _computeResolvedUnit(source);
1717 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration; 1709 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration;
1718 BlockFunctionBody body = 1710 BlockFunctionBody body =
1719 function.functionExpression.body as BlockFunctionBody; 1711 function.functionExpression.body as BlockFunctionBody;
1720 IfStatement ifStatement = body.block.statements[0] as IfStatement; 1712 IfStatement ifStatement = body.block.statements[0] as IfStatement;
1721 ReturnStatement statement = 1713 ReturnStatement statement =
1722 (ifStatement.thenStatement as Block).statements[0] as ReturnStatement; 1714 (ifStatement.thenStatement as Block).statements[0] as ReturnStatement;
1723 SimpleIdentifier variableName = statement.expression as SimpleIdentifier; 1715 SimpleIdentifier variableName = statement.expression as SimpleIdentifier;
1724 expect(variableName.propagatedType, same(null)); 1716 expect(variableName.propagatedType, isNull);
1725 } 1717 }
1726 1718
1727 test_is_if_logicalAnd() async { 1719 test_is_if_logicalAnd() async {
1728 Source source = addSource(r''' 1720 Source source = addSource(r'''
1729 class A {} 1721 class A {}
1730 A f(var p) { 1722 A f(var p) {
1731 if (p is A && p != null) { 1723 if (p is A && p != null) {
1732 return p; 1724 return p;
1733 } else { 1725 } else {
1734 return null; 1726 return null;
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after
2023 }'''); 2015 }''');
2024 CompilationUnit unit = await _computeResolvedUnit(source); 2016 CompilationUnit unit = await _computeResolvedUnit(source);
2025 FunctionDeclaration function = unit.declarations[0] as FunctionDeclaration; 2017 FunctionDeclaration function = unit.declarations[0] as FunctionDeclaration;
2026 BlockFunctionBody body = 2018 BlockFunctionBody body =
2027 function.functionExpression.body as BlockFunctionBody; 2019 function.functionExpression.body as BlockFunctionBody;
2028 ReturnStatement statement = body.block.statements[1] as ReturnStatement; 2020 ReturnStatement statement = body.block.statements[1] as ReturnStatement;
2029 IndexExpression indexExpression = statement.expression as IndexExpression; 2021 IndexExpression indexExpression = statement.expression as IndexExpression;
2030 expect(indexExpression.propagatedType, isNull); 2022 expect(indexExpression.propagatedType, isNull);
2031 Expression v = indexExpression.target; 2023 Expression v = indexExpression.target;
2032 InterfaceType propagatedType = v.propagatedType as InterfaceType; 2024 InterfaceType propagatedType = v.propagatedType as InterfaceType;
2033 expect(propagatedType.element, same(typeProvider.listType.element)); 2025 expect(propagatedType.element, typeProvider.listType.element);
2034 List<DartType> typeArguments = propagatedType.typeArguments; 2026 List<DartType> typeArguments = propagatedType.typeArguments;
2035 expect(typeArguments, hasLength(1)); 2027 expect(typeArguments, hasLength(1));
2036 expect(typeArguments[0], same(typeProvider.dynamicType)); 2028 expect(typeArguments[0], typeProvider.dynamicType);
2037 } 2029 }
2038 2030
2039 test_mapLiteral_different() async { 2031 test_mapLiteral_different() async {
2040 Source source = addSource(r''' 2032 Source source = addSource(r'''
2041 f() { 2033 f() {
2042 var v = {'0' : 0, 1 : '1', '2' : 2}; 2034 var v = {'0' : 0, 1 : '1', '2' : 2};
2043 return v; 2035 return v;
2044 }'''); 2036 }''');
2045 CompilationUnit unit = await _computeResolvedUnit(source); 2037 CompilationUnit unit = await _computeResolvedUnit(source);
2046 FunctionDeclaration function = unit.declarations[0] as FunctionDeclaration; 2038 FunctionDeclaration function = unit.declarations[0] as FunctionDeclaration;
2047 BlockFunctionBody body = 2039 BlockFunctionBody body =
2048 function.functionExpression.body as BlockFunctionBody; 2040 function.functionExpression.body as BlockFunctionBody;
2049 ReturnStatement statement = body.block.statements[1] as ReturnStatement; 2041 ReturnStatement statement = body.block.statements[1] as ReturnStatement;
2050 SimpleIdentifier identifier = statement.expression as SimpleIdentifier; 2042 SimpleIdentifier identifier = statement.expression as SimpleIdentifier;
2051 InterfaceType propagatedType = identifier.propagatedType as InterfaceType; 2043 InterfaceType propagatedType = identifier.propagatedType as InterfaceType;
2052 expect(propagatedType.element, same(typeProvider.mapType.element)); 2044 expect(propagatedType.element, typeProvider.mapType.element);
2053 List<DartType> typeArguments = propagatedType.typeArguments; 2045 List<DartType> typeArguments = propagatedType.typeArguments;
2054 expect(typeArguments, hasLength(2)); 2046 expect(typeArguments, hasLength(2));
2055 expect(typeArguments[0], same(typeProvider.dynamicType)); 2047 expect(typeArguments[0], typeProvider.dynamicType);
2056 expect(typeArguments[1], same(typeProvider.dynamicType)); 2048 expect(typeArguments[1], typeProvider.dynamicType);
2057 } 2049 }
2058 2050
2059 test_mapLiteral_same() async { 2051 test_mapLiteral_same() async {
2060 Source source = addSource(r''' 2052 Source source = addSource(r'''
2061 f() { 2053 f() {
2062 var v = {'a' : 0, 'b' : 1, 'c' : 2}; 2054 var v = {'a' : 0, 'b' : 1, 'c' : 2};
2063 return v; 2055 return v;
2064 }'''); 2056 }''');
2065 CompilationUnit unit = await _computeResolvedUnit(source); 2057 CompilationUnit unit = await _computeResolvedUnit(source);
2066 FunctionDeclaration function = unit.declarations[0] as FunctionDeclaration; 2058 FunctionDeclaration function = unit.declarations[0] as FunctionDeclaration;
2067 BlockFunctionBody body = 2059 BlockFunctionBody body =
2068 function.functionExpression.body as BlockFunctionBody; 2060 function.functionExpression.body as BlockFunctionBody;
2069 ReturnStatement statement = body.block.statements[1] as ReturnStatement; 2061 ReturnStatement statement = body.block.statements[1] as ReturnStatement;
2070 SimpleIdentifier identifier = statement.expression as SimpleIdentifier; 2062 SimpleIdentifier identifier = statement.expression as SimpleIdentifier;
2071 InterfaceType propagatedType = identifier.propagatedType as InterfaceType; 2063 InterfaceType propagatedType = identifier.propagatedType as InterfaceType;
2072 expect(propagatedType.element, same(typeProvider.mapType.element)); 2064 expect(propagatedType.element, typeProvider.mapType.element);
2073 List<DartType> typeArguments = propagatedType.typeArguments; 2065 List<DartType> typeArguments = propagatedType.typeArguments;
2074 expect(typeArguments, hasLength(2)); 2066 expect(typeArguments, hasLength(2));
2075 expect(typeArguments[0], same(typeProvider.dynamicType)); 2067 expect(typeArguments[0], typeProvider.dynamicType);
2076 expect(typeArguments[1], same(typeProvider.dynamicType)); 2068 expect(typeArguments[1], typeProvider.dynamicType);
2077 } 2069 }
2078 2070
2079 test_mergePropagatedTypes_afterIfThen_different() async { 2071 test_mergePropagatedTypes_afterIfThen_different() async {
2080 String code = r''' 2072 String code = r'''
2081 main() { 2073 main() {
2082 var v = 0; 2074 var v = 0;
2083 if (v != null) { 2075 if (v != null) {
2084 v = ''; 2076 v = '';
2085 } 2077 }
2086 return v; 2078 return v;
(...skipping 1533 matching lines...) Expand 10 before | Expand all | Expand 10 after
3620 */ 3612 */
3621 class _StaleElement extends ElementImpl { 3613 class _StaleElement extends ElementImpl {
3622 _StaleElement() : super("_StaleElement", -1); 3614 _StaleElement() : super("_StaleElement", -1);
3623 3615
3624 @override 3616 @override
3625 get kind => throw "_StaleElement's kind shouldn't be accessed"; 3617 get kind => throw "_StaleElement's kind shouldn't be accessed";
3626 3618
3627 @override 3619 @override
3628 /*=T*/ accept/*<T>*/(_) => throw "_StaleElement shouldn't be visited"; 3620 /*=T*/ accept/*<T>*/(_) => throw "_StaleElement shouldn't be visited";
3629 } 3621 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698