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

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

Issue 1268733004: Propagate a type in asynchronous for-in statements (issue 23945) (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 5 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
« no previous file with comments | « pkg/analyzer/lib/src/generated/testing/element_factory.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 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 engine.resolver_test; 5 library engine.resolver_test;
6 6
7 import 'dart:collection'; 7 import 'dart:collection';
8 8
9 import 'package:analyzer/src/context/context.dart' as newContext; 9 import 'package:analyzer/src/context/context.dart' as newContext;
10 import 'package:analyzer/src/generated/ast.dart'; 10 import 'package:analyzer/src/generated/ast.dart';
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 <ClassElement>[objectClassElement, objectClassElement], null), 158 <ClassElement>[objectClassElement, objectClassElement], null),
159 ElementFactory.functionElement3("print", VoidTypeImpl.instance.element, 159 ElementFactory.functionElement3("print", VoidTypeImpl.instance.element,
160 <ClassElement>[objectClassElement], null) 160 <ClassElement>[objectClassElement], null)
161 ]; 161 ];
162 TopLevelVariableElement proxyTopLevelVariableElt = ElementFactory 162 TopLevelVariableElement proxyTopLevelVariableElt = ElementFactory
163 .topLevelVariableElement3("proxy", true, false, proxyClassElement.type); 163 .topLevelVariableElement3("proxy", true, false, proxyClassElement.type);
164 ConstTopLevelVariableElementImpl deprecatedTopLevelVariableElt = 164 ConstTopLevelVariableElementImpl deprecatedTopLevelVariableElt =
165 ElementFactory.topLevelVariableElement3( 165 ElementFactory.topLevelVariableElement3(
166 "deprecated", true, false, provider.deprecatedType); 166 "deprecated", true, false, provider.deprecatedType);
167 deprecatedTopLevelVariableElt.constantInitializer = AstFactory 167 deprecatedTopLevelVariableElt.constantInitializer = AstFactory
168 .instanceCreationExpression2(Keyword.CONST, 168 .instanceCreationExpression2(
169 Keyword.CONST,
169 AstFactory.typeName(provider.deprecatedType.element), 170 AstFactory.typeName(provider.deprecatedType.element),
170 [AstFactory.string2('next release')]); 171 [AstFactory.string2('next release')]);
171 coreUnit.accessors = <PropertyAccessorElement>[ 172 coreUnit.accessors = <PropertyAccessorElement>[
172 proxyTopLevelVariableElt.getter, 173 proxyTopLevelVariableElt.getter,
173 deprecatedTopLevelVariableElt.getter 174 deprecatedTopLevelVariableElt.getter
174 ]; 175 ];
175 coreUnit.topLevelVariables = <TopLevelVariableElement>[ 176 coreUnit.topLevelVariables = <TopLevelVariableElement>[
176 proxyTopLevelVariableElt, 177 proxyTopLevelVariableElt,
177 deprecatedTopLevelVariableElt 178 deprecatedTopLevelVariableElt
178 ]; 179 ];
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 ]); 223 ]);
223 futureElement.methods = <MethodElement>[thenMethod]; 224 futureElement.methods = <MethodElement>[thenMethod];
224 // Completer 225 // Completer
225 ClassElementImpl completerElement = 226 ClassElementImpl completerElement =
226 ElementFactory.classElement2("Completer", ["T"]); 227 ElementFactory.classElement2("Completer", ["T"]);
227 ConstructorElementImpl completerConstructor = 228 ConstructorElementImpl completerConstructor =
228 ElementFactory.constructorElement2(completerElement, null); 229 ElementFactory.constructorElement2(completerElement, null);
229 (completerConstructor.type as FunctionTypeImpl).typeArguments = 230 (completerConstructor.type as FunctionTypeImpl).typeArguments =
230 completerElement.type.typeArguments; 231 completerElement.type.typeArguments;
231 completerElement.constructors = <ConstructorElement>[completerConstructor]; 232 completerElement.constructors = <ConstructorElement>[completerConstructor];
233 // StreamSubscription
234 ClassElementImpl streamSubscriptionElement =
235 ElementFactory.classElement2("StreamSubscription", ["T"]);
236 // Stream
237 ClassElementImpl streamElement =
238 ElementFactory.classElement2("Stream", ["T"]);
239 DartType returnType = streamSubscriptionElement.type
240 .substitute4(streamElement.type.typeArguments);
241 List<DartType> parameterTypes = <DartType>[
242 ElementFactory
243 .functionElement3('onData', VoidTypeImpl.instance.element,
244 <TypeDefiningElement>[streamElement.typeParameters[0]], null)
245 .type,
246 ];
247 // TODO(brianwilkerson) This is missing the optional parameters.
248 MethodElementImpl listenMethod =
249 ElementFactory.methodElement('listen', returnType, parameterTypes);
250 streamElement.methods = <MethodElement>[listenMethod];
251
232 asyncUnit.types = <ClassElement>[ 252 asyncUnit.types = <ClassElement>[
233 completerElement, 253 completerElement,
234 futureElement, 254 futureElement,
235 ElementFactory.classElement2("Stream", ["T"]) 255 streamElement
236 ]; 256 ];
237 LibraryElementImpl asyncLibrary = new LibraryElementImpl.forNode( 257 LibraryElementImpl asyncLibrary = new LibraryElementImpl.forNode(
238 coreContext, AstFactory.libraryIdentifier2(["dart", "async"])); 258 coreContext, AstFactory.libraryIdentifier2(["dart", "async"]));
239 asyncLibrary.definingCompilationUnit = asyncUnit; 259 asyncLibrary.definingCompilationUnit = asyncUnit;
240 // 260 //
241 // dart:html 261 // dart:html
242 // 262 //
243 CompilationUnitElementImpl htmlUnit = 263 CompilationUnitElementImpl htmlUnit =
244 new CompilationUnitElementImpl("html_dartium.dart"); 264 new CompilationUnitElementImpl("html_dartium.dart");
245 Source htmlSource = sourceFactory.forUri(DartSdk.DART_HTML); 265 Source htmlSource = sourceFactory.forUri(DartSdk.DART_HTML);
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
299 coreContext, AstFactory.libraryIdentifier2(["dart", "dom", "html"])); 319 coreContext, AstFactory.libraryIdentifier2(["dart", "dom", "html"]));
300 htmlLibrary.definingCompilationUnit = htmlUnit; 320 htmlLibrary.definingCompilationUnit = htmlUnit;
301 // 321 //
302 // dart:math 322 // dart:math
303 // 323 //
304 CompilationUnitElementImpl mathUnit = 324 CompilationUnitElementImpl mathUnit =
305 new CompilationUnitElementImpl("math.dart"); 325 new CompilationUnitElementImpl("math.dart");
306 Source mathSource = sourceFactory.forUri(_DART_MATH); 326 Source mathSource = sourceFactory.forUri(_DART_MATH);
307 coreContext.setContents(mathSource, ""); 327 coreContext.setContents(mathSource, "");
308 mathUnit.librarySource = mathUnit.source = mathSource; 328 mathUnit.librarySource = mathUnit.source = mathSource;
309 FunctionElement cosElement = ElementFactory.functionElement3("cos", 329 FunctionElement cosElement = ElementFactory.functionElement3(
310 provider.doubleType.element, <ClassElement>[provider.numType.element], 330 "cos",
331 provider.doubleType.element,
332 <ClassElement>[provider.numType.element],
311 ClassElement.EMPTY_LIST); 333 ClassElement.EMPTY_LIST);
312 TopLevelVariableElement ln10Element = ElementFactory 334 TopLevelVariableElement ln10Element = ElementFactory
313 .topLevelVariableElement3("LN10", true, false, provider.doubleType); 335 .topLevelVariableElement3("LN10", true, false, provider.doubleType);
314 TopLevelVariableElement piElement = ElementFactory.topLevelVariableElement3( 336 TopLevelVariableElement piElement = ElementFactory.topLevelVariableElement3(
315 "PI", true, false, provider.doubleType); 337 "PI", true, false, provider.doubleType);
316 ClassElementImpl randomElement = ElementFactory.classElement2("Random"); 338 ClassElementImpl randomElement = ElementFactory.classElement2("Random");
317 randomElement.abstract = true; 339 randomElement.abstract = true;
318 ConstructorElementImpl randomConstructor = 340 ConstructorElementImpl randomConstructor =
319 ElementFactory.constructorElement2(randomElement, null); 341 ElementFactory.constructorElement2(randomElement, null);
320 randomConstructor.factory = true; 342 randomConstructor.factory = true;
321 ParameterElementImpl seedParam = new ParameterElementImpl("seed", 0); 343 ParameterElementImpl seedParam = new ParameterElementImpl("seed", 0);
322 seedParam.parameterKind = ParameterKind.POSITIONAL; 344 seedParam.parameterKind = ParameterKind.POSITIONAL;
323 seedParam.type = provider.intType; 345 seedParam.type = provider.intType;
324 randomConstructor.parameters = <ParameterElement>[seedParam]; 346 randomConstructor.parameters = <ParameterElement>[seedParam];
325 randomElement.constructors = <ConstructorElement>[randomConstructor]; 347 randomElement.constructors = <ConstructorElement>[randomConstructor];
326 FunctionElement sinElement = ElementFactory.functionElement3("sin", 348 FunctionElement sinElement = ElementFactory.functionElement3(
327 provider.doubleType.element, <ClassElement>[provider.numType.element], 349 "sin",
350 provider.doubleType.element,
351 <ClassElement>[provider.numType.element],
328 ClassElement.EMPTY_LIST); 352 ClassElement.EMPTY_LIST);
329 FunctionElement sqrtElement = ElementFactory.functionElement3("sqrt", 353 FunctionElement sqrtElement = ElementFactory.functionElement3(
330 provider.doubleType.element, <ClassElement>[provider.numType.element], 354 "sqrt",
355 provider.doubleType.element,
356 <ClassElement>[provider.numType.element],
331 ClassElement.EMPTY_LIST); 357 ClassElement.EMPTY_LIST);
332 mathUnit.accessors = <PropertyAccessorElement>[ 358 mathUnit.accessors = <PropertyAccessorElement>[
333 ln10Element.getter, 359 ln10Element.getter,
334 piElement.getter 360 piElement.getter
335 ]; 361 ];
336 mathUnit.functions = <FunctionElement>[cosElement, sinElement, sqrtElement]; 362 mathUnit.functions = <FunctionElement>[cosElement, sinElement, sqrtElement];
337 mathUnit.topLevelVariables = <TopLevelVariableElement>[ 363 mathUnit.topLevelVariables = <TopLevelVariableElement>[
338 ln10Element, 364 ln10Element,
339 piElement 365 piElement
340 ]; 366 ];
(...skipping 860 matching lines...) Expand 10 before | Expand all | Expand 10 after
1201 1227
1202 /** 1228 /**
1203 * The resolver being used to resolve the test cases. 1229 * The resolver being used to resolve the test cases.
1204 */ 1230 */
1205 ElementResolver _resolver; 1231 ElementResolver _resolver;
1206 1232
1207 void fail_visitExportDirective_combinators() { 1233 void fail_visitExportDirective_combinators() {
1208 fail("Not yet tested"); 1234 fail("Not yet tested");
1209 // Need to set up the exported library so that the identifier can be 1235 // Need to set up the exported library so that the identifier can be
1210 // resolved. 1236 // resolved.
1211 ExportDirective directive = 1237 ExportDirective directive = AstFactory.exportDirective2(null, [
1212 AstFactory.exportDirective2(null, [AstFactory.hideCombinator2(["A"])]); 1238 AstFactory.hideCombinator2(["A"])
1239 ]);
1213 _resolveNode(directive); 1240 _resolveNode(directive);
1214 _listener.assertNoErrors(); 1241 _listener.assertNoErrors();
1215 } 1242 }
1216 1243
1217 void fail_visitFunctionExpressionInvocation() { 1244 void fail_visitFunctionExpressionInvocation() {
1218 fail("Not yet tested"); 1245 fail("Not yet tested");
1219 _listener.assertNoErrors(); 1246 _listener.assertNoErrors();
1220 } 1247 }
1221 1248
1222 void fail_visitImportDirective_combinators_noPrefix() { 1249 void fail_visitImportDirective_combinators_noPrefix() {
1223 fail("Not yet tested"); 1250 fail("Not yet tested");
1224 // Need to set up the imported library so that the identifier can be 1251 // Need to set up the imported library so that the identifier can be
1225 // resolved. 1252 // resolved.
1226 ImportDirective directive = AstFactory.importDirective3( 1253 ImportDirective directive = AstFactory.importDirective3(null, null, [
1227 null, null, [AstFactory.showCombinator2(["A"])]); 1254 AstFactory.showCombinator2(["A"])
1255 ]);
1228 _resolveNode(directive); 1256 _resolveNode(directive);
1229 _listener.assertNoErrors(); 1257 _listener.assertNoErrors();
1230 } 1258 }
1231 1259
1232 void fail_visitImportDirective_combinators_prefix() { 1260 void fail_visitImportDirective_combinators_prefix() {
1233 fail("Not yet tested"); 1261 fail("Not yet tested");
1234 // Need to set up the imported library so that the identifiers can be 1262 // Need to set up the imported library so that the identifiers can be
1235 // resolved. 1263 // resolved.
1236 String prefixName = "p"; 1264 String prefixName = "p";
1237 _definingLibrary.imports = <ImportElement>[ 1265 _definingLibrary.imports = <ImportElement>[
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
1317 // var j; 1345 // var j;
1318 // i == j 1346 // i == j
1319 InterfaceType stringType = _typeProvider.stringType; 1347 InterfaceType stringType = _typeProvider.stringType;
1320 SimpleIdentifier left = AstFactory.identifier3("i"); 1348 SimpleIdentifier left = AstFactory.identifier3("i");
1321 left.staticType = stringType; 1349 left.staticType = stringType;
1322 BinaryExpression expression = AstFactory.binaryExpression( 1350 BinaryExpression expression = AstFactory.binaryExpression(
1323 left, TokenType.BANG_EQ, AstFactory.identifier3("j")); 1351 left, TokenType.BANG_EQ, AstFactory.identifier3("j"));
1324 _resolveNode(expression); 1352 _resolveNode(expression);
1325 var stringElement = stringType.element; 1353 var stringElement = stringType.element;
1326 expect(expression.staticElement, isNotNull); 1354 expect(expression.staticElement, isNotNull);
1327 expect(expression.staticElement, stringElement.lookUpMethod( 1355 expect(
1328 TokenType.EQ_EQ.lexeme, stringElement.library)); 1356 expression.staticElement,
1357 stringElement.lookUpMethod(
1358 TokenType.EQ_EQ.lexeme, stringElement.library));
1329 expect(expression.propagatedElement, isNull); 1359 expect(expression.propagatedElement, isNull);
1330 _listener.assertNoErrors(); 1360 _listener.assertNoErrors();
1331 } 1361 }
1332 1362
1333 void test_visitBinaryExpression_eq() { 1363 void test_visitBinaryExpression_eq() {
1334 // String i; 1364 // String i;
1335 // var j; 1365 // var j;
1336 // i == j 1366 // i == j
1337 InterfaceType stringType = _typeProvider.stringType; 1367 InterfaceType stringType = _typeProvider.stringType;
1338 SimpleIdentifier left = AstFactory.identifier3("i"); 1368 SimpleIdentifier left = AstFactory.identifier3("i");
1339 left.staticType = stringType; 1369 left.staticType = stringType;
1340 BinaryExpression expression = AstFactory.binaryExpression( 1370 BinaryExpression expression = AstFactory.binaryExpression(
1341 left, TokenType.EQ_EQ, AstFactory.identifier3("j")); 1371 left, TokenType.EQ_EQ, AstFactory.identifier3("j"));
1342 _resolveNode(expression); 1372 _resolveNode(expression);
1343 var stringElement = stringType.element; 1373 var stringElement = stringType.element;
1344 expect(expression.staticElement, stringElement.lookUpMethod( 1374 expect(
1345 TokenType.EQ_EQ.lexeme, stringElement.library)); 1375 expression.staticElement,
1376 stringElement.lookUpMethod(
1377 TokenType.EQ_EQ.lexeme, stringElement.library));
1346 expect(expression.propagatedElement, isNull); 1378 expect(expression.propagatedElement, isNull);
1347 _listener.assertNoErrors(); 1379 _listener.assertNoErrors();
1348 } 1380 }
1349 1381
1350 void test_visitBinaryExpression_plus() { 1382 void test_visitBinaryExpression_plus() {
1351 // num i; 1383 // num i;
1352 // var j; 1384 // var j;
1353 // i + j 1385 // i + j
1354 InterfaceType numType = _typeProvider.numType; 1386 InterfaceType numType = _typeProvider.numType;
1355 SimpleIdentifier left = AstFactory.identifier3("i"); 1387 SimpleIdentifier left = AstFactory.identifier3("i");
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after
1606 ConstructorElementImpl constructor = 1638 ConstructorElementImpl constructor =
1607 ElementFactory.constructorElement2(classA, constructorName); 1639 ElementFactory.constructorElement2(classA, constructorName);
1608 String parameterName = "a"; 1640 String parameterName = "a";
1609 ParameterElement parameter = ElementFactory.namedParameter(parameterName); 1641 ParameterElement parameter = ElementFactory.namedParameter(parameterName);
1610 constructor.parameters = <ParameterElement>[parameter]; 1642 constructor.parameters = <ParameterElement>[parameter];
1611 classA.constructors = <ConstructorElement>[constructor]; 1643 classA.constructors = <ConstructorElement>[constructor];
1612 ConstructorName name = AstFactory.constructorName( 1644 ConstructorName name = AstFactory.constructorName(
1613 AstFactory.typeName(classA), constructorName); 1645 AstFactory.typeName(classA), constructorName);
1614 name.staticElement = constructor; 1646 name.staticElement = constructor;
1615 InstanceCreationExpression creation = AstFactory.instanceCreationExpression( 1647 InstanceCreationExpression creation = AstFactory.instanceCreationExpression(
1616 Keyword.NEW, name, 1648 Keyword.NEW,
1649 name,
1617 [AstFactory.namedExpression2(parameterName, AstFactory.integer(0))]); 1650 [AstFactory.namedExpression2(parameterName, AstFactory.integer(0))]);
1618 _resolveNode(creation); 1651 _resolveNode(creation);
1619 expect(creation.staticElement, same(constructor)); 1652 expect(creation.staticElement, same(constructor));
1620 expect((creation.argumentList.arguments[ 1653 expect(
1621 0] as NamedExpression).name.label.staticElement, same(parameter)); 1654 (creation.argumentList.arguments[0] as NamedExpression)
1655 .name
1656 .label
1657 .staticElement,
1658 same(parameter));
1622 _listener.assertNoErrors(); 1659 _listener.assertNoErrors();
1623 } 1660 }
1624 1661
1625 void test_visitMethodInvocation() { 1662 void test_visitMethodInvocation() {
1626 InterfaceType numType = _typeProvider.numType; 1663 InterfaceType numType = _typeProvider.numType;
1627 SimpleIdentifier left = AstFactory.identifier3("i"); 1664 SimpleIdentifier left = AstFactory.identifier3("i");
1628 left.staticType = numType; 1665 left.staticType = numType;
1629 String methodName = "abs"; 1666 String methodName = "abs";
1630 MethodInvocation invocation = AstFactory.methodInvocation(left, methodName); 1667 MethodInvocation invocation = AstFactory.methodInvocation(left, methodName);
1631 _resolveNode(invocation); 1668 _resolveNode(invocation);
1632 expect(invocation.methodName.staticElement, 1669 expect(invocation.methodName.staticElement,
1633 same(getMethod(numType, methodName))); 1670 same(getMethod(numType, methodName)));
1634 _listener.assertNoErrors(); 1671 _listener.assertNoErrors();
1635 } 1672 }
1636 1673
1637 void test_visitMethodInvocation_namedParameter() { 1674 void test_visitMethodInvocation_namedParameter() {
1638 ClassElementImpl classA = ElementFactory.classElement2("A"); 1675 ClassElementImpl classA = ElementFactory.classElement2("A");
1639 String methodName = "m"; 1676 String methodName = "m";
1640 String parameterName = "p"; 1677 String parameterName = "p";
1641 MethodElementImpl method = ElementFactory.methodElement(methodName, null); 1678 MethodElementImpl method = ElementFactory.methodElement(methodName, null);
1642 ParameterElement parameter = ElementFactory.namedParameter(parameterName); 1679 ParameterElement parameter = ElementFactory.namedParameter(parameterName);
1643 method.parameters = <ParameterElement>[parameter]; 1680 method.parameters = <ParameterElement>[parameter];
1644 classA.methods = <MethodElement>[method]; 1681 classA.methods = <MethodElement>[method];
1645 SimpleIdentifier left = AstFactory.identifier3("i"); 1682 SimpleIdentifier left = AstFactory.identifier3("i");
1646 left.staticType = classA.type; 1683 left.staticType = classA.type;
1647 MethodInvocation invocation = AstFactory.methodInvocation(left, methodName, 1684 MethodInvocation invocation = AstFactory.methodInvocation(left, methodName,
1648 [AstFactory.namedExpression2(parameterName, AstFactory.integer(0))]); 1685 [AstFactory.namedExpression2(parameterName, AstFactory.integer(0))]);
1649 _resolveNode(invocation); 1686 _resolveNode(invocation);
1650 expect(invocation.methodName.staticElement, same(method)); 1687 expect(invocation.methodName.staticElement, same(method));
1651 expect((invocation.argumentList.arguments[ 1688 expect(
1652 0] as NamedExpression).name.label.staticElement, same(parameter)); 1689 (invocation.argumentList.arguments[0] as NamedExpression)
1690 .name
1691 .label
1692 .staticElement,
1693 same(parameter));
1653 _listener.assertNoErrors(); 1694 _listener.assertNoErrors();
1654 } 1695 }
1655 1696
1656 void test_visitPostfixExpression() { 1697 void test_visitPostfixExpression() {
1657 InterfaceType numType = _typeProvider.numType; 1698 InterfaceType numType = _typeProvider.numType;
1658 SimpleIdentifier operand = AstFactory.identifier3("i"); 1699 SimpleIdentifier operand = AstFactory.identifier3("i");
1659 operand.staticType = numType; 1700 operand.staticType = numType;
1660 PostfixExpression expression = 1701 PostfixExpression expression =
1661 AstFactory.postfixExpression(operand, TokenType.PLUS_PLUS); 1702 AstFactory.postfixExpression(operand, TokenType.PLUS_PLUS);
1662 _resolveNode(expression); 1703 _resolveNode(expression);
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
1801 // } 1842 // }
1802 // 1843 //
1803 ClassElementImpl classA = ElementFactory.classElement2("A"); 1844 ClassElementImpl classA = ElementFactory.classElement2("A");
1804 String getterName = "b"; 1845 String getterName = "b";
1805 PropertyAccessorElement getter = 1846 PropertyAccessorElement getter =
1806 ElementFactory.getterElement(getterName, false, _typeProvider.intType); 1847 ElementFactory.getterElement(getterName, false, _typeProvider.intType);
1807 classA.accessors = <PropertyAccessorElement>[getter]; 1848 classA.accessors = <PropertyAccessorElement>[getter];
1808 SuperExpression target = AstFactory.superExpression(); 1849 SuperExpression target = AstFactory.superExpression();
1809 target.staticType = ElementFactory.classElement("B", classA.type).type; 1850 target.staticType = ElementFactory.classElement("B", classA.type).type;
1810 PropertyAccess access = AstFactory.propertyAccess2(target, getterName); 1851 PropertyAccess access = AstFactory.propertyAccess2(target, getterName);
1811 AstFactory.methodDeclaration2(null, null, null, null, 1852 AstFactory.methodDeclaration2(
1812 AstFactory.identifier3("m"), AstFactory.formalParameterList(), 1853 null,
1854 null,
1855 null,
1856 null,
1857 AstFactory.identifier3("m"),
1858 AstFactory.formalParameterList(),
1813 AstFactory.expressionFunctionBody(access)); 1859 AstFactory.expressionFunctionBody(access));
1814 _resolveNode(access); 1860 _resolveNode(access);
1815 expect(access.propertyName.staticElement, same(getter)); 1861 expect(access.propertyName.staticElement, same(getter));
1816 _listener.assertNoErrors(); 1862 _listener.assertNoErrors();
1817 } 1863 }
1818 1864
1819 void test_visitPropertyAccess_setter_this() { 1865 void test_visitPropertyAccess_setter_this() {
1820 ClassElementImpl classA = ElementFactory.classElement2("A"); 1866 ClassElementImpl classA = ElementFactory.classElement2("A");
1821 String setterName = "b"; 1867 String setterName = "b";
1822 PropertyAccessorElement setter = 1868 PropertyAccessorElement setter =
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
1903 ElementFactory.classElement("B", superclass.type); 1949 ElementFactory.classElement("B", superclass.type);
1904 ConstructorElementImpl subConstructor = 1950 ConstructorElementImpl subConstructor =
1905 ElementFactory.constructorElement2(subclass, null); 1951 ElementFactory.constructorElement2(subclass, null);
1906 subclass.constructors = <ConstructorElement>[subConstructor]; 1952 subclass.constructors = <ConstructorElement>[subConstructor];
1907 SuperConstructorInvocation invocation = AstFactory 1953 SuperConstructorInvocation invocation = AstFactory
1908 .superConstructorInvocation([ 1954 .superConstructorInvocation([
1909 AstFactory.namedExpression2(parameterName, AstFactory.integer(0)) 1955 AstFactory.namedExpression2(parameterName, AstFactory.integer(0))
1910 ]); 1956 ]);
1911 _resolveInClass(invocation, subclass); 1957 _resolveInClass(invocation, subclass);
1912 expect(invocation.staticElement, superConstructor); 1958 expect(invocation.staticElement, superConstructor);
1913 expect((invocation.argumentList.arguments[ 1959 expect(
1914 0] as NamedExpression).name.label.staticElement, same(parameter)); 1960 (invocation.argumentList.arguments[0] as NamedExpression)
1961 .name
1962 .label
1963 .staticElement,
1964 same(parameter));
1915 _listener.assertNoErrors(); 1965 _listener.assertNoErrors();
1916 } 1966 }
1917 1967
1918 /** 1968 /**
1919 * Create the resolver used by the tests. 1969 * Create the resolver used by the tests.
1920 * 1970 *
1921 * @return the resolver that was created 1971 * @return the resolver that was created
1922 */ 1972 */
1923 ElementResolver _createResolver() { 1973 ElementResolver _createResolver() {
1924 InternalAnalysisContext context = AnalysisContextFactory.contextWithCore(); 1974 InternalAnalysisContext context = AnalysisContextFactory.contextWithCore();
(...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after
2234 verify([source]); 2284 verify([source]);
2235 } 2285 }
2236 2286
2237 void fail_unusedImport_as_equalPrefixes() { 2287 void fail_unusedImport_as_equalPrefixes() {
2238 // See todo at ImportsVerifier.prefixElementMap. 2288 // See todo at ImportsVerifier.prefixElementMap.
2239 Source source = addSource(r''' 2289 Source source = addSource(r'''
2240 library L; 2290 library L;
2241 import 'lib1.dart' as one; 2291 import 'lib1.dart' as one;
2242 import 'lib2.dart' as one; 2292 import 'lib2.dart' as one;
2243 one.A a;'''); 2293 one.A a;''');
2244 Source source2 = addNamedSource("/lib1.dart", r''' 2294 Source source2 = addNamedSource(
2295 "/lib1.dart",
2296 r'''
2245 library lib1; 2297 library lib1;
2246 class A {}'''); 2298 class A {}''');
2247 Source source3 = addNamedSource("/lib2.dart", r''' 2299 Source source3 = addNamedSource(
2300 "/lib2.dart",
2301 r'''
2248 library lib2; 2302 library lib2;
2249 class B {}'''); 2303 class B {}''');
2250 computeLibrarySourceErrors(source); 2304 computeLibrarySourceErrors(source);
2251 assertErrors(source, [HintCode.UNUSED_IMPORT]); 2305 assertErrors(source, [HintCode.UNUSED_IMPORT]);
2252 assertNoErrors(source2); 2306 assertNoErrors(source2);
2253 assertNoErrors(source3); 2307 assertNoErrors(source3);
2254 verify([source, source2, source3]); 2308 verify([source, source2, source3]);
2255 } 2309 }
2256 2310
2257 void test_argumentTypeNotAssignable_functionType() { 2311 void test_argumentTypeNotAssignable_functionType() {
(...skipping 452 matching lines...) Expand 10 before | Expand all | Expand 10 after
2710 m() {} 2764 m() {}
2711 n() {m();} 2765 n() {m();}
2712 }'''); 2766 }''');
2713 computeLibrarySourceErrors(source); 2767 computeLibrarySourceErrors(source);
2714 assertErrors(source, [HintCode.DEPRECATED_MEMBER_USE]); 2768 assertErrors(source, [HintCode.DEPRECATED_MEMBER_USE]);
2715 verify([source]); 2769 verify([source]);
2716 } 2770 }
2717 2771
2718 void test_deprecatedAnnotationUse_export() { 2772 void test_deprecatedAnnotationUse_export() {
2719 Source source = addSource("export 'deprecated_library.dart';"); 2773 Source source = addSource("export 'deprecated_library.dart';");
2720 addNamedSource("/deprecated_library.dart", r''' 2774 addNamedSource(
2775 "/deprecated_library.dart",
2776 r'''
2721 @deprecated 2777 @deprecated
2722 library deprecated_library; 2778 library deprecated_library;
2723 class A {}'''); 2779 class A {}''');
2724 computeLibrarySourceErrors(source); 2780 computeLibrarySourceErrors(source);
2725 assertErrors(source, [HintCode.DEPRECATED_MEMBER_USE]); 2781 assertErrors(source, [HintCode.DEPRECATED_MEMBER_USE]);
2726 verify([source]); 2782 verify([source]);
2727 } 2783 }
2728 2784
2729 void test_deprecatedAnnotationUse_getter() { 2785 void test_deprecatedAnnotationUse_getter() {
2730 Source source = addSource(r''' 2786 Source source = addSource(r'''
2731 class A { 2787 class A {
2732 @deprecated 2788 @deprecated
2733 get m => 1; 2789 get m => 1;
2734 } 2790 }
2735 f(A a) { 2791 f(A a) {
2736 return a.m; 2792 return a.m;
2737 }'''); 2793 }''');
2738 computeLibrarySourceErrors(source); 2794 computeLibrarySourceErrors(source);
2739 assertErrors(source, [HintCode.DEPRECATED_MEMBER_USE]); 2795 assertErrors(source, [HintCode.DEPRECATED_MEMBER_USE]);
2740 verify([source]); 2796 verify([source]);
2741 } 2797 }
2742 2798
2743 void test_deprecatedAnnotationUse_import() { 2799 void test_deprecatedAnnotationUse_import() {
2744 Source source = addSource(r''' 2800 Source source = addSource(r'''
2745 import 'deprecated_library.dart'; 2801 import 'deprecated_library.dart';
2746 f(A a) {}'''); 2802 f(A a) {}''');
2747 addNamedSource("/deprecated_library.dart", r''' 2803 addNamedSource(
2804 "/deprecated_library.dart",
2805 r'''
2748 @deprecated 2806 @deprecated
2749 library deprecated_library; 2807 library deprecated_library;
2750 class A {}'''); 2808 class A {}''');
2751 computeLibrarySourceErrors(source); 2809 computeLibrarySourceErrors(source);
2752 assertErrors(source, [HintCode.DEPRECATED_MEMBER_USE]); 2810 assertErrors(source, [HintCode.DEPRECATED_MEMBER_USE]);
2753 verify([source]); 2811 verify([source]);
2754 } 2812 }
2755 2813
2756 void test_deprecatedAnnotationUse_indexExpression() { 2814 void test_deprecatedAnnotationUse_indexExpression() {
2757 Source source = addSource(r''' 2815 Source source = addSource(r'''
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
2894 assertErrors(source, [HintCode.DIVISION_OPTIMIZATION]); 2952 assertErrors(source, [HintCode.DIVISION_OPTIMIZATION]);
2895 verify([source]); 2953 verify([source]);
2896 } 2954 }
2897 2955
2898 void test_duplicateImport() { 2956 void test_duplicateImport() {
2899 Source source = addSource(r''' 2957 Source source = addSource(r'''
2900 library L; 2958 library L;
2901 import 'lib1.dart'; 2959 import 'lib1.dart';
2902 import 'lib1.dart'; 2960 import 'lib1.dart';
2903 A a;'''); 2961 A a;''');
2904 addNamedSource("/lib1.dart", r''' 2962 addNamedSource(
2963 "/lib1.dart",
2964 r'''
2905 library lib1; 2965 library lib1;
2906 class A {}'''); 2966 class A {}''');
2907 computeLibrarySourceErrors(source); 2967 computeLibrarySourceErrors(source);
2908 assertErrors(source, [HintCode.DUPLICATE_IMPORT]); 2968 assertErrors(source, [HintCode.DUPLICATE_IMPORT]);
2909 verify([source]); 2969 verify([source]);
2910 } 2970 }
2911 2971
2912 void test_duplicateImport2() { 2972 void test_duplicateImport2() {
2913 Source source = addSource(r''' 2973 Source source = addSource(r'''
2914 library L; 2974 library L;
2915 import 'lib1.dart'; 2975 import 'lib1.dart';
2916 import 'lib1.dart'; 2976 import 'lib1.dart';
2917 import 'lib1.dart'; 2977 import 'lib1.dart';
2918 A a;'''); 2978 A a;''');
2919 addNamedSource("/lib1.dart", r''' 2979 addNamedSource(
2980 "/lib1.dart",
2981 r'''
2920 library lib1; 2982 library lib1;
2921 class A {}'''); 2983 class A {}''');
2922 computeLibrarySourceErrors(source); 2984 computeLibrarySourceErrors(source);
2923 assertErrors( 2985 assertErrors(
2924 source, [HintCode.DUPLICATE_IMPORT, HintCode.DUPLICATE_IMPORT]); 2986 source, [HintCode.DUPLICATE_IMPORT, HintCode.DUPLICATE_IMPORT]);
2925 verify([source]); 2987 verify([source]);
2926 } 2988 }
2927 2989
2928 void test_duplicateImport3() { 2990 void test_duplicateImport3() {
2929 Source source = addSource(r''' 2991 Source source = addSource(r'''
2930 library L; 2992 library L;
2931 import 'lib1.dart' as M show A hide B; 2993 import 'lib1.dart' as M show A hide B;
2932 import 'lib1.dart' as M show A hide B; 2994 import 'lib1.dart' as M show A hide B;
2933 M.A a;'''); 2995 M.A a;''');
2934 addNamedSource("/lib1.dart", r''' 2996 addNamedSource(
2997 "/lib1.dart",
2998 r'''
2935 library lib1; 2999 library lib1;
2936 class A {} 3000 class A {}
2937 class B {}'''); 3001 class B {}''');
2938 computeLibrarySourceErrors(source); 3002 computeLibrarySourceErrors(source);
2939 assertErrors(source, [HintCode.DUPLICATE_IMPORT]); 3003 assertErrors(source, [HintCode.DUPLICATE_IMPORT]);
2940 verify([source]); 3004 verify([source]);
2941 } 3005 }
2942 3006
2943 void test_importDeferredLibraryWithLoadFunction() { 3007 void test_importDeferredLibraryWithLoadFunction() {
2944 resolveWithErrors(<String>[ 3008 resolveWithErrors(<String>[
2945 r''' 3009 r'''
2946 library lib1; 3010 library lib1;
2947 loadLibrary() {} 3011 loadLibrary() {}
2948 f() {}''', 3012 f() {}''',
2949 r''' 3013 r'''
2950 library root; 3014 library root;
2951 import 'lib1.dart' deferred as lib1; 3015 import 'lib1.dart' deferred as lib1;
2952 main() { lib1.f(); }''' 3016 main() { lib1.f(); }'''
2953 ], <ErrorCode>[HintCode.IMPORT_DEFERRED_LIBRARY_WITH_LOAD_FUNCTION]); 3017 ], <ErrorCode>[
3018 HintCode.IMPORT_DEFERRED_LIBRARY_WITH_LOAD_FUNCTION
3019 ]);
2954 } 3020 }
2955 3021
2956 void test_invalidAssignment_instanceVariable() { 3022 void test_invalidAssignment_instanceVariable() {
2957 Source source = addSource(r''' 3023 Source source = addSource(r'''
2958 class A { 3024 class A {
2959 int x; 3025 int x;
2960 } 3026 }
2961 f(var y) { 3027 f(var y) {
2962 A a; 3028 A a;
2963 if(y is String) { 3029 if(y is String) {
(...skipping 1250 matching lines...) Expand 10 before | Expand all | Expand 10 after
4214 assertNoErrors(source2); 4280 assertNoErrors(source2);
4215 verify([source, source2]); 4281 verify([source, source2]);
4216 } 4282 }
4217 4283
4218 void test_unusedImport_as() { 4284 void test_unusedImport_as() {
4219 Source source = addSource(r''' 4285 Source source = addSource(r'''
4220 library L; 4286 library L;
4221 import 'lib1.dart'; 4287 import 'lib1.dart';
4222 import 'lib1.dart' as one; 4288 import 'lib1.dart' as one;
4223 one.A a;'''); 4289 one.A a;''');
4224 Source source2 = addNamedSource("/lib1.dart", r''' 4290 Source source2 = addNamedSource(
4291 "/lib1.dart",
4292 r'''
4225 library lib1; 4293 library lib1;
4226 class A {}'''); 4294 class A {}''');
4227 computeLibrarySourceErrors(source); 4295 computeLibrarySourceErrors(source);
4228 assertErrors(source, [HintCode.UNUSED_IMPORT]); 4296 assertErrors(source, [HintCode.UNUSED_IMPORT]);
4229 assertNoErrors(source2); 4297 assertNoErrors(source2);
4230 verify([source, source2]); 4298 verify([source, source2]);
4231 } 4299 }
4232 4300
4233 void test_unusedImport_hide() { 4301 void test_unusedImport_hide() {
4234 Source source = addSource(r''' 4302 Source source = addSource(r'''
4235 library L; 4303 library L;
4236 import 'lib1.dart'; 4304 import 'lib1.dart';
4237 import 'lib1.dart' hide A; 4305 import 'lib1.dart' hide A;
4238 A a;'''); 4306 A a;''');
4239 Source source2 = addNamedSource("/lib1.dart", r''' 4307 Source source2 = addNamedSource(
4308 "/lib1.dart",
4309 r'''
4240 library lib1; 4310 library lib1;
4241 class A {}'''); 4311 class A {}''');
4242 computeLibrarySourceErrors(source); 4312 computeLibrarySourceErrors(source);
4243 assertErrors(source, [HintCode.UNUSED_IMPORT]); 4313 assertErrors(source, [HintCode.UNUSED_IMPORT]);
4244 assertNoErrors(source2); 4314 assertNoErrors(source2);
4245 verify([source, source2]); 4315 verify([source, source2]);
4246 } 4316 }
4247 4317
4248 void test_unusedImport_show() { 4318 void test_unusedImport_show() {
4249 Source source = addSource(r''' 4319 Source source = addSource(r'''
4250 library L; 4320 library L;
4251 import 'lib1.dart' show A; 4321 import 'lib1.dart' show A;
4252 import 'lib1.dart' show B; 4322 import 'lib1.dart' show B;
4253 A a;'''); 4323 A a;''');
4254 Source source2 = addNamedSource("/lib1.dart", r''' 4324 Source source2 = addNamedSource(
4325 "/lib1.dart",
4326 r'''
4255 library lib1; 4327 library lib1;
4256 class A {} 4328 class A {}
4257 class B {}'''); 4329 class B {}''');
4258 computeLibrarySourceErrors(source); 4330 computeLibrarySourceErrors(source);
4259 assertErrors(source, [HintCode.UNUSED_IMPORT]); 4331 assertErrors(source, [HintCode.UNUSED_IMPORT]);
4260 assertNoErrors(source2); 4332 assertNoErrors(source2);
4261 verify([source, source2]); 4333 verify([source, source2]);
4262 } 4334 }
4263 4335
4264 void test_unusedLocalVariable_inCatch_exception() { 4336 void test_unusedLocalVariable_inCatch_exception() {
(...skipping 1515 matching lines...) Expand 10 before | Expand all | Expand 10 after
5780 _context = AnalysisContextFactory.contextWithCore(); 5852 _context = AnalysisContextFactory.contextWithCore();
5781 } 5853 }
5782 5854
5783 @override 5855 @override
5784 void tearDown() { 5856 void tearDown() {
5785 _context = null; 5857 _context = null;
5786 super.tearDown(); 5858 super.tearDown();
5787 } 5859 }
5788 5860
5789 void test_accessorsAcrossFiles() { 5861 void test_accessorsAcrossFiles() {
5790 Source librarySource = addSource("/lib.dart", r''' 5862 Source librarySource = addSource(
5863 "/lib.dart",
5864 r'''
5791 library lib; 5865 library lib;
5792 part 'first.dart'; 5866 part 'first.dart';
5793 part 'second.dart';'''); 5867 part 'second.dart';''');
5794 addSource("/first.dart", r''' 5868 addSource(
5869 "/first.dart",
5870 r'''
5795 part of lib; 5871 part of lib;
5796 int get V => 0;'''); 5872 int get V => 0;''');
5797 addSource("/second.dart", r''' 5873 addSource(
5874 "/second.dart",
5875 r'''
5798 part of lib; 5876 part of lib;
5799 void set V(int v) {}'''); 5877 void set V(int v) {}''');
5800 LibraryElement element = _buildLibrary(librarySource); 5878 LibraryElement element = _buildLibrary(librarySource);
5801 expect(element, isNotNull); 5879 expect(element, isNotNull);
5802 List<CompilationUnitElement> sourcedUnits = element.parts; 5880 List<CompilationUnitElement> sourcedUnits = element.parts;
5803 expect(sourcedUnits, hasLength(2)); 5881 expect(sourcedUnits, hasLength(2));
5804 List<PropertyAccessorElement> firstAccessors = sourcedUnits[0].accessors; 5882 List<PropertyAccessorElement> firstAccessors = sourcedUnits[0].accessors;
5805 expect(firstAccessors, hasLength(1)); 5883 expect(firstAccessors, hasLength(1));
5806 List<PropertyAccessorElement> secondAccessors = sourcedUnits[1].accessors; 5884 List<PropertyAccessorElement> secondAccessors = sourcedUnits[1].accessors;
5807 expect(secondAccessors, hasLength(1)); 5885 expect(secondAccessors, hasLength(1));
(...skipping 25 matching lines...) Expand all
5833 void test_missingLibraryDirectiveWithPart() { 5911 void test_missingLibraryDirectiveWithPart() {
5834 addSource("/a.dart", "part of lib;"); 5912 addSource("/a.dart", "part of lib;");
5835 Source librarySource = addSource("/lib.dart", "part 'a.dart';"); 5913 Source librarySource = addSource("/lib.dart", "part 'a.dart';");
5836 LibraryElement element = _buildLibrary( 5914 LibraryElement element = _buildLibrary(
5837 librarySource, [ResolverErrorCode.MISSING_LIBRARY_DIRECTIVE_WITH_PART]); 5915 librarySource, [ResolverErrorCode.MISSING_LIBRARY_DIRECTIVE_WITH_PART]);
5838 expect(element, isNotNull); 5916 expect(element, isNotNull);
5839 } 5917 }
5840 5918
5841 void test_missingPartOfDirective() { 5919 void test_missingPartOfDirective() {
5842 addSource("/a.dart", "class A {}"); 5920 addSource("/a.dart", "class A {}");
5843 Source librarySource = addSource("/lib.dart", r''' 5921 Source librarySource = addSource(
5922 "/lib.dart",
5923 r'''
5844 library lib; 5924 library lib;
5845 5925
5846 part 'a.dart';'''); 5926 part 'a.dart';''');
5847 LibraryElement element = 5927 LibraryElement element =
5848 _buildLibrary(librarySource, [CompileTimeErrorCode.PART_OF_NON_PART]); 5928 _buildLibrary(librarySource, [CompileTimeErrorCode.PART_OF_NON_PART]);
5849 expect(element, isNotNull); 5929 expect(element, isNotNull);
5850 } 5930 }
5851 5931
5852 void test_multipleFiles() { 5932 void test_multipleFiles() {
5853 Source librarySource = addSource("/lib.dart", r''' 5933 Source librarySource = addSource(
5934 "/lib.dart",
5935 r'''
5854 library lib; 5936 library lib;
5855 part 'first.dart'; 5937 part 'first.dart';
5856 part 'second.dart'; 5938 part 'second.dart';
5857 5939
5858 class A {}'''); 5940 class A {}''');
5859 addSource("/first.dart", r''' 5941 addSource(
5942 "/first.dart",
5943 r'''
5860 part of lib; 5944 part of lib;
5861 class B {}'''); 5945 class B {}''');
5862 addSource("/second.dart", r''' 5946 addSource(
5947 "/second.dart",
5948 r'''
5863 part of lib; 5949 part of lib;
5864 class C {}'''); 5950 class C {}''');
5865 LibraryElement element = _buildLibrary(librarySource); 5951 LibraryElement element = _buildLibrary(librarySource);
5866 expect(element, isNotNull); 5952 expect(element, isNotNull);
5867 List<CompilationUnitElement> sourcedUnits = element.parts; 5953 List<CompilationUnitElement> sourcedUnits = element.parts;
5868 expect(sourcedUnits, hasLength(2)); 5954 expect(sourcedUnits, hasLength(2));
5869 _assertTypes(element.definingCompilationUnit, ["A"]); 5955 _assertTypes(element.definingCompilationUnit, ["A"]);
5870 if (sourcedUnits[0].name == "first.dart") { 5956 if (sourcedUnits[0].name == "first.dart") {
5871 _assertTypes(sourcedUnits[0], ["B"]); 5957 _assertTypes(sourcedUnits[0], ["B"]);
5872 _assertTypes(sourcedUnits[1], ["C"]); 5958 _assertTypes(sourcedUnits[1], ["C"]);
5873 } else { 5959 } else {
5874 _assertTypes(sourcedUnits[0], ["C"]); 5960 _assertTypes(sourcedUnits[0], ["C"]);
5875 _assertTypes(sourcedUnits[1], ["B"]); 5961 _assertTypes(sourcedUnits[1], ["B"]);
5876 } 5962 }
5877 } 5963 }
5878 5964
5879 void test_singleFile() { 5965 void test_singleFile() {
5880 Source librarySource = addSource("/lib.dart", r''' 5966 Source librarySource = addSource(
5967 "/lib.dart",
5968 r'''
5881 library lib; 5969 library lib;
5882 5970
5883 class A {}'''); 5971 class A {}''');
5884 LibraryElement element = _buildLibrary(librarySource); 5972 LibraryElement element = _buildLibrary(librarySource);
5885 expect(element, isNotNull); 5973 expect(element, isNotNull);
5886 _assertTypes(element.definingCompilationUnit, ["A"]); 5974 _assertTypes(element.definingCompilationUnit, ["A"]);
5887 } 5975 }
5888 5976
5889 /** 5977 /**
5890 * Ensure that there are elements representing all of the types in the given a rray of type names. 5978 * Ensure that there are elements representing all of the types in the given a rray of type names.
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
5939 void test_conflictingImports() { 6027 void test_conflictingImports() {
5940 AnalysisContext context = AnalysisContextFactory.contextWithCore(); 6028 AnalysisContext context = AnalysisContextFactory.contextWithCore();
5941 String typeNameA = "A"; 6029 String typeNameA = "A";
5942 String typeNameB = "B"; 6030 String typeNameB = "B";
5943 String typeNameC = "C"; 6031 String typeNameC = "C";
5944 ClassElement typeA = ElementFactory.classElement2(typeNameA); 6032 ClassElement typeA = ElementFactory.classElement2(typeNameA);
5945 ClassElement typeB1 = ElementFactory.classElement2(typeNameB); 6033 ClassElement typeB1 = ElementFactory.classElement2(typeNameB);
5946 ClassElement typeB2 = ElementFactory.classElement2(typeNameB); 6034 ClassElement typeB2 = ElementFactory.classElement2(typeNameB);
5947 ClassElement typeC = ElementFactory.classElement2(typeNameC); 6035 ClassElement typeC = ElementFactory.classElement2(typeNameC);
5948 LibraryElement importedLibrary1 = createTestLibrary(context, "imported1"); 6036 LibraryElement importedLibrary1 = createTestLibrary(context, "imported1");
5949 (importedLibrary1.definingCompilationUnit as CompilationUnitElementImpl).typ es = 6037 (importedLibrary1.definingCompilationUnit as CompilationUnitElementImpl)
5950 <ClassElement>[typeA, typeB1]; 6038 .types = <ClassElement>[typeA, typeB1];
5951 ImportElementImpl import1 = 6039 ImportElementImpl import1 =
5952 ElementFactory.importFor(importedLibrary1, null); 6040 ElementFactory.importFor(importedLibrary1, null);
5953 LibraryElement importedLibrary2 = createTestLibrary(context, "imported2"); 6041 LibraryElement importedLibrary2 = createTestLibrary(context, "imported2");
5954 (importedLibrary2.definingCompilationUnit as CompilationUnitElementImpl).typ es = 6042 (importedLibrary2.definingCompilationUnit as CompilationUnitElementImpl)
5955 <ClassElement>[typeB2, typeC]; 6043 .types = <ClassElement>[typeB2, typeC];
5956 ImportElementImpl import2 = 6044 ImportElementImpl import2 =
5957 ElementFactory.importFor(importedLibrary2, null); 6045 ElementFactory.importFor(importedLibrary2, null);
5958 LibraryElementImpl importingLibrary = 6046 LibraryElementImpl importingLibrary =
5959 createTestLibrary(context, "importing"); 6047 createTestLibrary(context, "importing");
5960 importingLibrary.imports = <ImportElement>[import1, import2]; 6048 importingLibrary.imports = <ImportElement>[import1, import2];
5961 { 6049 {
5962 GatheringErrorListener errorListener = new GatheringErrorListener(); 6050 GatheringErrorListener errorListener = new GatheringErrorListener();
5963 Scope scope = new LibraryImportScope(importingLibrary, errorListener); 6051 Scope scope = new LibraryImportScope(importingLibrary, errorListener);
5964 expect(scope.lookup(AstFactory.identifier3(typeNameA), importingLibrary), 6052 expect(scope.lookup(AstFactory.identifier3(typeNameA), importingLibrary),
5965 typeA); 6053 typeA);
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
6001 GatheringErrorListener errorListener = new GatheringErrorListener(); 6089 GatheringErrorListener errorListener = new GatheringErrorListener();
6002 new LibraryImportScope(definingLibrary, errorListener); 6090 new LibraryImportScope(definingLibrary, errorListener);
6003 } 6091 }
6004 6092
6005 void test_creation_nonEmpty() { 6093 void test_creation_nonEmpty() {
6006 AnalysisContext context = AnalysisContextFactory.contextWithCore(); 6094 AnalysisContext context = AnalysisContextFactory.contextWithCore();
6007 String importedTypeName = "A"; 6095 String importedTypeName = "A";
6008 ClassElement importedType = 6096 ClassElement importedType =
6009 new ClassElementImpl.forNode(AstFactory.identifier3(importedTypeName)); 6097 new ClassElementImpl.forNode(AstFactory.identifier3(importedTypeName));
6010 LibraryElement importedLibrary = createTestLibrary(context, "imported"); 6098 LibraryElement importedLibrary = createTestLibrary(context, "imported");
6011 (importedLibrary.definingCompilationUnit as CompilationUnitElementImpl).type s = 6099 (importedLibrary.definingCompilationUnit as CompilationUnitElementImpl)
6012 <ClassElement>[importedType]; 6100 .types = <ClassElement>[importedType];
6013 LibraryElementImpl definingLibrary = 6101 LibraryElementImpl definingLibrary =
6014 createTestLibrary(context, "importing"); 6102 createTestLibrary(context, "importing");
6015 ImportElementImpl importElement = new ImportElementImpl(0); 6103 ImportElementImpl importElement = new ImportElementImpl(0);
6016 importElement.importedLibrary = importedLibrary; 6104 importElement.importedLibrary = importedLibrary;
6017 definingLibrary.imports = <ImportElement>[importElement]; 6105 definingLibrary.imports = <ImportElement>[importElement];
6018 GatheringErrorListener errorListener = new GatheringErrorListener(); 6106 GatheringErrorListener errorListener = new GatheringErrorListener();
6019 Scope scope = new LibraryImportScope(definingLibrary, errorListener); 6107 Scope scope = new LibraryImportScope(definingLibrary, errorListener);
6020 expect( 6108 expect(
6021 scope.lookup(AstFactory.identifier3(importedTypeName), definingLibrary), 6109 scope.lookup(AstFactory.identifier3(importedTypeName), definingLibrary),
6022 importedType); 6110 importedType);
6023 } 6111 }
6024 6112
6025 void test_getErrorListener() { 6113 void test_getErrorListener() {
6026 LibraryElement definingLibrary = createDefaultTestLibrary(); 6114 LibraryElement definingLibrary = createDefaultTestLibrary();
6027 GatheringErrorListener errorListener = new GatheringErrorListener(); 6115 GatheringErrorListener errorListener = new GatheringErrorListener();
6028 LibraryImportScope scope = 6116 LibraryImportScope scope =
6029 new LibraryImportScope(definingLibrary, errorListener); 6117 new LibraryImportScope(definingLibrary, errorListener);
6030 expect(scope.errorListener, errorListener); 6118 expect(scope.errorListener, errorListener);
6031 } 6119 }
6032 6120
6033 void test_nonConflictingImports_fromSdk() { 6121 void test_nonConflictingImports_fromSdk() {
6034 AnalysisContext context = AnalysisContextFactory.contextWithCore(); 6122 AnalysisContext context = AnalysisContextFactory.contextWithCore();
6035 String typeName = "List"; 6123 String typeName = "List";
6036 ClassElement type = ElementFactory.classElement2(typeName); 6124 ClassElement type = ElementFactory.classElement2(typeName);
6037 LibraryElement importedLibrary = createTestLibrary(context, "lib"); 6125 LibraryElement importedLibrary = createTestLibrary(context, "lib");
6038 (importedLibrary.definingCompilationUnit as CompilationUnitElementImpl).type s = 6126 (importedLibrary.definingCompilationUnit as CompilationUnitElementImpl)
6039 <ClassElement>[type]; 6127 .types = <ClassElement>[type];
6040 ImportElementImpl importCore = ElementFactory.importFor( 6128 ImportElementImpl importCore = ElementFactory.importFor(
6041 context.getLibraryElement(context.sourceFactory.forUri("dart:core")), 6129 context.getLibraryElement(context.sourceFactory.forUri("dart:core")),
6042 null); 6130 null);
6043 ImportElementImpl importLib = 6131 ImportElementImpl importLib =
6044 ElementFactory.importFor(importedLibrary, null); 6132 ElementFactory.importFor(importedLibrary, null);
6045 LibraryElementImpl importingLibrary = 6133 LibraryElementImpl importingLibrary =
6046 createTestLibrary(context, "importing"); 6134 createTestLibrary(context, "importing");
6047 importingLibrary.imports = <ImportElement>[importCore, importLib]; 6135 importingLibrary.imports = <ImportElement>[importCore, importLib];
6048 GatheringErrorListener errorListener = new GatheringErrorListener(); 6136 GatheringErrorListener errorListener = new GatheringErrorListener();
6049 Scope scope = new LibraryImportScope(importingLibrary, errorListener); 6137 Scope scope = new LibraryImportScope(importingLibrary, errorListener);
6050 expect( 6138 expect(
6051 scope.lookup(AstFactory.identifier3(typeName), importingLibrary), type); 6139 scope.lookup(AstFactory.identifier3(typeName), importingLibrary), type);
6052 errorListener 6140 errorListener
6053 .assertErrorsWithCodes([StaticWarningCode.CONFLICTING_DART_IMPORT]); 6141 .assertErrorsWithCodes([StaticWarningCode.CONFLICTING_DART_IMPORT]);
6054 } 6142 }
6055 6143
6056 void test_nonConflictingImports_sameElement() { 6144 void test_nonConflictingImports_sameElement() {
6057 AnalysisContext context = AnalysisContextFactory.contextWithCore(); 6145 AnalysisContext context = AnalysisContextFactory.contextWithCore();
6058 String typeNameA = "A"; 6146 String typeNameA = "A";
6059 String typeNameB = "B"; 6147 String typeNameB = "B";
6060 ClassElement typeA = ElementFactory.classElement2(typeNameA); 6148 ClassElement typeA = ElementFactory.classElement2(typeNameA);
6061 ClassElement typeB = ElementFactory.classElement2(typeNameB); 6149 ClassElement typeB = ElementFactory.classElement2(typeNameB);
6062 LibraryElement importedLibrary = createTestLibrary(context, "imported"); 6150 LibraryElement importedLibrary = createTestLibrary(context, "imported");
6063 (importedLibrary.definingCompilationUnit as CompilationUnitElementImpl).type s = 6151 (importedLibrary.definingCompilationUnit as CompilationUnitElementImpl)
6064 <ClassElement>[typeA, typeB]; 6152 .types = <ClassElement>[typeA, typeB];
6065 ImportElementImpl import1 = ElementFactory.importFor(importedLibrary, null); 6153 ImportElementImpl import1 = ElementFactory.importFor(importedLibrary, null);
6066 ImportElementImpl import2 = ElementFactory.importFor(importedLibrary, null); 6154 ImportElementImpl import2 = ElementFactory.importFor(importedLibrary, null);
6067 LibraryElementImpl importingLibrary = 6155 LibraryElementImpl importingLibrary =
6068 createTestLibrary(context, "importing"); 6156 createTestLibrary(context, "importing");
6069 importingLibrary.imports = <ImportElement>[import1, import2]; 6157 importingLibrary.imports = <ImportElement>[import1, import2];
6070 GatheringErrorListener errorListener = new GatheringErrorListener(); 6158 GatheringErrorListener errorListener = new GatheringErrorListener();
6071 Scope scope = new LibraryImportScope(importingLibrary, errorListener); 6159 Scope scope = new LibraryImportScope(importingLibrary, errorListener);
6072 expect(scope.lookup(AstFactory.identifier3(typeNameA), importingLibrary), 6160 expect(scope.lookup(AstFactory.identifier3(typeNameA), importingLibrary),
6073 typeA); 6161 typeA);
6074 errorListener.assertNoErrors(); 6162 errorListener.assertNoErrors();
6075 expect(scope.lookup(AstFactory.identifier3(typeNameB), importingLibrary), 6163 expect(scope.lookup(AstFactory.identifier3(typeNameB), importingLibrary),
6076 typeB); 6164 typeB);
6077 errorListener.assertNoErrors(); 6165 errorListener.assertNoErrors();
6078 } 6166 }
6079 6167
6080 void test_prefixedAndNonPrefixed() { 6168 void test_prefixedAndNonPrefixed() {
6081 AnalysisContext context = AnalysisContextFactory.contextWithCore(); 6169 AnalysisContext context = AnalysisContextFactory.contextWithCore();
6082 String typeName = "C"; 6170 String typeName = "C";
6083 String prefixName = "p"; 6171 String prefixName = "p";
6084 ClassElement prefixedType = ElementFactory.classElement2(typeName); 6172 ClassElement prefixedType = ElementFactory.classElement2(typeName);
6085 ClassElement nonPrefixedType = ElementFactory.classElement2(typeName); 6173 ClassElement nonPrefixedType = ElementFactory.classElement2(typeName);
6086 LibraryElement prefixedLibrary = 6174 LibraryElement prefixedLibrary =
6087 createTestLibrary(context, "import.prefixed"); 6175 createTestLibrary(context, "import.prefixed");
6088 (prefixedLibrary.definingCompilationUnit as CompilationUnitElementImpl).type s = 6176 (prefixedLibrary.definingCompilationUnit as CompilationUnitElementImpl)
6089 <ClassElement>[prefixedType]; 6177 .types = <ClassElement>[prefixedType];
6090 ImportElementImpl prefixedImport = ElementFactory.importFor( 6178 ImportElementImpl prefixedImport = ElementFactory.importFor(
6091 prefixedLibrary, ElementFactory.prefix(prefixName)); 6179 prefixedLibrary, ElementFactory.prefix(prefixName));
6092 LibraryElement nonPrefixedLibrary = 6180 LibraryElement nonPrefixedLibrary =
6093 createTestLibrary(context, "import.nonPrefixed"); 6181 createTestLibrary(context, "import.nonPrefixed");
6094 (nonPrefixedLibrary.definingCompilationUnit as CompilationUnitElementImpl).t ypes = 6182 (nonPrefixedLibrary.definingCompilationUnit as CompilationUnitElementImpl)
6095 <ClassElement>[nonPrefixedType]; 6183 .types = <ClassElement>[nonPrefixedType];
6096 ImportElementImpl nonPrefixedImport = 6184 ImportElementImpl nonPrefixedImport =
6097 ElementFactory.importFor(nonPrefixedLibrary, null); 6185 ElementFactory.importFor(nonPrefixedLibrary, null);
6098 LibraryElementImpl importingLibrary = 6186 LibraryElementImpl importingLibrary =
6099 createTestLibrary(context, "importing"); 6187 createTestLibrary(context, "importing");
6100 importingLibrary.imports = <ImportElement>[ 6188 importingLibrary.imports = <ImportElement>[
6101 prefixedImport, 6189 prefixedImport,
6102 nonPrefixedImport 6190 nonPrefixedImport
6103 ]; 6191 ];
6104 GatheringErrorListener errorListener = new GatheringErrorListener(); 6192 GatheringErrorListener errorListener = new GatheringErrorListener();
6105 Scope scope = new LibraryImportScope(importingLibrary, errorListener); 6193 Scope scope = new LibraryImportScope(importingLibrary, errorListener);
(...skipping 24 matching lines...) Expand all
6130 analysisContext2.sourceFactory.forUri(DartSdk.DART_CORE); 6218 analysisContext2.sourceFactory.forUri(DartSdk.DART_CORE);
6131 _asyncLibrarySource = 6219 _asyncLibrarySource =
6132 analysisContext2.sourceFactory.forUri(DartSdk.DART_ASYNC); 6220 analysisContext2.sourceFactory.forUri(DartSdk.DART_ASYNC);
6133 } 6221 }
6134 6222
6135 void test_imports_relative() { 6223 void test_imports_relative() {
6136 Source sourceA = addSource(r''' 6224 Source sourceA = addSource(r'''
6137 library libA; 6225 library libA;
6138 import 'libB.dart'; 6226 import 'libB.dart';
6139 class A {}'''); 6227 class A {}''');
6140 Source sourceB = addNamedSource("/libB.dart", r''' 6228 Source sourceB = addNamedSource(
6229 "/libB.dart",
6230 r'''
6141 library libB; 6231 library libB;
6142 import 'test.dart 6232 import 'test.dart
6143 class B {}'''); 6233 class B {}''');
6144 List<ResolvableLibrary> cycle = new List<ResolvableLibrary>(); 6234 List<ResolvableLibrary> cycle = new List<ResolvableLibrary>();
6145 ResolvableLibrary coreLib = _createResolvableLibrary(_coreLibrarySource); 6235 ResolvableLibrary coreLib = _createResolvableLibrary(_coreLibrarySource);
6146 coreLib.libraryElement = analysisContext2 6236 coreLib.libraryElement = analysisContext2
6147 .computeLibraryElement(_coreLibrarySource) as LibraryElementImpl; 6237 .computeLibraryElement(_coreLibrarySource) as LibraryElementImpl;
6148 ResolvableLibrary asyncLib = _createResolvableLibrary(_asyncLibrarySource); 6238 ResolvableLibrary asyncLib = _createResolvableLibrary(_asyncLibrarySource);
6149 asyncLib.libraryElement = analysisContext2 6239 asyncLib.libraryElement = analysisContext2
6150 .computeLibraryElement(_asyncLibrarySource) as LibraryElementImpl; 6240 .computeLibraryElement(_asyncLibrarySource) as LibraryElementImpl;
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
6217 GatheringErrorListener errorListener = new GatheringErrorListener(); 6307 GatheringErrorListener errorListener = new GatheringErrorListener();
6218 new LibraryScope(definingLibrary, errorListener); 6308 new LibraryScope(definingLibrary, errorListener);
6219 } 6309 }
6220 6310
6221 void test_creation_nonEmpty() { 6311 void test_creation_nonEmpty() {
6222 AnalysisContext context = AnalysisContextFactory.contextWithCore(); 6312 AnalysisContext context = AnalysisContextFactory.contextWithCore();
6223 String importedTypeName = "A"; 6313 String importedTypeName = "A";
6224 ClassElement importedType = 6314 ClassElement importedType =
6225 new ClassElementImpl.forNode(AstFactory.identifier3(importedTypeName)); 6315 new ClassElementImpl.forNode(AstFactory.identifier3(importedTypeName));
6226 LibraryElement importedLibrary = createTestLibrary(context, "imported"); 6316 LibraryElement importedLibrary = createTestLibrary(context, "imported");
6227 (importedLibrary.definingCompilationUnit as CompilationUnitElementImpl).type s = 6317 (importedLibrary.definingCompilationUnit as CompilationUnitElementImpl)
6228 <ClassElement>[importedType]; 6318 .types = <ClassElement>[importedType];
6229 LibraryElementImpl definingLibrary = 6319 LibraryElementImpl definingLibrary =
6230 createTestLibrary(context, "importing"); 6320 createTestLibrary(context, "importing");
6231 ImportElementImpl importElement = new ImportElementImpl(0); 6321 ImportElementImpl importElement = new ImportElementImpl(0);
6232 importElement.importedLibrary = importedLibrary; 6322 importElement.importedLibrary = importedLibrary;
6233 definingLibrary.imports = <ImportElement>[importElement]; 6323 definingLibrary.imports = <ImportElement>[importElement];
6234 GatheringErrorListener errorListener = new GatheringErrorListener(); 6324 GatheringErrorListener errorListener = new GatheringErrorListener();
6235 Scope scope = new LibraryScope(definingLibrary, errorListener); 6325 Scope scope = new LibraryScope(definingLibrary, errorListener);
6236 expect( 6326 expect(
6237 scope.lookup(AstFactory.identifier3(importedTypeName), definingLibrary), 6327 scope.lookup(AstFactory.identifier3(importedTypeName), definingLibrary),
6238 importedType); 6328 importedType);
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
6339 } 6429 }
6340 6430
6341 void test_setLibraryElement() { 6431 void test_setLibraryElement() {
6342 LibraryElementImpl element = new LibraryElementImpl.forNode( 6432 LibraryElementImpl element = new LibraryElementImpl.forNode(
6343 _analysisContext, AstFactory.libraryIdentifier2(["lib"])); 6433 _analysisContext, AstFactory.libraryIdentifier2(["lib"]));
6344 _library.libraryElement = element; 6434 _library.libraryElement = element;
6345 expect(_library.libraryElement, same(element)); 6435 expect(_library.libraryElement, same(element));
6346 } 6436 }
6347 6437
6348 Library _createLibrary(String definingCompilationUnitPath) => new Library( 6438 Library _createLibrary(String definingCompilationUnitPath) => new Library(
6349 _analysisContext, _errorListener, new FileBasedSource( 6439 _analysisContext,
6440 _errorListener,
6441 new FileBasedSource(
6350 FileUtilities2.createFile(definingCompilationUnitPath))); 6442 FileUtilities2.createFile(definingCompilationUnitPath)));
6351 } 6443 }
6352 6444
6353 @reflectiveTest 6445 @reflectiveTest
6354 class MemberMapTest { 6446 class MemberMapTest {
6355 /** 6447 /**
6356 * The null type. 6448 * The null type.
6357 */ 6449 */
6358 InterfaceType _nullType; 6450 InterfaceType _nullType;
6359 6451
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
6499 verify([source]); 6591 verify([source]);
6500 } 6592 }
6501 6593
6502 void test_deadCode_deadBlock_if_debugConst_prefixedIdentifier2() { 6594 void test_deadCode_deadBlock_if_debugConst_prefixedIdentifier2() {
6503 Source source = addSource(r''' 6595 Source source = addSource(r'''
6504 library L; 6596 library L;
6505 import 'lib2.dart'; 6597 import 'lib2.dart';
6506 f() { 6598 f() {
6507 if(A.DEBUG) {} 6599 if(A.DEBUG) {}
6508 }'''); 6600 }''');
6509 addNamedSource("/lib2.dart", r''' 6601 addNamedSource(
6602 "/lib2.dart",
6603 r'''
6510 library lib2; 6604 library lib2;
6511 class A { 6605 class A {
6512 static const bool DEBUG = false; 6606 static const bool DEBUG = false;
6513 }'''); 6607 }''');
6514 computeLibrarySourceErrors(source); 6608 computeLibrarySourceErrors(source);
6515 assertNoErrors(source); 6609 assertNoErrors(source);
6516 verify([source]); 6610 verify([source]);
6517 } 6611 }
6518 6612
6519 void test_deadCode_deadBlock_if_debugConst_propertyAccessor() { 6613 void test_deadCode_deadBlock_if_debugConst_propertyAccessor() {
6520 Source source = addSource(r''' 6614 Source source = addSource(r'''
6521 library L; 6615 library L;
6522 import 'lib2.dart' as LIB; 6616 import 'lib2.dart' as LIB;
6523 f() { 6617 f() {
6524 if(LIB.A.DEBUG) {} 6618 if(LIB.A.DEBUG) {}
6525 }'''); 6619 }''');
6526 addNamedSource("/lib2.dart", r''' 6620 addNamedSource(
6621 "/lib2.dart",
6622 r'''
6527 library lib2; 6623 library lib2;
6528 class A { 6624 class A {
6529 static const bool DEBUG = false; 6625 static const bool DEBUG = false;
6530 }'''); 6626 }''');
6531 computeLibrarySourceErrors(source); 6627 computeLibrarySourceErrors(source);
6532 assertNoErrors(source); 6628 assertNoErrors(source);
6533 verify([source]); 6629 verify([source]);
6534 } 6630 }
6535 6631
6536 void test_deadCode_deadBlock_if_debugConst_simpleIdentifier() { 6632 void test_deadCode_deadBlock_if_debugConst_simpleIdentifier() {
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
6622 verify([source]); 6718 verify([source]);
6623 } 6719 }
6624 6720
6625 void test_duplicateImport_as() { 6721 void test_duplicateImport_as() {
6626 Source source = addSource(r''' 6722 Source source = addSource(r'''
6627 library L; 6723 library L;
6628 import 'lib1.dart'; 6724 import 'lib1.dart';
6629 import 'lib1.dart' as one; 6725 import 'lib1.dart' as one;
6630 A a; 6726 A a;
6631 one.A a2;'''); 6727 one.A a2;''');
6632 addNamedSource("/lib1.dart", r''' 6728 addNamedSource(
6729 "/lib1.dart",
6730 r'''
6633 library lib1; 6731 library lib1;
6634 class A {}'''); 6732 class A {}''');
6635 computeLibrarySourceErrors(source); 6733 computeLibrarySourceErrors(source);
6636 assertNoErrors(source); 6734 assertNoErrors(source);
6637 verify([source]); 6735 verify([source]);
6638 } 6736 }
6639 6737
6640 void test_duplicateImport_hide() { 6738 void test_duplicateImport_hide() {
6641 Source source = addSource(r''' 6739 Source source = addSource(r'''
6642 library L; 6740 library L;
6643 import 'lib1.dart'; 6741 import 'lib1.dart';
6644 import 'lib1.dart' hide A; 6742 import 'lib1.dart' hide A;
6645 A a; 6743 A a;
6646 B b;'''); 6744 B b;''');
6647 addNamedSource("/lib1.dart", r''' 6745 addNamedSource(
6746 "/lib1.dart",
6747 r'''
6648 library lib1; 6748 library lib1;
6649 class A {} 6749 class A {}
6650 class B {}'''); 6750 class B {}''');
6651 computeLibrarySourceErrors(source); 6751 computeLibrarySourceErrors(source);
6652 assertNoErrors(source); 6752 assertNoErrors(source);
6653 verify([source]); 6753 verify([source]);
6654 } 6754 }
6655 6755
6656 void test_duplicateImport_show() { 6756 void test_duplicateImport_show() {
6657 Source source = addSource(r''' 6757 Source source = addSource(r'''
6658 library L; 6758 library L;
6659 import 'lib1.dart'; 6759 import 'lib1.dart';
6660 import 'lib1.dart' show A; 6760 import 'lib1.dart' show A;
6661 A a; 6761 A a;
6662 B b;'''); 6762 B b;''');
6663 addNamedSource("/lib1.dart", r''' 6763 addNamedSource(
6764 "/lib1.dart",
6765 r'''
6664 library lib1; 6766 library lib1;
6665 class A {} 6767 class A {}
6666 class B {}'''); 6768 class B {}''');
6667 computeLibrarySourceErrors(source); 6769 computeLibrarySourceErrors(source);
6668 assertNoErrors(source); 6770 assertNoErrors(source);
6669 verify([source]); 6771 verify([source]);
6670 } 6772 }
6671 6773
6672 void test_importDeferredLibraryWithLoadFunction() { 6774 void test_importDeferredLibraryWithLoadFunction() {
6673 resolveWithErrors(<String>[ 6775 resolveWithErrors(<String>[
(...skipping 527 matching lines...) Expand 10 before | Expand all | Expand 10 after
7201 computeLibrarySourceErrors(source); 7303 computeLibrarySourceErrors(source);
7202 assertNoErrors(source); 7304 assertNoErrors(source);
7203 verify([source]); 7305 verify([source]);
7204 } 7306 }
7205 7307
7206 void test_unusedImport_annotationOnDirective() { 7308 void test_unusedImport_annotationOnDirective() {
7207 Source source = addSource(r''' 7309 Source source = addSource(r'''
7208 library L; 7310 library L;
7209 @A() 7311 @A()
7210 import 'lib1.dart';'''); 7312 import 'lib1.dart';''');
7211 Source source2 = addNamedSource("/lib1.dart", r''' 7313 Source source2 = addNamedSource(
7314 "/lib1.dart",
7315 r'''
7212 library lib1; 7316 library lib1;
7213 class A { 7317 class A {
7214 const A() {} 7318 const A() {}
7215 }'''); 7319 }''');
7216 computeLibrarySourceErrors(source); 7320 computeLibrarySourceErrors(source);
7217 assertErrors(source); 7321 assertErrors(source);
7218 verify([source, source2]); 7322 verify([source, source2]);
7219 } 7323 }
7220 7324
7221 void test_unusedImport_as_equalPrefixes() { 7325 void test_unusedImport_as_equalPrefixes() {
7222 // 18818 7326 // 18818
7223 Source source = addSource(r''' 7327 Source source = addSource(r'''
7224 library L; 7328 library L;
7225 import 'lib1.dart' as one; 7329 import 'lib1.dart' as one;
7226 import 'lib2.dart' as one; 7330 import 'lib2.dart' as one;
7227 one.A a; 7331 one.A a;
7228 one.B b;'''); 7332 one.B b;''');
7229 Source source2 = addNamedSource("/lib1.dart", r''' 7333 Source source2 = addNamedSource(
7334 "/lib1.dart",
7335 r'''
7230 library lib1; 7336 library lib1;
7231 class A {}'''); 7337 class A {}''');
7232 Source source3 = addNamedSource("/lib2.dart", r''' 7338 Source source3 = addNamedSource(
7339 "/lib2.dart",
7340 r'''
7233 library lib2; 7341 library lib2;
7234 class B {}'''); 7342 class B {}''');
7235 computeLibrarySourceErrors(source); 7343 computeLibrarySourceErrors(source);
7236 assertErrors(source); 7344 assertErrors(source);
7237 assertNoErrors(source2); 7345 assertNoErrors(source2);
7238 assertNoErrors(source3); 7346 assertNoErrors(source3);
7239 verify([source, source2, source3]); 7347 verify([source, source2, source3]);
7240 } 7348 }
7241 7349
7242 void test_unusedImport_core_library() { 7350 void test_unusedImport_core_library() {
7243 Source source = addSource(r''' 7351 Source source = addSource(r'''
7244 library L; 7352 library L;
7245 import 'dart:core';'''); 7353 import 'dart:core';''');
7246 computeLibrarySourceErrors(source); 7354 computeLibrarySourceErrors(source);
7247 assertNoErrors(source); 7355 assertNoErrors(source);
7248 verify([source]); 7356 verify([source]);
7249 } 7357 }
7250 7358
7251 void test_unusedImport_export() { 7359 void test_unusedImport_export() {
7252 Source source = addSource(r''' 7360 Source source = addSource(r'''
7253 library L; 7361 library L;
7254 import 'lib1.dart'; 7362 import 'lib1.dart';
7255 Two two;'''); 7363 Two two;''');
7256 addNamedSource("/lib1.dart", r''' 7364 addNamedSource(
7365 "/lib1.dart",
7366 r'''
7257 library lib1; 7367 library lib1;
7258 export 'lib2.dart'; 7368 export 'lib2.dart';
7259 class One {}'''); 7369 class One {}''');
7260 addNamedSource("/lib2.dart", r''' 7370 addNamedSource(
7371 "/lib2.dart",
7372 r'''
7261 library lib2; 7373 library lib2;
7262 class Two {}'''); 7374 class Two {}''');
7263 computeLibrarySourceErrors(source); 7375 computeLibrarySourceErrors(source);
7264 assertNoErrors(source); 7376 assertNoErrors(source);
7265 verify([source]); 7377 verify([source]);
7266 } 7378 }
7267 7379
7268 void test_unusedImport_export2() { 7380 void test_unusedImport_export2() {
7269 Source source = addSource(r''' 7381 Source source = addSource(r'''
7270 library L; 7382 library L;
7271 import 'lib1.dart'; 7383 import 'lib1.dart';
7272 Three three;'''); 7384 Three three;''');
7273 addNamedSource("/lib1.dart", r''' 7385 addNamedSource(
7386 "/lib1.dart",
7387 r'''
7274 library lib1; 7388 library lib1;
7275 export 'lib2.dart'; 7389 export 'lib2.dart';
7276 class One {}'''); 7390 class One {}''');
7277 addNamedSource("/lib2.dart", r''' 7391 addNamedSource(
7392 "/lib2.dart",
7393 r'''
7278 library lib2; 7394 library lib2;
7279 export 'lib3.dart'; 7395 export 'lib3.dart';
7280 class Two {}'''); 7396 class Two {}''');
7281 addNamedSource("/lib3.dart", r''' 7397 addNamedSource(
7398 "/lib3.dart",
7399 r'''
7282 library lib3; 7400 library lib3;
7283 class Three {}'''); 7401 class Three {}''');
7284 computeLibrarySourceErrors(source); 7402 computeLibrarySourceErrors(source);
7285 assertNoErrors(source); 7403 assertNoErrors(source);
7286 verify([source]); 7404 verify([source]);
7287 } 7405 }
7288 7406
7289 void test_unusedImport_export_infiniteLoop() { 7407 void test_unusedImport_export_infiniteLoop() {
7290 Source source = addSource(r''' 7408 Source source = addSource(r'''
7291 library L; 7409 library L;
7292 import 'lib1.dart'; 7410 import 'lib1.dart';
7293 Two two;'''); 7411 Two two;''');
7294 addNamedSource("/lib1.dart", r''' 7412 addNamedSource(
7413 "/lib1.dart",
7414 r'''
7295 library lib1; 7415 library lib1;
7296 export 'lib2.dart'; 7416 export 'lib2.dart';
7297 class One {}'''); 7417 class One {}''');
7298 addNamedSource("/lib2.dart", r''' 7418 addNamedSource(
7419 "/lib2.dart",
7420 r'''
7299 library lib2; 7421 library lib2;
7300 export 'lib3.dart'; 7422 export 'lib3.dart';
7301 class Two {}'''); 7423 class Two {}''');
7302 addNamedSource("/lib3.dart", r''' 7424 addNamedSource(
7425 "/lib3.dart",
7426 r'''
7303 library lib3; 7427 library lib3;
7304 export 'lib2.dart'; 7428 export 'lib2.dart';
7305 class Three {}'''); 7429 class Three {}''');
7306 computeLibrarySourceErrors(source); 7430 computeLibrarySourceErrors(source);
7307 assertNoErrors(source); 7431 assertNoErrors(source);
7308 verify([source]); 7432 verify([source]);
7309 } 7433 }
7310 7434
7311 void test_unusedImport_metadata() { 7435 void test_unusedImport_metadata() {
7312 Source source = addSource(r''' 7436 Source source = addSource(r'''
7313 library L; 7437 library L;
7314 @A(x) 7438 @A(x)
7315 import 'lib1.dart'; 7439 import 'lib1.dart';
7316 class A { 7440 class A {
7317 final int value; 7441 final int value;
7318 const A(this.value); 7442 const A(this.value);
7319 }'''); 7443 }''');
7320 addNamedSource("/lib1.dart", r''' 7444 addNamedSource(
7445 "/lib1.dart",
7446 r'''
7321 library lib1; 7447 library lib1;
7322 const x = 0;'''); 7448 const x = 0;''');
7323 computeLibrarySourceErrors(source); 7449 computeLibrarySourceErrors(source);
7324 assertNoErrors(source); 7450 assertNoErrors(source);
7325 verify([source]); 7451 verify([source]);
7326 } 7452 }
7327 7453
7328 void test_unusedImport_prefix_topLevelFunction() { 7454 void test_unusedImport_prefix_topLevelFunction() {
7329 Source source = addSource(r''' 7455 Source source = addSource(r'''
7330 library L; 7456 library L;
7331 import 'lib1.dart' hide topLevelFunction; 7457 import 'lib1.dart' hide topLevelFunction;
7332 import 'lib1.dart' as one show topLevelFunction; 7458 import 'lib1.dart' as one show topLevelFunction;
7333 class A { 7459 class A {
7334 static void x() { 7460 static void x() {
7335 One o; 7461 One o;
7336 one.topLevelFunction(); 7462 one.topLevelFunction();
7337 } 7463 }
7338 }'''); 7464 }''');
7339 addNamedSource("/lib1.dart", r''' 7465 addNamedSource(
7466 "/lib1.dart",
7467 r'''
7340 library lib1; 7468 library lib1;
7341 class One {} 7469 class One {}
7342 topLevelFunction() {}'''); 7470 topLevelFunction() {}''');
7343 computeLibrarySourceErrors(source); 7471 computeLibrarySourceErrors(source);
7344 assertNoErrors(source); 7472 assertNoErrors(source);
7345 verify([source]); 7473 verify([source]);
7346 } 7474 }
7347 7475
7348 void test_useOfVoidResult_implicitReturnValue() { 7476 void test_useOfVoidResult_implicitReturnValue() {
7349 Source source = addSource(r''' 7477 Source source = addSource(r'''
(...skipping 503 matching lines...) Expand 10 before | Expand all | Expand 10 after
7853 createTestLibrary(AnalysisContextFactory.contextWithCore(), "test"); 7981 createTestLibrary(AnalysisContextFactory.contextWithCore(), "test");
7854 7982
7855 /** 7983 /**
7856 * Create a library element that represents a library with the given name cont aining a single 7984 * Create a library element that represents a library with the given name cont aining a single
7857 * empty compilation unit. 7985 * empty compilation unit.
7858 * 7986 *
7859 * @param libraryName the name of the library to be created 7987 * @param libraryName the name of the library to be created
7860 * @return the library element that was created 7988 * @return the library element that was created
7861 */ 7989 */
7862 LibraryElementImpl createTestLibrary( 7990 LibraryElementImpl createTestLibrary(
7863 AnalysisContext context, String libraryName, [List<String> typeNames]) { 7991 AnalysisContext context, String libraryName,
7992 [List<String> typeNames]) {
7864 String fileName = "$libraryName.dart"; 7993 String fileName = "$libraryName.dart";
7865 FileBasedSource definingCompilationUnitSource = 7994 FileBasedSource definingCompilationUnitSource =
7866 _createNamedSource(fileName); 7995 _createNamedSource(fileName);
7867 List<CompilationUnitElement> sourcedCompilationUnits; 7996 List<CompilationUnitElement> sourcedCompilationUnits;
7868 if (typeNames == null) { 7997 if (typeNames == null) {
7869 sourcedCompilationUnits = CompilationUnitElement.EMPTY_LIST; 7998 sourcedCompilationUnits = CompilationUnitElement.EMPTY_LIST;
7870 } else { 7999 } else {
7871 int count = typeNames.length; 8000 int count = typeNames.length;
7872 sourcedCompilationUnits = new List<CompilationUnitElement>(count); 8001 sourcedCompilationUnits = new List<CompilationUnitElement>(count);
7873 for (int i = 0; i < count; i++) { 8002 for (int i = 0; i < count; i++) {
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
7969 CompilationUnit unit = 8098 CompilationUnit unit =
7970 resolveSource2("/lib${i + 1}.dart", sourceTexts[i]); 8099 resolveSource2("/lib${i + 1}.dart", sourceTexts[i]);
7971 // reference the source if this is the last source 8100 // reference the source if this is the last source
7972 if (i + 1 == sourceTexts.length) { 8101 if (i + 1 == sourceTexts.length) {
7973 return unit.element.source; 8102 return unit.element.source;
7974 } 8103 }
7975 } 8104 }
7976 return null; 8105 return null;
7977 } 8106 }
7978 8107
7979 void resolveWithAndWithoutExperimental(List<String> strSources, 8108 void resolveWithAndWithoutExperimental(
8109 List<String> strSources,
7980 List<ErrorCode> codesWithoutExperimental, 8110 List<ErrorCode> codesWithoutExperimental,
7981 List<ErrorCode> codesWithExperimental) { 8111 List<ErrorCode> codesWithExperimental) {
7982 // Setup analysis context as non-experimental 8112 // Setup analysis context as non-experimental
7983 AnalysisOptionsImpl options = new AnalysisOptionsImpl(); 8113 AnalysisOptionsImpl options = new AnalysisOptionsImpl();
7984 // options.enableDeferredLoading = false; 8114 // options.enableDeferredLoading = false;
7985 resetWithOptions(options); 8115 resetWithOptions(options);
7986 // Analysis and assertions 8116 // Analysis and assertions
7987 Source source = resolveSources(strSources); 8117 Source source = resolveSources(strSources);
7988 assertErrors(source, codesWithoutExperimental); 8118 assertErrors(source, codesWithoutExperimental);
7989 verify([source]); 8119 verify([source]);
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
8045 class Scope_EnclosedScopeTest_test_define_duplicate extends Scope { 8175 class Scope_EnclosedScopeTest_test_define_duplicate extends Scope {
8046 GatheringErrorListener listener; 8176 GatheringErrorListener listener;
8047 8177
8048 Scope_EnclosedScopeTest_test_define_duplicate(this.listener) : super(); 8178 Scope_EnclosedScopeTest_test_define_duplicate(this.listener) : super();
8049 8179
8050 @override 8180 @override
8051 AnalysisErrorListener get errorListener => listener; 8181 AnalysisErrorListener get errorListener => listener;
8052 8182
8053 @override 8183 @override
8054 Element internalLookup(Identifier identifier, String name, 8184 Element internalLookup(Identifier identifier, String name,
8055 LibraryElement referencingLibrary) => null; 8185 LibraryElement referencingLibrary) =>
8186 null;
8056 } 8187 }
8057 8188
8058 class Scope_EnclosedScopeTest_test_define_normal extends Scope { 8189 class Scope_EnclosedScopeTest_test_define_normal extends Scope {
8059 GatheringErrorListener listener; 8190 GatheringErrorListener listener;
8060 8191
8061 Scope_EnclosedScopeTest_test_define_normal(this.listener) : super(); 8192 Scope_EnclosedScopeTest_test_define_normal(this.listener) : super();
8062 8193
8063 @override 8194 @override
8064 AnalysisErrorListener get errorListener => listener; 8195 AnalysisErrorListener get errorListener => listener;
8065 8196
8066 @override 8197 @override
8067 Element internalLookup(Identifier identifier, String name, 8198 Element internalLookup(Identifier identifier, String name,
8068 LibraryElement referencingLibrary) => null; 8199 LibraryElement referencingLibrary) =>
8200 null;
8069 } 8201 }
8070 8202
8071 @reflectiveTest 8203 @reflectiveTest
8072 class ScopeTest extends ResolverTestCase { 8204 class ScopeTest extends ResolverTestCase {
8073 void test_define_duplicate() { 8205 void test_define_duplicate() {
8074 GatheringErrorListener errorListener = new GatheringErrorListener(); 8206 GatheringErrorListener errorListener = new GatheringErrorListener();
8075 ScopeTest_TestScope scope = new ScopeTest_TestScope(errorListener); 8207 ScopeTest_TestScope scope = new ScopeTest_TestScope(errorListener);
8076 VariableElement element1 = 8208 VariableElement element1 =
8077 ElementFactory.localVariableElement(AstFactory.identifier3("v1")); 8209 ElementFactory.localVariableElement(AstFactory.identifier3("v1"));
8078 VariableElement element2 = 8210 VariableElement element2 =
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
8154 // the accessors defined in M2. 8286 // the accessors defined in M2.
8155 FunctionDeclaration main = 8287 FunctionDeclaration main =
8156 library.definingCompilationUnit.functions[0].computeNode(); 8288 library.definingCompilationUnit.functions[0].computeNode();
8157 BlockFunctionBody body = main.functionExpression.body; 8289 BlockFunctionBody body = main.functionExpression.body;
8158 ExpressionStatement stmt = body.block.statements[0]; 8290 ExpressionStatement stmt = body.block.statements[0];
8159 AssignmentExpression assignment = stmt.expression; 8291 AssignmentExpression assignment = stmt.expression;
8160 PropertyAccess propertyAccess = assignment.leftHandSide; 8292 PropertyAccess propertyAccess = assignment.leftHandSide;
8161 expect( 8293 expect(
8162 propertyAccess.propertyName.staticElement.enclosingElement.name, 'M2'); 8294 propertyAccess.propertyName.staticElement.enclosingElement.name, 'M2');
8163 expect( 8295 expect(
8164 propertyAccess.propertyName.auxiliaryElements.staticElement.enclosingEle ment.name, 8296 propertyAccess
8297 .propertyName.auxiliaryElements.staticElement.enclosingElement.name,
8165 'M2'); 8298 'M2');
8166 } 8299 }
8167 8300
8168 void fail_staticInvocation() { 8301 void fail_staticInvocation() {
8169 Source source = addSource(r''' 8302 Source source = addSource(r'''
8170 class A { 8303 class A {
8171 static int get g => (a,b) => 0; 8304 static int get g => (a,b) => 0;
8172 } 8305 }
8173 class B { 8306 class B {
8174 f() { 8307 f() {
(...skipping 554 matching lines...) Expand 10 before | Expand all | Expand 10 after
8729 } 8862 }
8730 8863
8731 void test_empty() { 8864 void test_empty() {
8732 Source source = addSource(""); 8865 Source source = addSource("");
8733 computeLibrarySourceErrors(source); 8866 computeLibrarySourceErrors(source);
8734 assertNoErrors(source); 8867 assertNoErrors(source);
8735 verify([source]); 8868 verify([source]);
8736 } 8869 }
8737 8870
8738 void test_entryPoint_exported() { 8871 void test_entryPoint_exported() {
8739 addNamedSource("/two.dart", r''' 8872 addNamedSource(
8873 "/two.dart",
8874 r'''
8740 library two; 8875 library two;
8741 main() {}'''); 8876 main() {}''');
8742 Source source = addNamedSource("/one.dart", r''' 8877 Source source = addNamedSource(
8878 "/one.dart",
8879 r'''
8743 library one; 8880 library one;
8744 export 'two.dart';'''); 8881 export 'two.dart';''');
8745 LibraryElement library = resolve2(source); 8882 LibraryElement library = resolve2(source);
8746 expect(library, isNotNull); 8883 expect(library, isNotNull);
8747 FunctionElement main = library.entryPoint; 8884 FunctionElement main = library.entryPoint;
8748 expect(main, isNotNull); 8885 expect(main, isNotNull);
8749 expect(main.library, isNot(same(library))); 8886 expect(main.library, isNot(same(library)));
8750 assertNoErrors(source); 8887 assertNoErrors(source);
8751 verify([source]); 8888 verify([source]);
8752 } 8889 }
8753 8890
8754 void test_entryPoint_local() { 8891 void test_entryPoint_local() {
8755 Source source = addNamedSource("/one.dart", r''' 8892 Source source = addNamedSource(
8893 "/one.dart",
8894 r'''
8756 library one; 8895 library one;
8757 main() {}'''); 8896 main() {}''');
8758 LibraryElement library = resolve2(source); 8897 LibraryElement library = resolve2(source);
8759 expect(library, isNotNull); 8898 expect(library, isNotNull);
8760 FunctionElement main = library.entryPoint; 8899 FunctionElement main = library.entryPoint;
8761 expect(main, isNotNull); 8900 expect(main, isNotNull);
8762 expect(main.library, same(library)); 8901 expect(main.library, same(library));
8763 assertNoErrors(source); 8902 assertNoErrors(source);
8764 verify([source]); 8903 verify([source]);
8765 } 8904 }
8766 8905
8767 void test_entryPoint_none() { 8906 void test_entryPoint_none() {
8768 Source source = addNamedSource("/one.dart", "library one;"); 8907 Source source = addNamedSource("/one.dart", "library one;");
8769 LibraryElement library = resolve2(source); 8908 LibraryElement library = resolve2(source);
8770 expect(library, isNotNull); 8909 expect(library, isNotNull);
8771 expect(library.entryPoint, isNull); 8910 expect(library.entryPoint, isNull);
8772 assertNoErrors(source); 8911 assertNoErrors(source);
8773 verify([source]); 8912 verify([source]);
8774 } 8913 }
8775 8914
8776 void test_enum_externalLibrary() { 8915 void test_enum_externalLibrary() {
8777 addNamedSource("/my_lib.dart", r''' 8916 addNamedSource(
8917 "/my_lib.dart",
8918 r'''
8778 library my_lib; 8919 library my_lib;
8779 enum EEE {A, B, C}'''); 8920 enum EEE {A, B, C}''');
8780 Source source = addSource(r''' 8921 Source source = addSource(r'''
8781 import 'my_lib.dart'; 8922 import 'my_lib.dart';
8782 main() { 8923 main() {
8783 EEE e = null; 8924 EEE e = null;
8784 }'''); 8925 }''');
8785 computeLibrarySourceErrors(source); 8926 computeLibrarySourceErrors(source);
8786 assertNoErrors(source); 8927 assertNoErrors(source);
8787 verify([source]); 8928 verify([source]);
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
8965 expect(unit, isNotNull); 9106 expect(unit, isNotNull);
8966 List<ClassElement> classes = unit.types; 9107 List<ClassElement> classes = unit.types;
8967 expect(classes, hasLength(2)); 9108 expect(classes, hasLength(2));
8968 expect(classes[0].hasReferenceToSuper, isFalse); 9109 expect(classes[0].hasReferenceToSuper, isFalse);
8969 expect(classes[1].hasReferenceToSuper, isTrue); 9110 expect(classes[1].hasReferenceToSuper, isTrue);
8970 assertNoErrors(source); 9111 assertNoErrors(source);
8971 verify([source]); 9112 verify([source]);
8972 } 9113 }
8973 9114
8974 void test_import_hide() { 9115 void test_import_hide() {
8975 addNamedSource("lib1.dart", r''' 9116 addNamedSource(
9117 "lib1.dart",
9118 r'''
8976 library lib1; 9119 library lib1;
8977 set foo(value) {} 9120 set foo(value) {}
8978 class A {}'''); 9121 class A {}''');
8979 addNamedSource("lib2.dart", r''' 9122 addNamedSource(
9123 "lib2.dart",
9124 r'''
8980 library lib2; 9125 library lib2;
8981 set foo(value) {}'''); 9126 set foo(value) {}''');
8982 Source source = addNamedSource("lib3.dart", r''' 9127 Source source = addNamedSource(
9128 "lib3.dart",
9129 r'''
8983 import 'lib1.dart' hide foo; 9130 import 'lib1.dart' hide foo;
8984 import 'lib2.dart'; 9131 import 'lib2.dart';
8985 9132
8986 main() { 9133 main() {
8987 foo = 0; 9134 foo = 0;
8988 } 9135 }
8989 A a;'''); 9136 A a;''');
8990 computeLibrarySourceErrors(source); 9137 computeLibrarySourceErrors(source);
8991 assertNoErrors(source); 9138 assertNoErrors(source);
8992 verify([source]); 9139 verify([source]);
8993 } 9140 }
8994 9141
8995 void test_import_prefix() { 9142 void test_import_prefix() {
8996 addNamedSource("/two.dart", r''' 9143 addNamedSource(
9144 "/two.dart",
9145 r'''
8997 library two; 9146 library two;
8998 f(int x) { 9147 f(int x) {
8999 return x * x; 9148 return x * x;
9000 }'''); 9149 }''');
9001 Source source = addNamedSource("/one.dart", r''' 9150 Source source = addNamedSource(
9151 "/one.dart",
9152 r'''
9002 library one; 9153 library one;
9003 import 'two.dart' as _two; 9154 import 'two.dart' as _two;
9004 main() { 9155 main() {
9005 _two.f(0); 9156 _two.f(0);
9006 }'''); 9157 }''');
9007 computeLibrarySourceErrors(source); 9158 computeLibrarySourceErrors(source);
9008 assertNoErrors(source); 9159 assertNoErrors(source);
9009 verify([source]); 9160 verify([source]);
9010 } 9161 }
9011 9162
9012 void test_import_spaceInUri() { 9163 void test_import_spaceInUri() {
9013 addNamedSource("sub folder/lib.dart", r''' 9164 addNamedSource(
9165 "sub folder/lib.dart",
9166 r'''
9014 library lib; 9167 library lib;
9015 foo() {}'''); 9168 foo() {}''');
9016 Source source = addNamedSource("app.dart", r''' 9169 Source source = addNamedSource(
9170 "app.dart",
9171 r'''
9017 import 'sub folder/lib.dart'; 9172 import 'sub folder/lib.dart';
9018 9173
9019 main() { 9174 main() {
9020 foo(); 9175 foo();
9021 }'''); 9176 }''');
9022 computeLibrarySourceErrors(source); 9177 computeLibrarySourceErrors(source);
9023 assertNoErrors(source); 9178 assertNoErrors(source);
9024 verify([source]); 9179 verify([source]);
9025 } 9180 }
9026 9181
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
9198 expect(unitElement, isNotNull); 9353 expect(unitElement, isNotNull);
9199 List<ClassElement> classes = unitElement.types; 9354 List<ClassElement> classes = unitElement.types;
9200 expect(classes, hasLength(1)); 9355 expect(classes, hasLength(1));
9201 List<ElementAnnotation> annotations = classes[0].metadata; 9356 List<ElementAnnotation> annotations = classes[0].metadata;
9202 expect(annotations, hasLength(1)); 9357 expect(annotations, hasLength(1));
9203 assertNoErrors(source); 9358 assertNoErrors(source);
9204 verify([source]); 9359 verify([source]);
9205 CompilationUnit unit = resolveCompilationUnit(source, library); 9360 CompilationUnit unit = resolveCompilationUnit(source, library);
9206 NodeList<CompilationUnitMember> declarations = unit.declarations; 9361 NodeList<CompilationUnitMember> declarations = unit.declarations;
9207 expect(declarations, hasLength(2)); 9362 expect(declarations, hasLength(2));
9208 Element expectedElement = (declarations[ 9363 Element expectedElement = (declarations[0] as TopLevelVariableDeclaration)
9209 0] as TopLevelVariableDeclaration).variables.variables[ 9364 .variables
9210 0].name.staticElement; 9365 .variables[0].name.staticElement;
9211 EngineTestCase.assertInstanceOf((obj) => obj is PropertyInducingElement, 9366 EngineTestCase.assertInstanceOf((obj) => obj is PropertyInducingElement,
9212 PropertyInducingElement, expectedElement); 9367 PropertyInducingElement, expectedElement);
9213 expectedElement = (expectedElement as PropertyInducingElement).getter; 9368 expectedElement = (expectedElement as PropertyInducingElement).getter;
9214 Element actualElement = 9369 Element actualElement =
9215 (declarations[1] as ClassDeclaration).metadata[0].name.staticElement; 9370 (declarations[1] as ClassDeclaration).metadata[0].name.staticElement;
9216 expect(actualElement, same(expectedElement)); 9371 expect(actualElement, same(expectedElement));
9217 } 9372 }
9218 9373
9219 void test_metadata_field() { 9374 void test_metadata_field() {
9220 Source source = addSource(r''' 9375 Source source = addSource(r'''
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
9389 expect(unitElement, isNotNull); 9544 expect(unitElement, isNotNull);
9390 List<FunctionTypeAliasElement> aliases = unitElement.functionTypeAliases; 9545 List<FunctionTypeAliasElement> aliases = unitElement.functionTypeAliases;
9391 expect(aliases, hasLength(1)); 9546 expect(aliases, hasLength(1));
9392 List<ElementAnnotation> annotations = aliases[0].metadata; 9547 List<ElementAnnotation> annotations = aliases[0].metadata;
9393 expect(annotations, hasLength(1)); 9548 expect(annotations, hasLength(1));
9394 assertNoErrors(source); 9549 assertNoErrors(source);
9395 verify([source]); 9550 verify([source]);
9396 CompilationUnit unit = resolveCompilationUnit(source, library); 9551 CompilationUnit unit = resolveCompilationUnit(source, library);
9397 NodeList<CompilationUnitMember> declarations = unit.declarations; 9552 NodeList<CompilationUnitMember> declarations = unit.declarations;
9398 expect(declarations, hasLength(2)); 9553 expect(declarations, hasLength(2));
9399 Element expectedElement = (declarations[ 9554 Element expectedElement = (declarations[0] as TopLevelVariableDeclaration)
9400 0] as TopLevelVariableDeclaration).variables.variables[ 9555 .variables
9401 0].name.staticElement; 9556 .variables[0].name.staticElement;
9402 EngineTestCase.assertInstanceOf((obj) => obj is PropertyInducingElement, 9557 EngineTestCase.assertInstanceOf((obj) => obj is PropertyInducingElement,
9403 PropertyInducingElement, expectedElement); 9558 PropertyInducingElement, expectedElement);
9404 expectedElement = (expectedElement as PropertyInducingElement).getter; 9559 expectedElement = (expectedElement as PropertyInducingElement).getter;
9405 Element actualElement = 9560 Element actualElement =
9406 (declarations[1] as FunctionTypeAlias).metadata[0].name.staticElement; 9561 (declarations[1] as FunctionTypeAlias).metadata[0].name.staticElement;
9407 expect(actualElement, same(expectedElement)); 9562 expect(actualElement, same(expectedElement));
9408 } 9563 }
9409 9564
9410 void test_method_fromMixin() { 9565 void test_method_fromMixin() {
9411 Source source = addSource(r''' 9566 Source source = addSource(r'''
(...skipping 500 matching lines...) Expand 10 before | Expand all | Expand 10 after
9912 InterfaceType numType = _typeProvider.numType; 10067 InterfaceType numType = _typeProvider.numType;
9913 // class Derived<T> extends Future<T> 10068 // class Derived<T> extends Future<T>
9914 ClassElementImpl derivedClass = 10069 ClassElementImpl derivedClass =
9915 ElementFactory.classElement2('Derived', ['T']); 10070 ElementFactory.classElement2('Derived', ['T']);
9916 derivedClass.supertype = _typeProvider.futureType 10071 derivedClass.supertype = _typeProvider.futureType
9917 .substitute4([derivedClass.typeParameters[0].type]); 10072 .substitute4([derivedClass.typeParameters[0].type]);
9918 InterfaceType derivedType = derivedClass.type; 10073 InterfaceType derivedType = derivedClass.type;
9919 // class A extends Derived<int> implements Derived<num> { ... } 10074 // class A extends Derived<int> implements Derived<num> { ... }
9920 ClassElementImpl classA = 10075 ClassElementImpl classA =
9921 ElementFactory.classElement('A', derivedType.substitute4([intType])); 10076 ElementFactory.classElement('A', derivedType.substitute4([intType]));
9922 classA.interfaces = <InterfaceType>[derivedType.substitute4([numType])]; 10077 classA.interfaces = <InterfaceType>[
10078 derivedType.substitute4([numType])
10079 ];
9923 // class B extends Future<num> implements Future<int> { ... } 10080 // class B extends Future<num> implements Future<int> { ... }
9924 ClassElementImpl classB = 10081 ClassElementImpl classB =
9925 ElementFactory.classElement('B', derivedType.substitute4([numType])); 10082 ElementFactory.classElement('B', derivedType.substitute4([numType]));
9926 classB.interfaces = <InterfaceType>[derivedType.substitute4([intType])]; 10083 classB.interfaces = <InterfaceType>[
10084 derivedType.substitute4([intType])
10085 ];
9927 // flatten(A) = flatten(B) = int, since int is more specific than num. 10086 // flatten(A) = flatten(B) = int, since int is more specific than num.
9928 // The code in flatten() that inhibits infinite recursion shouldn't be 10087 // The code in flatten() that inhibits infinite recursion shouldn't be
9929 // fooled by the fact that Derived appears twice in the type hierarchy. 10088 // fooled by the fact that Derived appears twice in the type hierarchy.
9930 expect(_flatten(classA.type), intType); 10089 expect(_flatten(classA.type), intType);
9931 expect(_flatten(classB.type), intType); 10090 expect(_flatten(classB.type), intType);
9932 } 10091 }
9933 10092
9934 void test_flatten_related_types() { 10093 void test_flatten_related_types() {
9935 InterfaceType futureType = _typeProvider.futureType; 10094 InterfaceType futureType = _typeProvider.futureType;
9936 InterfaceType intType = _typeProvider.intType; 10095 InterfaceType intType = _typeProvider.intType;
9937 InterfaceType numType = _typeProvider.numType; 10096 InterfaceType numType = _typeProvider.numType;
9938 // class A extends Future<int> implements Future<num> { ... } 10097 // class A extends Future<int> implements Future<num> { ... }
9939 ClassElementImpl classA = 10098 ClassElementImpl classA =
9940 ElementFactory.classElement('A', futureType.substitute4([intType])); 10099 ElementFactory.classElement('A', futureType.substitute4([intType]));
9941 classA.interfaces = <InterfaceType>[futureType.substitute4([numType])]; 10100 classA.interfaces = <InterfaceType>[
10101 futureType.substitute4([numType])
10102 ];
9942 // class B extends Future<num> implements Future<int> { ... } 10103 // class B extends Future<num> implements Future<int> { ... }
9943 ClassElementImpl classB = 10104 ClassElementImpl classB =
9944 ElementFactory.classElement('B', futureType.substitute4([numType])); 10105 ElementFactory.classElement('B', futureType.substitute4([numType]));
9945 classB.interfaces = <InterfaceType>[futureType.substitute4([intType])]; 10106 classB.interfaces = <InterfaceType>[
10107 futureType.substitute4([intType])
10108 ];
9946 // flatten(A) = flatten(B) = int, since int is more specific than num. 10109 // flatten(A) = flatten(B) = int, since int is more specific than num.
9947 expect(_flatten(classA.type), intType); 10110 expect(_flatten(classA.type), intType);
9948 expect(_flatten(classB.type), intType); 10111 expect(_flatten(classB.type), intType);
9949 } 10112 }
9950 10113
9951 void test_flatten_simple() { 10114 void test_flatten_simple() {
9952 InterfaceType intType = _typeProvider.intType; 10115 InterfaceType intType = _typeProvider.intType;
9953 DartType dynamicType = _typeProvider.dynamicType; 10116 DartType dynamicType = _typeProvider.dynamicType;
9954 InterfaceType futureDynamicType = _typeProvider.futureDynamicType; 10117 InterfaceType futureDynamicType = _typeProvider.futureDynamicType;
9955 InterfaceType futureIntType = 10118 InterfaceType futureIntType =
(...skipping 16 matching lines...) Expand all
9972 expect(_flatten(futureFutureIntType), intType); 10135 expect(_flatten(futureFutureIntType), intType);
9973 } 10136 }
9974 10137
9975 void test_flatten_unrelated_types() { 10138 void test_flatten_unrelated_types() {
9976 InterfaceType futureType = _typeProvider.futureType; 10139 InterfaceType futureType = _typeProvider.futureType;
9977 InterfaceType intType = _typeProvider.intType; 10140 InterfaceType intType = _typeProvider.intType;
9978 InterfaceType stringType = _typeProvider.stringType; 10141 InterfaceType stringType = _typeProvider.stringType;
9979 // class A extends Future<int> implements Future<String> { ... } 10142 // class A extends Future<int> implements Future<String> { ... }
9980 ClassElementImpl classA = 10143 ClassElementImpl classA =
9981 ElementFactory.classElement('A', futureType.substitute4([intType])); 10144 ElementFactory.classElement('A', futureType.substitute4([intType]));
9982 classA.interfaces = <InterfaceType>[futureType.substitute4([stringType])]; 10145 classA.interfaces = <InterfaceType>[
10146 futureType.substitute4([stringType])
10147 ];
9983 // class B extends Future<String> implements Future<int> { ... } 10148 // class B extends Future<String> implements Future<int> { ... }
9984 ClassElementImpl classB = 10149 ClassElementImpl classB =
9985 ElementFactory.classElement('B', futureType.substitute4([stringType])); 10150 ElementFactory.classElement('B', futureType.substitute4([stringType]));
9986 classB.interfaces = <InterfaceType>[futureType.substitute4([intType])]; 10151 classB.interfaces = <InterfaceType>[
10152 futureType.substitute4([intType])
10153 ];
9987 // flatten(A) = A and flatten(B) = B, since neither string nor int is more 10154 // flatten(A) = A and flatten(B) = B, since neither string nor int is more
9988 // specific than the other. 10155 // specific than the other.
9989 expect(_flatten(classA.type), classA.type); 10156 expect(_flatten(classA.type), classA.type);
9990 expect(_flatten(classB.type), classB.type); 10157 expect(_flatten(classB.type), classB.type);
9991 } 10158 }
9992 10159
9993 void test_visitAdjacentStrings() { 10160 void test_visitAdjacentStrings() {
9994 // "a" "b" 10161 // "a" "b"
9995 Expression node = AstFactory 10162 Expression node = AstFactory
9996 .adjacentStrings([_resolvedString("a"), _resolvedString("b")]); 10163 .adjacentStrings([_resolvedString("a"), _resolvedString("b")]);
(...skipping 22 matching lines...) Expand all
10019 MethodElement plusMethod = getMethod(numType, "+"); 10186 MethodElement plusMethod = getMethod(numType, "+");
10020 node.staticElement = plusMethod; 10187 node.staticElement = plusMethod;
10021 expect(_analyze(node), same(numType)); 10188 expect(_analyze(node), same(numType));
10022 _listener.assertNoErrors(); 10189 _listener.assertNoErrors();
10023 } 10190 }
10024 10191
10025 void test_visitAssignmentExpression_compoundIfNull_differentTypes() { 10192 void test_visitAssignmentExpression_compoundIfNull_differentTypes() {
10026 // double d; d ??= 0 10193 // double d; d ??= 0
10027 Expression node = AstFactory.assignmentExpression( 10194 Expression node = AstFactory.assignmentExpression(
10028 _resolvedVariable(_typeProvider.doubleType, 'd'), 10195 _resolvedVariable(_typeProvider.doubleType, 'd'),
10029 TokenType.QUESTION_QUESTION_EQ, _resolvedInteger(0)); 10196 TokenType.QUESTION_QUESTION_EQ,
10197 _resolvedInteger(0));
10030 expect(_analyze(node), same(_typeProvider.numType)); 10198 expect(_analyze(node), same(_typeProvider.numType));
10031 _listener.assertNoErrors(); 10199 _listener.assertNoErrors();
10032 } 10200 }
10033 10201
10034 void test_visitAssignmentExpression_compoundIfNull_sameTypes() { 10202 void test_visitAssignmentExpression_compoundIfNull_sameTypes() {
10035 // int i; i ??= 0 10203 // int i; i ??= 0
10036 Expression node = AstFactory.assignmentExpression( 10204 Expression node = AstFactory.assignmentExpression(
10037 _resolvedVariable(_typeProvider.intType, 'i'), 10205 _resolvedVariable(_typeProvider.intType, 'i'),
10038 TokenType.QUESTION_QUESTION_EQ, _resolvedInteger(0)); 10206 TokenType.QUESTION_QUESTION_EQ,
10207 _resolvedInteger(0));
10039 expect(_analyze(node), same(_typeProvider.intType)); 10208 expect(_analyze(node), same(_typeProvider.intType));
10040 _listener.assertNoErrors(); 10209 _listener.assertNoErrors();
10041 } 10210 }
10042 10211
10043 void test_visitAssignmentExpression_simple() { 10212 void test_visitAssignmentExpression_simple() {
10044 // i = 0 10213 // i = 0
10045 InterfaceType intType = _typeProvider.intType; 10214 InterfaceType intType = _typeProvider.intType;
10046 Expression node = AstFactory.assignmentExpression( 10215 Expression node = AstFactory.assignmentExpression(
10047 _resolvedVariable(intType, "i"), TokenType.EQ, _resolvedInteger(0)); 10216 _resolvedVariable(intType, "i"), TokenType.EQ, _resolvedInteger(0));
10048 expect(_analyze(node), same(intType)); 10217 expect(_analyze(node), same(intType));
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
10085 // 1 ?? 1.5 10254 // 1 ?? 1.5
10086 Expression node = AstFactory.binaryExpression( 10255 Expression node = AstFactory.binaryExpression(
10087 _resolvedInteger(1), TokenType.QUESTION_QUESTION, _resolvedDouble(1.5)); 10256 _resolvedInteger(1), TokenType.QUESTION_QUESTION, _resolvedDouble(1.5));
10088 expect(_analyze(node), same(_typeProvider.numType)); 10257 expect(_analyze(node), same(_typeProvider.numType));
10089 _listener.assertNoErrors(); 10258 _listener.assertNoErrors();
10090 } 10259 }
10091 10260
10092 void test_visitBinaryExpression_logicalAnd() { 10261 void test_visitBinaryExpression_logicalAnd() {
10093 // false && true 10262 // false && true
10094 Expression node = AstFactory.binaryExpression( 10263 Expression node = AstFactory.binaryExpression(
10095 AstFactory.booleanLiteral(false), TokenType.AMPERSAND_AMPERSAND, 10264 AstFactory.booleanLiteral(false),
10265 TokenType.AMPERSAND_AMPERSAND,
10096 AstFactory.booleanLiteral(true)); 10266 AstFactory.booleanLiteral(true));
10097 expect(_analyze(node), same(_typeProvider.boolType)); 10267 expect(_analyze(node), same(_typeProvider.boolType));
10098 _listener.assertNoErrors(); 10268 _listener.assertNoErrors();
10099 } 10269 }
10100 10270
10101 void test_visitBinaryExpression_logicalOr() { 10271 void test_visitBinaryExpression_logicalOr() {
10102 // false || true 10272 // false || true
10103 Expression node = AstFactory.binaryExpression( 10273 Expression node = AstFactory.binaryExpression(
10104 AstFactory.booleanLiteral(false), TokenType.BAR_BAR, 10274 AstFactory.booleanLiteral(false),
10275 TokenType.BAR_BAR,
10105 AstFactory.booleanLiteral(true)); 10276 AstFactory.booleanLiteral(true));
10106 expect(_analyze(node), same(_typeProvider.boolType)); 10277 expect(_analyze(node), same(_typeProvider.boolType));
10107 _listener.assertNoErrors(); 10278 _listener.assertNoErrors();
10108 } 10279 }
10109 10280
10110 void test_visitBinaryExpression_minusID_propagated() { 10281 void test_visitBinaryExpression_minusID_propagated() {
10111 // a - b 10282 // a - b
10112 BinaryExpression node = AstFactory.binaryExpression( 10283 BinaryExpression node = AstFactory.binaryExpression(
10113 _propagatedVariable(_typeProvider.intType, 'a'), TokenType.MINUS, 10284 _propagatedVariable(_typeProvider.intType, 'a'),
10285 TokenType.MINUS,
10114 _propagatedVariable(_typeProvider.doubleType, 'b')); 10286 _propagatedVariable(_typeProvider.doubleType, 'b'));
10115 node.propagatedElement = getMethod(_typeProvider.numType, "+"); 10287 node.propagatedElement = getMethod(_typeProvider.numType, "+");
10116 _analyze(node); 10288 _analyze(node);
10117 expect(node.propagatedType, same(_typeProvider.doubleType)); 10289 expect(node.propagatedType, same(_typeProvider.doubleType));
10118 _listener.assertNoErrors(); 10290 _listener.assertNoErrors();
10119 } 10291 }
10120 10292
10121 void test_visitBinaryExpression_notEquals() { 10293 void test_visitBinaryExpression_notEquals() {
10122 // 2 != 3 10294 // 2 != 3
10123 Expression node = AstFactory.binaryExpression( 10295 Expression node = AstFactory.binaryExpression(
(...skipping 16 matching lines...) Expand all
10140 BinaryExpression node = AstFactory.binaryExpression( 10312 BinaryExpression node = AstFactory.binaryExpression(
10141 _resolvedInteger(1), TokenType.PLUS, _resolvedInteger(2)); 10313 _resolvedInteger(1), TokenType.PLUS, _resolvedInteger(2));
10142 node.staticElement = getMethod(_typeProvider.numType, "+"); 10314 node.staticElement = getMethod(_typeProvider.numType, "+");
10143 expect(_analyze(node), same(_typeProvider.intType)); 10315 expect(_analyze(node), same(_typeProvider.intType));
10144 _listener.assertNoErrors(); 10316 _listener.assertNoErrors();
10145 } 10317 }
10146 10318
10147 void test_visitBinaryExpression_plusII_propagated() { 10319 void test_visitBinaryExpression_plusII_propagated() {
10148 // a + b 10320 // a + b
10149 BinaryExpression node = AstFactory.binaryExpression( 10321 BinaryExpression node = AstFactory.binaryExpression(
10150 _propagatedVariable(_typeProvider.intType, 'a'), TokenType.PLUS, 10322 _propagatedVariable(_typeProvider.intType, 'a'),
10323 TokenType.PLUS,
10151 _propagatedVariable(_typeProvider.intType, 'b')); 10324 _propagatedVariable(_typeProvider.intType, 'b'));
10152 node.propagatedElement = getMethod(_typeProvider.numType, "+"); 10325 node.propagatedElement = getMethod(_typeProvider.numType, "+");
10153 _analyze(node); 10326 _analyze(node);
10154 expect(node.propagatedType, same(_typeProvider.intType)); 10327 expect(node.propagatedType, same(_typeProvider.intType));
10155 _listener.assertNoErrors(); 10328 _listener.assertNoErrors();
10156 } 10329 }
10157 10330
10158 void test_visitBinaryExpression_slash() { 10331 void test_visitBinaryExpression_slash() {
10159 // 2 / 2 10332 // 2 / 2
10160 BinaryExpression node = AstFactory.binaryExpression( 10333 BinaryExpression node = AstFactory.binaryExpression(
10161 _resolvedInteger(2), TokenType.SLASH, _resolvedInteger(2)); 10334 _resolvedInteger(2), TokenType.SLASH, _resolvedInteger(2));
10162 node.staticElement = getMethod(_typeProvider.numType, "/"); 10335 node.staticElement = getMethod(_typeProvider.numType, "/");
10163 expect(_analyze(node), same(_typeProvider.doubleType)); 10336 expect(_analyze(node), same(_typeProvider.doubleType));
10164 _listener.assertNoErrors(); 10337 _listener.assertNoErrors();
10165 } 10338 }
10166 10339
10167 void test_visitBinaryExpression_star_notSpecial() { 10340 void test_visitBinaryExpression_star_notSpecial() {
10168 // class A { 10341 // class A {
10169 // A operator *(double value); 10342 // A operator *(double value);
10170 // } 10343 // }
10171 // (a as A) * 2.0 10344 // (a as A) * 2.0
10172 ClassElementImpl classA = ElementFactory.classElement2("A"); 10345 ClassElementImpl classA = ElementFactory.classElement2("A");
10173 InterfaceType typeA = classA.type; 10346 InterfaceType typeA = classA.type;
10174 MethodElement operator = 10347 MethodElement operator =
10175 ElementFactory.methodElement("*", typeA, [_typeProvider.doubleType]); 10348 ElementFactory.methodElement("*", typeA, [_typeProvider.doubleType]);
10176 classA.methods = <MethodElement>[operator]; 10349 classA.methods = <MethodElement>[operator];
10177 BinaryExpression node = AstFactory.binaryExpression(AstFactory.asExpression( 10350 BinaryExpression node = AstFactory.binaryExpression(
10351 AstFactory.asExpression(
10178 AstFactory.identifier3("a"), AstFactory.typeName(classA)), 10352 AstFactory.identifier3("a"), AstFactory.typeName(classA)),
10179 TokenType.PLUS, _resolvedDouble(2.0)); 10353 TokenType.PLUS,
10354 _resolvedDouble(2.0));
10180 node.staticElement = operator; 10355 node.staticElement = operator;
10181 expect(_analyze(node), same(typeA)); 10356 expect(_analyze(node), same(typeA));
10182 _listener.assertNoErrors(); 10357 _listener.assertNoErrors();
10183 } 10358 }
10184 10359
10185 void test_visitBinaryExpression_starID() { 10360 void test_visitBinaryExpression_starID() {
10186 // 1 * 2.0 10361 // 1 * 2.0
10187 BinaryExpression node = AstFactory.binaryExpression( 10362 BinaryExpression node = AstFactory.binaryExpression(
10188 _resolvedInteger(1), TokenType.PLUS, _resolvedDouble(2.0)); 10363 _resolvedInteger(1), TokenType.PLUS, _resolvedDouble(2.0));
10189 node.staticElement = getMethod(_typeProvider.numType, "*"); 10364 node.staticElement = getMethod(_typeProvider.numType, "*");
(...skipping 19 matching lines...) Expand all
10209 // a..length 10384 // a..length
10210 Expression node = AstFactory.cascadeExpression( 10385 Expression node = AstFactory.cascadeExpression(
10211 _resolvedString("a"), [AstFactory.propertyAccess2(null, "length")]); 10386 _resolvedString("a"), [AstFactory.propertyAccess2(null, "length")]);
10212 expect(_analyze(node), same(_typeProvider.stringType)); 10387 expect(_analyze(node), same(_typeProvider.stringType));
10213 _listener.assertNoErrors(); 10388 _listener.assertNoErrors();
10214 } 10389 }
10215 10390
10216 void test_visitConditionalExpression_differentTypes() { 10391 void test_visitConditionalExpression_differentTypes() {
10217 // true ? 1.0 : 0 10392 // true ? 1.0 : 0
10218 Expression node = AstFactory.conditionalExpression( 10393 Expression node = AstFactory.conditionalExpression(
10219 AstFactory.booleanLiteral(true), _resolvedDouble(1.0), 10394 AstFactory.booleanLiteral(true),
10395 _resolvedDouble(1.0),
10220 _resolvedInteger(0)); 10396 _resolvedInteger(0));
10221 expect(_analyze(node), same(_typeProvider.numType)); 10397 expect(_analyze(node), same(_typeProvider.numType));
10222 _listener.assertNoErrors(); 10398 _listener.assertNoErrors();
10223 } 10399 }
10224 10400
10225 void test_visitConditionalExpression_sameTypes() { 10401 void test_visitConditionalExpression_sameTypes() {
10226 // true ? 1 : 0 10402 // true ? 1 : 0
10227 Expression node = AstFactory.conditionalExpression( 10403 Expression node = AstFactory.conditionalExpression(
10228 AstFactory.booleanLiteral(true), _resolvedInteger(1), 10404 AstFactory.booleanLiteral(true),
10405 _resolvedInteger(1),
10229 _resolvedInteger(0)); 10406 _resolvedInteger(0));
10230 expect(_analyze(node), same(_typeProvider.intType)); 10407 expect(_analyze(node), same(_typeProvider.intType));
10231 _listener.assertNoErrors(); 10408 _listener.assertNoErrors();
10232 } 10409 }
10233 10410
10234 void test_visitDoubleLiteral() { 10411 void test_visitDoubleLiteral() {
10235 // 4.33 10412 // 4.33
10236 Expression node = AstFactory.doubleLiteral(4.33); 10413 Expression node = AstFactory.doubleLiteral(4.33);
10237 expect(_analyze(node), same(_typeProvider.doubleType)); 10414 expect(_analyze(node), same(_typeProvider.doubleType));
10238 _listener.assertNoErrors(); 10415 _listener.assertNoErrors();
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
10370 FormalParameter p1 = AstFactory.simpleFormalParameter3("p1"); 10547 FormalParameter p1 = AstFactory.simpleFormalParameter3("p1");
10371 _setType(p1, dynamicType); 10548 _setType(p1, dynamicType);
10372 FormalParameter p2 = AstFactory.simpleFormalParameter3("p2"); 10549 FormalParameter p2 = AstFactory.simpleFormalParameter3("p2");
10373 _setType(p2, dynamicType); 10550 _setType(p2, dynamicType);
10374 FunctionExpression node = _resolvedFunctionExpression( 10551 FunctionExpression node = _resolvedFunctionExpression(
10375 AstFactory.formalParameterList([p1, p2]), 10552 AstFactory.formalParameterList([p1, p2]),
10376 AstFactory.blockFunctionBody2()); 10553 AstFactory.blockFunctionBody2());
10377 _analyze5(p1); 10554 _analyze5(p1);
10378 _analyze5(p2); 10555 _analyze5(p2);
10379 DartType resultType = _analyze(node); 10556 DartType resultType = _analyze(node);
10380 _assertFunctionType(dynamicType, <DartType>[ 10557 _assertFunctionType(dynamicType, <DartType>[dynamicType, dynamicType], null,
10381 dynamicType, 10558 null, resultType);
10382 dynamicType
10383 ], null, null, resultType);
10384 _listener.assertNoErrors(); 10559 _listener.assertNoErrors();
10385 } 10560 }
10386 10561
10387 void test_visitFunctionExpression_normal_expression() { 10562 void test_visitFunctionExpression_normal_expression() {
10388 // (p1, p2) -> 0 10563 // (p1, p2) -> 0
10389 DartType dynamicType = _typeProvider.dynamicType; 10564 DartType dynamicType = _typeProvider.dynamicType;
10390 FormalParameter p = AstFactory.simpleFormalParameter3("p"); 10565 FormalParameter p = AstFactory.simpleFormalParameter3("p");
10391 _setType(p, dynamicType); 10566 _setType(p, dynamicType);
10392 FunctionExpression node = _resolvedFunctionExpression( 10567 FunctionExpression node = _resolvedFunctionExpression(
10393 AstFactory.formalParameterList([p]), 10568 AstFactory.formalParameterList([p]),
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
10485 _setType(p1, dynamicType); 10660 _setType(p1, dynamicType);
10486 FormalParameter p2 = AstFactory.positionalFormalParameter( 10661 FormalParameter p2 = AstFactory.positionalFormalParameter(
10487 AstFactory.simpleFormalParameter3("p2"), _resolvedInteger(0)); 10662 AstFactory.simpleFormalParameter3("p2"), _resolvedInteger(0));
10488 _setType(p2, dynamicType); 10663 _setType(p2, dynamicType);
10489 FunctionExpression node = _resolvedFunctionExpression( 10664 FunctionExpression node = _resolvedFunctionExpression(
10490 AstFactory.formalParameterList([p1, p2]), 10665 AstFactory.formalParameterList([p1, p2]),
10491 AstFactory.blockFunctionBody2()); 10666 AstFactory.blockFunctionBody2());
10492 _analyze5(p1); 10667 _analyze5(p1);
10493 _analyze5(p2); 10668 _analyze5(p2);
10494 DartType resultType = _analyze(node); 10669 DartType resultType = _analyze(node);
10495 _assertFunctionType(dynamicType, null, <DartType>[ 10670 _assertFunctionType(dynamicType, null, <DartType>[dynamicType, dynamicType],
10496 dynamicType, 10671 null, resultType);
10497 dynamicType
10498 ], null, resultType);
10499 _listener.assertNoErrors(); 10672 _listener.assertNoErrors();
10500 } 10673 }
10501 10674
10502 void test_visitFunctionExpression_positional_expression() { 10675 void test_visitFunctionExpression_positional_expression() {
10503 // ([p1 = 0, p2 = 0]) -> 0 10676 // ([p1 = 0, p2 = 0]) -> 0
10504 DartType dynamicType = _typeProvider.dynamicType; 10677 DartType dynamicType = _typeProvider.dynamicType;
10505 FormalParameter p = AstFactory.positionalFormalParameter( 10678 FormalParameter p = AstFactory.positionalFormalParameter(
10506 AstFactory.simpleFormalParameter3("p"), _resolvedInteger(0)); 10679 AstFactory.simpleFormalParameter3("p"), _resolvedInteger(0));
10507 _setType(p, dynamicType); 10680 _setType(p, dynamicType);
10508 FunctionExpression node = _resolvedFunctionExpression( 10681 FunctionExpression node = _resolvedFunctionExpression(
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
10591 // new C.m() 10764 // new C.m()
10592 ClassElementImpl classElement = ElementFactory.classElement2("C"); 10765 ClassElementImpl classElement = ElementFactory.classElement2("C");
10593 String constructorName = "m"; 10766 String constructorName = "m";
10594 ConstructorElementImpl constructor = 10767 ConstructorElementImpl constructor =
10595 ElementFactory.constructorElement2(classElement, constructorName); 10768 ElementFactory.constructorElement2(classElement, constructorName);
10596 constructor.returnType = classElement.type; 10769 constructor.returnType = classElement.type;
10597 FunctionTypeImpl constructorType = new FunctionTypeImpl(constructor); 10770 FunctionTypeImpl constructorType = new FunctionTypeImpl(constructor);
10598 constructor.type = constructorType; 10771 constructor.type = constructorType;
10599 classElement.constructors = <ConstructorElement>[constructor]; 10772 classElement.constructors = <ConstructorElement>[constructor];
10600 InstanceCreationExpression node = AstFactory.instanceCreationExpression2( 10773 InstanceCreationExpression node = AstFactory.instanceCreationExpression2(
10601 null, AstFactory.typeName(classElement), 10774 null,
10775 AstFactory.typeName(classElement),
10602 [AstFactory.identifier3(constructorName)]); 10776 [AstFactory.identifier3(constructorName)]);
10603 node.staticElement = constructor; 10777 node.staticElement = constructor;
10604 expect(_analyze(node), same(classElement.type)); 10778 expect(_analyze(node), same(classElement.type));
10605 _listener.assertNoErrors(); 10779 _listener.assertNoErrors();
10606 } 10780 }
10607 10781
10608 void test_visitInstanceCreationExpression_typeParameters() { 10782 void test_visitInstanceCreationExpression_typeParameters() {
10609 // new C<I>() 10783 // new C<I>()
10610 ClassElementImpl elementC = ElementFactory.classElement2("C", ["E"]); 10784 ClassElementImpl elementC = ElementFactory.classElement2("C", ["E"]);
10611 ClassElementImpl elementI = ElementFactory.classElement2("I"); 10785 ClassElementImpl elementI = ElementFactory.classElement2("I");
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
10664 Expression node = AstFactory.isExpression( 10838 Expression node = AstFactory.isExpression(
10665 _resolvedString("a"), false, AstFactory.typeName4("String")); 10839 _resolvedString("a"), false, AstFactory.typeName4("String"));
10666 expect(_analyze(node), same(_typeProvider.boolType)); 10840 expect(_analyze(node), same(_typeProvider.boolType));
10667 _listener.assertNoErrors(); 10841 _listener.assertNoErrors();
10668 } 10842 }
10669 10843
10670 void test_visitListLiteral_empty() { 10844 void test_visitListLiteral_empty() {
10671 // [] 10845 // []
10672 Expression node = AstFactory.listLiteral(); 10846 Expression node = AstFactory.listLiteral();
10673 DartType resultType = _analyze(node); 10847 DartType resultType = _analyze(node);
10674 _assertType2(_typeProvider.listType 10848 _assertType2(
10675 .substitute4(<DartType>[_typeProvider.dynamicType]), resultType); 10849 _typeProvider.listType
10850 .substitute4(<DartType>[_typeProvider.dynamicType]),
10851 resultType);
10676 _listener.assertNoErrors(); 10852 _listener.assertNoErrors();
10677 } 10853 }
10678 10854
10679 void test_visitListLiteral_nonEmpty() { 10855 void test_visitListLiteral_nonEmpty() {
10680 // [0] 10856 // [0]
10681 Expression node = AstFactory.listLiteral([_resolvedInteger(0)]); 10857 Expression node = AstFactory.listLiteral([_resolvedInteger(0)]);
10682 DartType resultType = _analyze(node); 10858 DartType resultType = _analyze(node);
10683 _assertType2(_typeProvider.listType 10859 _assertType2(
10684 .substitute4(<DartType>[_typeProvider.dynamicType]), resultType); 10860 _typeProvider.listType
10861 .substitute4(<DartType>[_typeProvider.dynamicType]),
10862 resultType);
10685 _listener.assertNoErrors(); 10863 _listener.assertNoErrors();
10686 } 10864 }
10687 10865
10688 void test_visitMapLiteral_empty() { 10866 void test_visitMapLiteral_empty() {
10689 // {} 10867 // {}
10690 Expression node = AstFactory.mapLiteral2(); 10868 Expression node = AstFactory.mapLiteral2();
10691 DartType resultType = _analyze(node); 10869 DartType resultType = _analyze(node);
10692 _assertType2(_typeProvider.mapType.substitute4( 10870 _assertType2(
10871 _typeProvider.mapType.substitute4(
10693 <DartType>[_typeProvider.dynamicType, _typeProvider.dynamicType]), 10872 <DartType>[_typeProvider.dynamicType, _typeProvider.dynamicType]),
10694 resultType); 10873 resultType);
10695 _listener.assertNoErrors(); 10874 _listener.assertNoErrors();
10696 } 10875 }
10697 10876
10698 void test_visitMapLiteral_nonEmpty() { 10877 void test_visitMapLiteral_nonEmpty() {
10699 // {"k" : 0} 10878 // {"k" : 0}
10700 Expression node = AstFactory 10879 Expression node = AstFactory
10701 .mapLiteral2([AstFactory.mapLiteralEntry("k", _resolvedInteger(0))]); 10880 .mapLiteral2([AstFactory.mapLiteralEntry("k", _resolvedInteger(0))]);
10702 DartType resultType = _analyze(node); 10881 DartType resultType = _analyze(node);
10703 _assertType2(_typeProvider.mapType.substitute4( 10882 _assertType2(
10883 _typeProvider.mapType.substitute4(
10704 <DartType>[_typeProvider.dynamicType, _typeProvider.dynamicType]), 10884 <DartType>[_typeProvider.dynamicType, _typeProvider.dynamicType]),
10705 resultType); 10885 resultType);
10706 _listener.assertNoErrors(); 10886 _listener.assertNoErrors();
10707 } 10887 }
10708 10888
10709 void test_visitMethodInvocation_then() { 10889 void test_visitMethodInvocation_then() {
10710 // then() 10890 // then()
10711 Expression node = AstFactory.methodInvocation(null, "then"); 10891 Expression node = AstFactory.methodInvocation(null, "then");
10712 _analyze(node); 10892 _analyze(node);
10713 _listener.assertNoErrors(); 10893 _listener.assertNoErrors();
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
10919 _listener.assertNoErrors(); 11099 _listener.assertNoErrors();
10920 } 11100 }
10921 11101
10922 void test_visitSymbolLiteral() { 11102 void test_visitSymbolLiteral() {
10923 expect(_analyze(AstFactory.symbolLiteral(["a"])), 11103 expect(_analyze(AstFactory.symbolLiteral(["a"])),
10924 same(_typeProvider.symbolType)); 11104 same(_typeProvider.symbolType));
10925 } 11105 }
10926 11106
10927 void test_visitThisExpression() { 11107 void test_visitThisExpression() {
10928 // this 11108 // this
10929 InterfaceType thisType = ElementFactory.classElement( 11109 InterfaceType thisType = ElementFactory
10930 "B", ElementFactory.classElement2("A").type).type; 11110 .classElement("B", ElementFactory.classElement2("A").type)
11111 .type;
10931 Expression node = AstFactory.thisExpression(); 11112 Expression node = AstFactory.thisExpression();
10932 expect(_analyze3(node, thisType), same(thisType)); 11113 expect(_analyze3(node, thisType), same(thisType));
10933 _listener.assertNoErrors(); 11114 _listener.assertNoErrors();
10934 } 11115 }
10935 11116
10936 void test_visitThrowExpression_withoutValue() { 11117 void test_visitThrowExpression_withoutValue() {
10937 // throw 11118 // throw
10938 Expression node = AstFactory.throwExpression(); 11119 Expression node = AstFactory.throwExpression();
10939 expect(_analyze(node), same(_typeProvider.bottomType)); 11120 expect(_analyze(node), same(_typeProvider.bottomType));
10940 _listener.assertNoErrors(); 11121 _listener.assertNoErrors();
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
11019 11200
11020 /** 11201 /**
11021 * Assert that the actual type is a function type with the expected characteri stics. 11202 * Assert that the actual type is a function type with the expected characteri stics.
11022 * 11203 *
11023 * @param expectedReturnType the expected return type of the function 11204 * @param expectedReturnType the expected return type of the function
11024 * @param expectedNormalTypes the expected types of the normal parameters 11205 * @param expectedNormalTypes the expected types of the normal parameters
11025 * @param expectedOptionalTypes the expected types of the optional parameters 11206 * @param expectedOptionalTypes the expected types of the optional parameters
11026 * @param expectedNamedTypes the expected types of the named parameters 11207 * @param expectedNamedTypes the expected types of the named parameters
11027 * @param actualType the type being tested 11208 * @param actualType the type being tested
11028 */ 11209 */
11029 void _assertFunctionType(DartType expectedReturnType, 11210 void _assertFunctionType(
11030 List<DartType> expectedNormalTypes, List<DartType> expectedOptionalTypes, 11211 DartType expectedReturnType,
11031 Map<String, DartType> expectedNamedTypes, DartType actualType) { 11212 List<DartType> expectedNormalTypes,
11213 List<DartType> expectedOptionalTypes,
11214 Map<String, DartType> expectedNamedTypes,
11215 DartType actualType) {
11032 EngineTestCase.assertInstanceOf( 11216 EngineTestCase.assertInstanceOf(
11033 (obj) => obj is FunctionType, FunctionType, actualType); 11217 (obj) => obj is FunctionType, FunctionType, actualType);
11034 FunctionType functionType = actualType as FunctionType; 11218 FunctionType functionType = actualType as FunctionType;
11035 List<DartType> normalTypes = functionType.normalParameterTypes; 11219 List<DartType> normalTypes = functionType.normalParameterTypes;
11036 if (expectedNormalTypes == null) { 11220 if (expectedNormalTypes == null) {
11037 expect(normalTypes, hasLength(0)); 11221 expect(normalTypes, hasLength(0));
11038 } else { 11222 } else {
11039 int expectedCount = expectedNormalTypes.length; 11223 int expectedCount = expectedNormalTypes.length;
11040 expect(normalTypes, hasLength(expectedCount)); 11224 expect(normalTypes, hasLength(expectedCount));
11041 for (int i = 0; i < expectedCount; i++) { 11225 for (int i = 0; i < expectedCount; i++) {
(...skipping 732 matching lines...) Expand 10 before | Expand all | Expand 10 after
11774 11958
11775 void test_getType_noScope() { 11959 void test_getType_noScope() {
11776 TypeOverrideManager manager = new TypeOverrideManager(); 11960 TypeOverrideManager manager = new TypeOverrideManager();
11777 expect(manager.getType(ElementFactory.localVariableElement2("v")), isNull); 11961 expect(manager.getType(ElementFactory.localVariableElement2("v")), isNull);
11778 } 11962 }
11779 } 11963 }
11780 11964
11781 @reflectiveTest 11965 @reflectiveTest
11782 class TypePropagationTest extends ResolverTestCase { 11966 class TypePropagationTest extends ResolverTestCase {
11783 void fail_finalPropertyInducingVariable_classMember_instance() { 11967 void fail_finalPropertyInducingVariable_classMember_instance() {
11784 addNamedSource("/lib.dart", r''' 11968 addNamedSource(
11969 "/lib.dart",
11970 r'''
11785 class A { 11971 class A {
11786 final v = 0; 11972 final v = 0;
11787 }'''); 11973 }''');
11788 String code = r''' 11974 String code = r'''
11789 import 'lib.dart'; 11975 import 'lib.dart';
11790 f(A a) { 11976 f(A a) {
11791 return a.v; // marker 11977 return a.v; // marker
11792 }'''; 11978 }''';
11793 _assertTypeOfMarkedExpression( 11979 _assertTypeOfMarkedExpression(
11794 code, typeProvider.dynamicType, typeProvider.intType); 11980 code, typeProvider.dynamicType, typeProvider.intType);
11795 } 11981 }
11796 11982
11797 void fail_finalPropertyInducingVariable_classMember_instance_inherited() { 11983 void fail_finalPropertyInducingVariable_classMember_instance_inherited() {
11798 addNamedSource("/lib.dart", r''' 11984 addNamedSource(
11985 "/lib.dart",
11986 r'''
11799 class A { 11987 class A {
11800 final v = 0; 11988 final v = 0;
11801 }'''); 11989 }''');
11802 String code = r''' 11990 String code = r'''
11803 import 'lib.dart'; 11991 import 'lib.dart';
11804 class B extends A { 11992 class B extends A {
11805 m() { 11993 m() {
11806 return v; // marker 11994 return v; // marker
11807 } 11995 }
11808 }'''; 11996 }''';
11809 _assertTypeOfMarkedExpression( 11997 _assertTypeOfMarkedExpression(
11810 code, typeProvider.dynamicType, typeProvider.intType); 11998 code, typeProvider.dynamicType, typeProvider.intType);
11811 } 11999 }
11812 12000
11813 void fail_finalPropertyInducingVariable_classMember_instance_propagatedTarget( ) { 12001 void fail_finalPropertyInducingVariable_classMember_instance_propagatedTarget( ) {
11814 addNamedSource("/lib.dart", r''' 12002 addNamedSource(
12003 "/lib.dart",
12004 r'''
11815 class A { 12005 class A {
11816 final v = 0; 12006 final v = 0;
11817 }'''); 12007 }''');
11818 String code = r''' 12008 String code = r'''
11819 import 'lib.dart'; 12009 import 'lib.dart';
11820 f(p) { 12010 f(p) {
11821 if (p is A) { 12011 if (p is A) {
11822 return p.v; // marker 12012 return p.v; // marker
11823 } 12013 }
11824 }'''; 12014 }''';
11825 _assertTypeOfMarkedExpression( 12015 _assertTypeOfMarkedExpression(
11826 code, typeProvider.dynamicType, typeProvider.intType); 12016 code, typeProvider.dynamicType, typeProvider.intType);
11827 } 12017 }
11828 12018
11829 void fail_finalPropertyInducingVariable_classMember_static() { 12019 void fail_finalPropertyInducingVariable_classMember_static() {
11830 addNamedSource("/lib.dart", r''' 12020 addNamedSource(
12021 "/lib.dart",
12022 r'''
11831 class A { 12023 class A {
11832 static final V = 0; 12024 static final V = 0;
11833 }'''); 12025 }''');
11834 String code = r''' 12026 String code = r'''
11835 import 'lib.dart'; 12027 import 'lib.dart';
11836 f() { 12028 f() {
11837 return A.V; // marker 12029 return A.V; // marker
11838 }'''; 12030 }''';
11839 _assertTypeOfMarkedExpression( 12031 _assertTypeOfMarkedExpression(
11840 code, typeProvider.dynamicType, typeProvider.intType); 12032 code, typeProvider.dynamicType, typeProvider.intType);
(...skipping 16 matching lines...) Expand all
11857 import 'lib.dart'; 12049 import 'lib.dart';
11858 f() { 12050 f() {
11859 return V; // marker simple 12051 return V; // marker simple
11860 }'''; 12052 }''';
11861 _assertTypeOfMarkedExpression( 12053 _assertTypeOfMarkedExpression(
11862 code, typeProvider.dynamicType, typeProvider.intType); 12054 code, typeProvider.dynamicType, typeProvider.intType);
11863 } 12055 }
11864 12056
11865 void fail_mergePropagatedTypesAtJoinPoint_1() { 12057 void fail_mergePropagatedTypesAtJoinPoint_1() {
11866 // https://code.google.com/p/dart/issues/detail?id=19929 12058 // https://code.google.com/p/dart/issues/detail?id=19929
11867 _assertTypeOfMarkedExpression(r''' 12059 _assertTypeOfMarkedExpression(
12060 r'''
11868 f1(x) { 12061 f1(x) {
11869 var y = []; 12062 var y = [];
11870 if (x) { 12063 if (x) {
11871 y = 0; 12064 y = 0;
11872 } else { 12065 } else {
11873 y = ''; 12066 y = '';
11874 } 12067 }
11875 // Propagated type is [List] here: incorrect. 12068 // Propagated type is [List] here: incorrect.
11876 // Best we can do is [Object]? 12069 // Best we can do is [Object]?
11877 return y; // marker 12070 return y; // marker
11878 }''', null, typeProvider.dynamicType); 12071 }''',
12072 null,
12073 typeProvider.dynamicType);
11879 } 12074 }
11880 12075
11881 void fail_mergePropagatedTypesAtJoinPoint_2() { 12076 void fail_mergePropagatedTypesAtJoinPoint_2() {
11882 // https://code.google.com/p/dart/issues/detail?id=19929 12077 // https://code.google.com/p/dart/issues/detail?id=19929
11883 _assertTypeOfMarkedExpression(r''' 12078 _assertTypeOfMarkedExpression(
12079 r'''
11884 f2(x) { 12080 f2(x) {
11885 var y = []; 12081 var y = [];
11886 if (x) { 12082 if (x) {
11887 y = 0; 12083 y = 0;
11888 } else { 12084 } else {
11889 } 12085 }
11890 // Propagated type is [List] here: incorrect. 12086 // Propagated type is [List] here: incorrect.
11891 // Best we can do is [Object]? 12087 // Best we can do is [Object]?
11892 return y; // marker 12088 return y; // marker
11893 }''', null, typeProvider.dynamicType); 12089 }''',
12090 null,
12091 typeProvider.dynamicType);
11894 } 12092 }
11895 12093
11896 void fail_mergePropagatedTypesAtJoinPoint_3() { 12094 void fail_mergePropagatedTypesAtJoinPoint_3() {
11897 // https://code.google.com/p/dart/issues/detail?id=19929 12095 // https://code.google.com/p/dart/issues/detail?id=19929
11898 _assertTypeOfMarkedExpression(r''' 12096 _assertTypeOfMarkedExpression(
12097 r'''
11899 f4(x) { 12098 f4(x) {
11900 var y = []; 12099 var y = [];
11901 if (x) { 12100 if (x) {
11902 y = 0; 12101 y = 0;
11903 } else { 12102 } else {
11904 y = 1.5; 12103 y = 1.5;
11905 } 12104 }
11906 // Propagated type is [List] here: incorrect. 12105 // Propagated type is [List] here: incorrect.
11907 // A correct answer is the least upper bound of [int] and [double], 12106 // A correct answer is the least upper bound of [int] and [double],
11908 // i.e. [num]. 12107 // i.e. [num].
11909 return y; // marker 12108 return y; // marker
11910 }''', null, typeProvider.numType); 12109 }''',
12110 null,
12111 typeProvider.numType);
11911 } 12112 }
11912 12113
11913 void fail_mergePropagatedTypesAtJoinPoint_5() { 12114 void fail_mergePropagatedTypesAtJoinPoint_5() {
11914 // https://code.google.com/p/dart/issues/detail?id=19929 12115 // https://code.google.com/p/dart/issues/detail?id=19929
11915 _assertTypeOfMarkedExpression(r''' 12116 _assertTypeOfMarkedExpression(
12117 r'''
11916 f6(x,y) { 12118 f6(x,y) {
11917 var z = []; 12119 var z = [];
11918 if (x || (z = y) < 0) { 12120 if (x || (z = y) < 0) {
11919 } else { 12121 } else {
11920 z = 0; 12122 z = 0;
11921 } 12123 }
11922 // Propagated type is [List] here: incorrect. 12124 // Propagated type is [List] here: incorrect.
11923 // Best we can do is [Object]? 12125 // Best we can do is [Object]?
11924 return z; // marker 12126 return z; // marker
11925 }''', null, typeProvider.dynamicType); 12127 }''',
12128 null,
12129 typeProvider.dynamicType);
11926 } 12130 }
11927 12131
11928 void fail_mergePropagatedTypesAtJoinPoint_7() { 12132 void fail_mergePropagatedTypesAtJoinPoint_7() {
11929 // https://code.google.com/p/dart/issues/detail?id=19929 12133 // https://code.google.com/p/dart/issues/detail?id=19929
11930 // 12134 //
11931 // In general [continue]s are unsafe for the purposes of 12135 // In general [continue]s are unsafe for the purposes of
11932 // [isAbruptTerminationStatement]. 12136 // [isAbruptTerminationStatement].
11933 // 12137 //
11934 // This is like example 6, but less tricky: the code in the branch that 12138 // This is like example 6, but less tricky: the code in the branch that
11935 // [continue]s is in effect after the [if]. 12139 // [continue]s is in effect after the [if].
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
12155 expect(identifier.propagatedType, same(stringType)); 12359 expect(identifier.propagatedType, same(stringType));
12156 } 12360 }
12157 // in the loop body 12361 // in the loop body
12158 { 12362 {
12159 SimpleIdentifier identifier = EngineTestCase.findNode( 12363 SimpleIdentifier identifier = EngineTestCase.findNode(
12160 unit, code, "e;", (node) => node is SimpleIdentifier); 12364 unit, code, "e;", (node) => node is SimpleIdentifier);
12161 expect(identifier.propagatedType, same(stringType)); 12365 expect(identifier.propagatedType, same(stringType));
12162 } 12366 }
12163 } 12367 }
12164 12368
12369 void test_forEach_async() {
12370 String code = r'''
12371 import 'dart:async';
12372 f(Stream<String> stream) async {
12373 await for (var e in stream) {
12374 e;
12375 }
12376 }''';
12377 Source source = addSource(code);
12378 LibraryElement library = resolve2(source);
12379 assertNoErrors(source);
12380 verify([source]);
12381 CompilationUnit unit = resolveCompilationUnit(source, library);
12382 InterfaceType stringType = typeProvider.stringType;
12383 // in the declaration
12384 {
12385 SimpleIdentifier identifier = EngineTestCase.findNode(
12386 unit, code, "e in", (node) => node is SimpleIdentifier);
12387 expect(identifier.propagatedType, same(stringType));
12388 }
12389 // in the loop body
12390 {
12391 SimpleIdentifier identifier = EngineTestCase.findNode(
12392 unit, code, "e;", (node) => node is SimpleIdentifier);
12393 expect(identifier.propagatedType, same(stringType));
12394 }
12395 }
12396
12165 void test_functionExpression_asInvocationArgument() { 12397 void test_functionExpression_asInvocationArgument() {
12166 String code = r''' 12398 String code = r'''
12167 class MyMap<K, V> { 12399 class MyMap<K, V> {
12168 forEach(f(K key, V value)) {} 12400 forEach(f(K key, V value)) {}
12169 } 12401 }
12170 f(MyMap<int, String> m) { 12402 f(MyMap<int, String> m) {
12171 m.forEach((k, v) { 12403 m.forEach((k, v) {
12172 k; 12404 k;
12173 v; 12405 v;
12174 }); 12406 });
(...skipping 802 matching lines...) Expand 10 before | Expand all | Expand 10 after
12977 SimpleIdentifier identifier = _findMarkedIdentifier(code, "v;"); 13209 SimpleIdentifier identifier = _findMarkedIdentifier(code, "v;");
12978 expect(identifier.propagatedType, null); 13210 expect(identifier.propagatedType, null);
12979 } 13211 }
12980 { 13212 {
12981 SimpleIdentifier identifier = _findMarkedIdentifier(code, "v = '';"); 13213 SimpleIdentifier identifier = _findMarkedIdentifier(code, "v = '';");
12982 expect(identifier.propagatedType, typeProvider.stringType); 13214 expect(identifier.propagatedType, typeProvider.stringType);
12983 } 13215 }
12984 } 13216 }
12985 13217
12986 void test_mergePropagatedTypes_afterIfThen_same() { 13218 void test_mergePropagatedTypes_afterIfThen_same() {
12987 _assertTypeOfMarkedExpression(r''' 13219 _assertTypeOfMarkedExpression(
13220 r'''
12988 main() { 13221 main() {
12989 var v = 1; 13222 var v = 1;
12990 if (v != null) { 13223 if (v != null) {
12991 v = 2; 13224 v = 2;
12992 } 13225 }
12993 return v; // marker 13226 return v; // marker
12994 }''', null, typeProvider.intType); 13227 }''',
13228 null,
13229 typeProvider.intType);
12995 } 13230 }
12996 13231
12997 void test_mergePropagatedTypes_afterIfThenElse_different() { 13232 void test_mergePropagatedTypes_afterIfThenElse_different() {
12998 _assertTypeOfMarkedExpression(r''' 13233 _assertTypeOfMarkedExpression(
13234 r'''
12999 main() { 13235 main() {
13000 var v = 1; 13236 var v = 1;
13001 if (v != null) { 13237 if (v != null) {
13002 v = 2; 13238 v = 2;
13003 } else { 13239 } else {
13004 v = '3'; 13240 v = '3';
13005 } 13241 }
13006 return v; // marker 13242 return v; // marker
13007 }''', null, null); 13243 }''',
13244 null,
13245 null);
13008 } 13246 }
13009 13247
13010 void test_mergePropagatedTypes_afterIfThenElse_same() { 13248 void test_mergePropagatedTypes_afterIfThenElse_same() {
13011 _assertTypeOfMarkedExpression(r''' 13249 _assertTypeOfMarkedExpression(
13250 r'''
13012 main() { 13251 main() {
13013 var v = 1; 13252 var v = 1;
13014 if (v != null) { 13253 if (v != null) {
13015 v = 2; 13254 v = 2;
13016 } else { 13255 } else {
13017 v = 3; 13256 v = 3;
13018 } 13257 }
13019 return v; // marker 13258 return v; // marker
13020 }''', null, typeProvider.intType); 13259 }''',
13260 null,
13261 typeProvider.intType);
13021 } 13262 }
13022 13263
13023 void test_mergePropagatedTypesAtJoinPoint_4() { 13264 void test_mergePropagatedTypesAtJoinPoint_4() {
13024 // https://code.google.com/p/dart/issues/detail?id=19929 13265 // https://code.google.com/p/dart/issues/detail?id=19929
13025 _assertTypeOfMarkedExpression(r''' 13266 _assertTypeOfMarkedExpression(
13267 r'''
13026 f5(x) { 13268 f5(x) {
13027 var y = []; 13269 var y = [];
13028 if (x) { 13270 if (x) {
13029 y = 0; 13271 y = 0;
13030 } else { 13272 } else {
13031 return y; 13273 return y;
13032 } 13274 }
13033 // Propagated type is [int] here: correct. 13275 // Propagated type is [int] here: correct.
13034 return y; // marker 13276 return y; // marker
13035 }''', null, typeProvider.intType); 13277 }''',
13278 null,
13279 typeProvider.intType);
13036 } 13280 }
13037 13281
13038 void test_mutatedOutsideScope() { 13282 void test_mutatedOutsideScope() {
13039 // https://code.google.com/p/dart/issues/detail?id=22732 13283 // https://code.google.com/p/dart/issues/detail?id=22732
13040 Source source = addSource(r''' 13284 Source source = addSource(r'''
13041 class Base { 13285 class Base {
13042 } 13286 }
13043 13287
13044 class Derived extends Base { 13288 class Derived extends Base {
13045 get y => null; 13289 get y => null;
(...skipping 20 matching lines...) Expand all
13066 assertNoErrors(source); 13310 assertNoErrors(source);
13067 } 13311 }
13068 13312
13069 void test_objectMethodOnDynamicExpression_doubleEquals() { 13313 void test_objectMethodOnDynamicExpression_doubleEquals() {
13070 // https://code.google.com/p/dart/issues/detail?id=20342 13314 // https://code.google.com/p/dart/issues/detail?id=20342
13071 // 13315 //
13072 // This was not actually part of Issue 20342, since the spec specifies a 13316 // This was not actually part of Issue 20342, since the spec specifies a
13073 // static type of [bool] for [==] comparison and the implementation 13317 // static type of [bool] for [==] comparison and the implementation
13074 // was already consistent with the spec there. But, it's another 13318 // was already consistent with the spec there. But, it's another
13075 // [Object] method, so it's included here. 13319 // [Object] method, so it's included here.
13076 _assertTypeOfMarkedExpression(r''' 13320 _assertTypeOfMarkedExpression(
13321 r'''
13077 f1(x) { 13322 f1(x) {
13078 var v = (x == x); 13323 var v = (x == x);
13079 return v; // marker 13324 return v; // marker
13080 }''', null, typeProvider.boolType); 13325 }''',
13326 null,
13327 typeProvider.boolType);
13081 } 13328 }
13082 13329
13083 void test_objectMethodOnDynamicExpression_hashCode() { 13330 void test_objectMethodOnDynamicExpression_hashCode() {
13084 // https://code.google.com/p/dart/issues/detail?id=20342 13331 // https://code.google.com/p/dart/issues/detail?id=20342
13085 _assertTypeOfMarkedExpression(r''' 13332 _assertTypeOfMarkedExpression(
13333 r'''
13086 f1(x) { 13334 f1(x) {
13087 var v = x.hashCode; 13335 var v = x.hashCode;
13088 return v; // marker 13336 return v; // marker
13089 }''', null, typeProvider.intType); 13337 }''',
13338 null,
13339 typeProvider.intType);
13090 } 13340 }
13091 13341
13092 void test_objectMethodOnDynamicExpression_runtimeType() { 13342 void test_objectMethodOnDynamicExpression_runtimeType() {
13093 // https://code.google.com/p/dart/issues/detail?id=20342 13343 // https://code.google.com/p/dart/issues/detail?id=20342
13094 _assertTypeOfMarkedExpression(r''' 13344 _assertTypeOfMarkedExpression(
13345 r'''
13095 f1(x) { 13346 f1(x) {
13096 var v = x.runtimeType; 13347 var v = x.runtimeType;
13097 return v; // marker 13348 return v; // marker
13098 }''', null, typeProvider.typeType); 13349 }''',
13350 null,
13351 typeProvider.typeType);
13099 } 13352 }
13100 13353
13101 void test_objectMethodOnDynamicExpression_toString() { 13354 void test_objectMethodOnDynamicExpression_toString() {
13102 // https://code.google.com/p/dart/issues/detail?id=20342 13355 // https://code.google.com/p/dart/issues/detail?id=20342
13103 _assertTypeOfMarkedExpression(r''' 13356 _assertTypeOfMarkedExpression(
13357 r'''
13104 f1(x) { 13358 f1(x) {
13105 var v = x.toString(); 13359 var v = x.toString();
13106 return v; // marker 13360 return v; // marker
13107 }''', null, typeProvider.stringType); 13361 }''',
13362 null,
13363 typeProvider.stringType);
13108 } 13364 }
13109 13365
13110 void test_propagatedReturnType_function_hasReturnType_returnsNull() { 13366 void test_propagatedReturnType_function_hasReturnType_returnsNull() {
13111 String code = r''' 13367 String code = r'''
13112 String f() => null; 13368 String f() => null;
13113 main() { 13369 main() {
13114 var v = f(); 13370 var v = f();
13115 }'''; 13371 }''';
13116 _assertPropagatedReturnType( 13372 _assertPropagatedReturnType(
13117 code, typeProvider.dynamicType, typeProvider.stringType); 13373 code, typeProvider.dynamicType, typeProvider.stringType);
(...skipping 603 matching lines...) Expand 10 before | Expand all | Expand 10 after
13721 } 13977 }
13722 13978
13723 void test_visitFunctionDeclaration() { 13979 void test_visitFunctionDeclaration() {
13724 // R f(P p) {} 13980 // R f(P p) {}
13725 // class R {} 13981 // class R {}
13726 // class P {} 13982 // class P {}
13727 ClassElement elementR = ElementFactory.classElement2('R'); 13983 ClassElement elementR = ElementFactory.classElement2('R');
13728 ClassElement elementP = ElementFactory.classElement2('P'); 13984 ClassElement elementP = ElementFactory.classElement2('P');
13729 FunctionElement elementF = ElementFactory.functionElement('f'); 13985 FunctionElement elementF = ElementFactory.functionElement('f');
13730 FunctionDeclaration declaration = AstFactory.functionDeclaration( 13986 FunctionDeclaration declaration = AstFactory.functionDeclaration(
13731 AstFactory.typeName4('R'), null, 'f', AstFactory.functionExpression2( 13987 AstFactory.typeName4('R'),
13988 null,
13989 'f',
13990 AstFactory.functionExpression2(
13732 AstFactory.formalParameterList([ 13991 AstFactory.formalParameterList([
13733 AstFactory.simpleFormalParameter4(AstFactory.typeName4('P'), 'p') 13992 AstFactory.simpleFormalParameter4(AstFactory.typeName4('P'), 'p')
13734 ]), null)); 13993 ]),
13994 null));
13735 declaration.name.staticElement = elementF; 13995 declaration.name.staticElement = elementF;
13736 _resolveNode(declaration, [elementR, elementP]); 13996 _resolveNode(declaration, [elementR, elementP]);
13737 expect(declaration.returnType.type, elementR.type); 13997 expect(declaration.returnType.type, elementR.type);
13738 SimpleFormalParameter parameter = 13998 SimpleFormalParameter parameter =
13739 declaration.functionExpression.parameters.parameters[0]; 13999 declaration.functionExpression.parameters.parameters[0];
13740 expect(parameter.type.type, elementP.type); 14000 expect(parameter.type.type, elementP.type);
13741 _listener.assertNoErrors(); 14001 _listener.assertNoErrors();
13742 } 14002 }
13743 14003
13744 void test_visitFunctionDeclaration_typeParameter() { 14004 void test_visitFunctionDeclaration_typeParameter() {
13745 // E f<E>(E e) {} 14005 // E f<E>(E e) {}
13746 TypeParameterElement elementE = ElementFactory.typeParameterElement('E'); 14006 TypeParameterElement elementE = ElementFactory.typeParameterElement('E');
13747 FunctionElementImpl elementF = ElementFactory.functionElement('f'); 14007 FunctionElementImpl elementF = ElementFactory.functionElement('f');
13748 elementF.typeParameters = <TypeParameterElement>[elementE]; 14008 elementF.typeParameters = <TypeParameterElement>[elementE];
13749 FunctionDeclaration declaration = AstFactory.functionDeclaration( 14009 FunctionDeclaration declaration = AstFactory.functionDeclaration(
13750 AstFactory.typeName4('E'), null, 'f', AstFactory.functionExpression2( 14010 AstFactory.typeName4('E'),
14011 null,
14012 'f',
14013 AstFactory.functionExpression2(
13751 AstFactory.formalParameterList([ 14014 AstFactory.formalParameterList([
13752 AstFactory.simpleFormalParameter4(AstFactory.typeName4('E'), 'e') 14015 AstFactory.simpleFormalParameter4(AstFactory.typeName4('E'), 'e')
13753 ]), null)); 14016 ]),
14017 null));
13754 declaration.name.staticElement = elementF; 14018 declaration.name.staticElement = elementF;
13755 _resolveNode(declaration, []); 14019 _resolveNode(declaration, []);
13756 expect(declaration.returnType.type, elementE.type); 14020 expect(declaration.returnType.type, elementE.type);
13757 SimpleFormalParameter parameter = 14021 SimpleFormalParameter parameter =
13758 declaration.functionExpression.parameters.parameters[0]; 14022 declaration.functionExpression.parameters.parameters[0];
13759 expect(parameter.type.type, elementE.type); 14023 expect(parameter.type.type, elementE.type);
13760 _listener.assertNoErrors(); 14024 _listener.assertNoErrors();
13761 } 14025 }
13762 14026
13763 void test_visitFunctionTypedFormalParameter() { 14027 void test_visitFunctionTypedFormalParameter() {
13764 // R f(R g(P p)) {} 14028 // R f(R g(P p)) {}
13765 // class R {} 14029 // class R {}
13766 // class P {} 14030 // class P {}
13767 ClassElement elementR = ElementFactory.classElement2('R'); 14031 ClassElement elementR = ElementFactory.classElement2('R');
13768 ClassElement elementP = ElementFactory.classElement2('P'); 14032 ClassElement elementP = ElementFactory.classElement2('P');
13769 FunctionElement elementF = ElementFactory.functionElement('f'); 14033 FunctionElement elementF = ElementFactory.functionElement('f');
13770 ParameterElementImpl requiredParameter = 14034 ParameterElementImpl requiredParameter =
13771 ElementFactory.requiredParameter('p'); 14035 ElementFactory.requiredParameter('p');
13772 FunctionTypedFormalParameter parameterDeclaration = AstFactory 14036 FunctionTypedFormalParameter parameterDeclaration = AstFactory
13773 .functionTypedFormalParameter(AstFactory.typeName4('R'), 'g', [ 14037 .functionTypedFormalParameter(AstFactory.typeName4('R'), 'g', [
13774 AstFactory.simpleFormalParameter4(AstFactory.typeName4('P'), 'p') 14038 AstFactory.simpleFormalParameter4(AstFactory.typeName4('P'), 'p')
13775 ]); 14039 ]);
13776 parameterDeclaration.identifier.staticElement = requiredParameter; 14040 parameterDeclaration.identifier.staticElement = requiredParameter;
13777 FunctionDeclaration declaration = AstFactory.functionDeclaration( 14041 FunctionDeclaration declaration = AstFactory.functionDeclaration(
13778 AstFactory.typeName4('R'), null, 'f', AstFactory.functionExpression2( 14042 AstFactory.typeName4('R'),
14043 null,
14044 'f',
14045 AstFactory.functionExpression2(
13779 AstFactory.formalParameterList([parameterDeclaration]), null)); 14046 AstFactory.formalParameterList([parameterDeclaration]), null));
13780 declaration.name.staticElement = elementF; 14047 declaration.name.staticElement = elementF;
13781 _resolveNode(declaration, [elementR, elementP]); 14048 _resolveNode(declaration, [elementR, elementP]);
13782 expect(declaration.returnType.type, elementR.type); 14049 expect(declaration.returnType.type, elementR.type);
13783 FunctionTypedFormalParameter parameter = 14050 FunctionTypedFormalParameter parameter =
13784 declaration.functionExpression.parameters.parameters[0]; 14051 declaration.functionExpression.parameters.parameters[0];
13785 expect(parameter.returnType.type, elementR.type); 14052 expect(parameter.returnType.type, elementR.type);
13786 SimpleFormalParameter innerParameter = parameter.parameters.parameters[0]; 14053 SimpleFormalParameter innerParameter = parameter.parameters.parameters[0];
13787 expect(innerParameter.type.type, elementP.type); 14054 expect(innerParameter.type.type, elementP.type);
13788 _listener.assertNoErrors(); 14055 _listener.assertNoErrors();
13789 } 14056 }
13790 14057
13791 void test_visitFunctionTypedFormalParameter_typeParameter() { 14058 void test_visitFunctionTypedFormalParameter_typeParameter() {
13792 // R f(R g<E>(E e)) {} 14059 // R f(R g<E>(E e)) {}
13793 // class R {} 14060 // class R {}
13794 ClassElement elementR = ElementFactory.classElement2('R'); 14061 ClassElement elementR = ElementFactory.classElement2('R');
13795 TypeParameterElement elementE = ElementFactory.typeParameterElement('E'); 14062 TypeParameterElement elementE = ElementFactory.typeParameterElement('E');
13796 FunctionElement elementF = ElementFactory.functionElement('f'); 14063 FunctionElement elementF = ElementFactory.functionElement('f');
13797 ParameterElementImpl requiredParameter = 14064 ParameterElementImpl requiredParameter =
13798 ElementFactory.requiredParameter('g'); 14065 ElementFactory.requiredParameter('g');
13799 requiredParameter.typeParameters = <TypeParameterElement>[elementE]; 14066 requiredParameter.typeParameters = <TypeParameterElement>[elementE];
13800 FunctionTypedFormalParameter parameterDeclaration = AstFactory 14067 FunctionTypedFormalParameter parameterDeclaration = AstFactory
13801 .functionTypedFormalParameter(AstFactory.typeName4('R'), 'g', [ 14068 .functionTypedFormalParameter(AstFactory.typeName4('R'), 'g', [
13802 AstFactory.simpleFormalParameter4(AstFactory.typeName4('E'), 'e') 14069 AstFactory.simpleFormalParameter4(AstFactory.typeName4('E'), 'e')
13803 ]); 14070 ]);
13804 parameterDeclaration.identifier.staticElement = requiredParameter; 14071 parameterDeclaration.identifier.staticElement = requiredParameter;
13805 FunctionDeclaration declaration = AstFactory.functionDeclaration( 14072 FunctionDeclaration declaration = AstFactory.functionDeclaration(
13806 AstFactory.typeName4('R'), null, 'f', AstFactory.functionExpression2( 14073 AstFactory.typeName4('R'),
14074 null,
14075 'f',
14076 AstFactory.functionExpression2(
13807 AstFactory.formalParameterList([parameterDeclaration]), null)); 14077 AstFactory.formalParameterList([parameterDeclaration]), null));
13808 declaration.name.staticElement = elementF; 14078 declaration.name.staticElement = elementF;
13809 _resolveNode(declaration, [elementR]); 14079 _resolveNode(declaration, [elementR]);
13810 expect(declaration.returnType.type, elementR.type); 14080 expect(declaration.returnType.type, elementR.type);
13811 FunctionTypedFormalParameter parameter = 14081 FunctionTypedFormalParameter parameter =
13812 declaration.functionExpression.parameters.parameters[0]; 14082 declaration.functionExpression.parameters.parameters[0];
13813 expect(parameter.returnType.type, elementR.type); 14083 expect(parameter.returnType.type, elementR.type);
13814 SimpleFormalParameter innerParameter = parameter.parameters.parameters[0]; 14084 SimpleFormalParameter innerParameter = parameter.parameters.parameters[0];
13815 expect(innerParameter.type.type, elementE.type); 14085 expect(innerParameter.type.type, elementE.type);
13816 _listener.assertNoErrors(); 14086 _listener.assertNoErrors();
13817 } 14087 }
13818 14088
13819 void test_visitMethodDeclaration() { 14089 void test_visitMethodDeclaration() {
13820 // class A { 14090 // class A {
13821 // R m(P p) {} 14091 // R m(P p) {}
13822 // } 14092 // }
13823 // class R {} 14093 // class R {}
13824 // class P {} 14094 // class P {}
13825 ClassElementImpl elementA = ElementFactory.classElement2('A'); 14095 ClassElementImpl elementA = ElementFactory.classElement2('A');
13826 ClassElement elementR = ElementFactory.classElement2('R'); 14096 ClassElement elementR = ElementFactory.classElement2('R');
13827 ClassElement elementP = ElementFactory.classElement2('P'); 14097 ClassElement elementP = ElementFactory.classElement2('P');
13828 MethodElement elementM = ElementFactory.methodElement('m', null); 14098 MethodElement elementM = ElementFactory.methodElement('m', null);
13829 elementA.methods = <MethodElement>[elementM]; 14099 elementA.methods = <MethodElement>[elementM];
13830 MethodDeclaration declaration = AstFactory.methodDeclaration(null, 14100 MethodDeclaration declaration = AstFactory.methodDeclaration(
13831 AstFactory.typeName4('R'), null, null, AstFactory.identifier3('m'), 14101 null,
14102 AstFactory.typeName4('R'),
14103 null,
14104 null,
14105 AstFactory.identifier3('m'),
13832 AstFactory.formalParameterList([ 14106 AstFactory.formalParameterList([
13833 AstFactory.simpleFormalParameter4(AstFactory.typeName4('P'), 'p') 14107 AstFactory.simpleFormalParameter4(AstFactory.typeName4('P'), 'p')
13834 ])); 14108 ]));
13835 declaration.name.staticElement = elementM; 14109 declaration.name.staticElement = elementM;
13836 _resolveNode(declaration, [elementA, elementR, elementP]); 14110 _resolveNode(declaration, [elementA, elementR, elementP]);
13837 expect(declaration.returnType.type, elementR.type); 14111 expect(declaration.returnType.type, elementR.type);
13838 SimpleFormalParameter parameter = declaration.parameters.parameters[0]; 14112 SimpleFormalParameter parameter = declaration.parameters.parameters[0];
13839 expect(parameter.type.type, elementP.type); 14113 expect(parameter.type.type, elementP.type);
13840 _listener.assertNoErrors(); 14114 _listener.assertNoErrors();
13841 } 14115 }
13842 14116
13843 void test_visitMethodDeclaration_typeParameter() { 14117 void test_visitMethodDeclaration_typeParameter() {
13844 // class A { 14118 // class A {
13845 // E m<E>(E e) {} 14119 // E m<E>(E e) {}
13846 // } 14120 // }
13847 ClassElementImpl elementA = ElementFactory.classElement2('A'); 14121 ClassElementImpl elementA = ElementFactory.classElement2('A');
13848 TypeParameterElement elementE = ElementFactory.typeParameterElement('E'); 14122 TypeParameterElement elementE = ElementFactory.typeParameterElement('E');
13849 MethodElementImpl elementM = ElementFactory.methodElement('m', null); 14123 MethodElementImpl elementM = ElementFactory.methodElement('m', null);
13850 elementM.typeParameters = <TypeParameterElement>[elementE]; 14124 elementM.typeParameters = <TypeParameterElement>[elementE];
13851 elementA.methods = <MethodElement>[elementM]; 14125 elementA.methods = <MethodElement>[elementM];
13852 MethodDeclaration declaration = AstFactory.methodDeclaration(null, 14126 MethodDeclaration declaration = AstFactory.methodDeclaration(
13853 AstFactory.typeName4('E'), null, null, AstFactory.identifier3('m'), 14127 null,
14128 AstFactory.typeName4('E'),
14129 null,
14130 null,
14131 AstFactory.identifier3('m'),
13854 AstFactory.formalParameterList([ 14132 AstFactory.formalParameterList([
13855 AstFactory.simpleFormalParameter4(AstFactory.typeName4('E'), 'e') 14133 AstFactory.simpleFormalParameter4(AstFactory.typeName4('E'), 'e')
13856 ])); 14134 ]));
13857 declaration.name.staticElement = elementM; 14135 declaration.name.staticElement = elementM;
13858 _resolveNode(declaration, [elementA]); 14136 _resolveNode(declaration, [elementA]);
13859 expect(declaration.returnType.type, elementE.type); 14137 expect(declaration.returnType.type, elementE.type);
13860 SimpleFormalParameter parameter = declaration.parameters.parameters[0]; 14138 SimpleFormalParameter parameter = declaration.parameters.parameters[0];
13861 expect(parameter.type.type, elementE.type); 14139 expect(parameter.type.type, elementE.type);
13862 _listener.assertNoErrors(); 14140 _listener.assertNoErrors();
13863 } 14141 }
13864 14142
13865 void test_visitSimpleFormalParameter_noType() { 14143 void test_visitSimpleFormalParameter_noType() {
13866 // p 14144 // p
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
14039 // check propagated type 14317 // check propagated type
14040 FunctionType propagatedType = node.propagatedType as FunctionType; 14318 FunctionType propagatedType = node.propagatedType as FunctionType;
14041 expect(propagatedType.returnType, test.typeProvider.stringType); 14319 expect(propagatedType.returnType, test.typeProvider.stringType);
14042 } on AnalysisException catch (e, stackTrace) { 14320 } on AnalysisException catch (e, stackTrace) {
14043 thrownException[0] = new CaughtException(e, stackTrace); 14321 thrownException[0] = new CaughtException(e, stackTrace);
14044 } 14322 }
14045 } 14323 }
14046 return null; 14324 return null;
14047 } 14325 }
14048 } 14326 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/generated/testing/element_factory.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698