| OLD | NEW |
| 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/generated/ast.dart'; | 9 import 'package:analyzer/src/generated/ast.dart'; |
| 10 import 'package:analyzer/src/generated/element.dart'; | 10 import 'package:analyzer/src/generated/element.dart'; |
| (...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 265 contextElement, | 265 contextElement, |
| 266 context2dElement, | 266 context2dElement, |
| 267 ElementFactory.classElement("DivElement", elementType), | 267 ElementFactory.classElement("DivElement", elementType), |
| 268 documentElement, | 268 documentElement, |
| 269 elementElement, | 269 elementElement, |
| 270 htmlDocumentElement, | 270 htmlDocumentElement, |
| 271 ElementFactory.classElement("InputElement", elementType), | 271 ElementFactory.classElement("InputElement", elementType), |
| 272 ElementFactory.classElement("SelectElement", elementType) | 272 ElementFactory.classElement("SelectElement", elementType) |
| 273 ]; | 273 ]; |
| 274 htmlUnit.functions = <FunctionElement>[ | 274 htmlUnit.functions = <FunctionElement>[ |
| 275 ElementFactory.functionElement3("query", elementElement, <ClassElement>[ | 275 ElementFactory.functionElement3("query", elementElement, |
| 276 provider.stringType.element | 276 <ClassElement>[provider.stringType.element], |
| 277 ], ClassElementImpl.EMPTY_ARRAY) | 277 ClassElementImpl.EMPTY_ARRAY) |
| 278 ]; | 278 ]; |
| 279 TopLevelVariableElementImpl document = ElementFactory | 279 TopLevelVariableElementImpl document = ElementFactory |
| 280 .topLevelVariableElement3( | 280 .topLevelVariableElement3( |
| 281 "document", false, true, htmlDocumentElement.type); | 281 "document", false, true, htmlDocumentElement.type); |
| 282 htmlUnit.topLevelVariables = <TopLevelVariableElement>[document]; | 282 htmlUnit.topLevelVariables = <TopLevelVariableElement>[document]; |
| 283 htmlUnit.accessors = <PropertyAccessorElement>[document.getter]; | 283 htmlUnit.accessors = <PropertyAccessorElement>[document.getter]; |
| 284 LibraryElementImpl htmlLibrary = new LibraryElementImpl.forNode( | 284 LibraryElementImpl htmlLibrary = new LibraryElementImpl.forNode( |
| 285 coreContext, AstFactory.libraryIdentifier2(["dart", "dom", "html"])); | 285 coreContext, AstFactory.libraryIdentifier2(["dart", "dom", "html"])); |
| 286 htmlLibrary.definingCompilationUnit = htmlUnit; | 286 htmlLibrary.definingCompilationUnit = htmlUnit; |
| 287 // | 287 // |
| 288 // dart:math | 288 // dart:math |
| 289 // | 289 // |
| 290 CompilationUnitElementImpl mathUnit = | 290 CompilationUnitElementImpl mathUnit = |
| 291 new CompilationUnitElementImpl("math.dart"); | 291 new CompilationUnitElementImpl("math.dart"); |
| 292 Source mathSource = sourceFactory.forUri(_DART_MATH); | 292 Source mathSource = sourceFactory.forUri(_DART_MATH); |
| 293 coreContext.setContents(mathSource, ""); | 293 coreContext.setContents(mathSource, ""); |
| 294 mathUnit.source = mathSource; | 294 mathUnit.source = mathSource; |
| 295 FunctionElement cosElement = ElementFactory.functionElement3("cos", | 295 FunctionElement cosElement = ElementFactory.functionElement3("cos", |
| 296 provider.doubleType.element, <ClassElement>[ | 296 provider.doubleType.element, <ClassElement>[provider.numType.element], |
| 297 provider.numType.element | 297 ClassElementImpl.EMPTY_ARRAY); |
| 298 ], ClassElementImpl.EMPTY_ARRAY); | |
| 299 TopLevelVariableElement ln10Element = ElementFactory | 298 TopLevelVariableElement ln10Element = ElementFactory |
| 300 .topLevelVariableElement3("LN10", true, false, provider.doubleType); | 299 .topLevelVariableElement3("LN10", true, false, provider.doubleType); |
| 301 TopLevelVariableElement piElement = ElementFactory.topLevelVariableElement3( | 300 TopLevelVariableElement piElement = ElementFactory.topLevelVariableElement3( |
| 302 "PI", true, false, provider.doubleType); | 301 "PI", true, false, provider.doubleType); |
| 303 ClassElementImpl randomElement = ElementFactory.classElement2("Random"); | 302 ClassElementImpl randomElement = ElementFactory.classElement2("Random"); |
| 304 randomElement.abstract = true; | 303 randomElement.abstract = true; |
| 305 ConstructorElementImpl randomConstructor = | 304 ConstructorElementImpl randomConstructor = |
| 306 ElementFactory.constructorElement2(randomElement, null); | 305 ElementFactory.constructorElement2(randomElement, null); |
| 307 randomConstructor.factory = true; | 306 randomConstructor.factory = true; |
| 308 ParameterElementImpl seedParam = new ParameterElementImpl("seed", 0); | 307 ParameterElementImpl seedParam = new ParameterElementImpl("seed", 0); |
| 309 seedParam.parameterKind = ParameterKind.POSITIONAL; | 308 seedParam.parameterKind = ParameterKind.POSITIONAL; |
| 310 seedParam.type = provider.intType; | 309 seedParam.type = provider.intType; |
| 311 randomConstructor.parameters = <ParameterElement>[seedParam]; | 310 randomConstructor.parameters = <ParameterElement>[seedParam]; |
| 312 randomElement.constructors = <ConstructorElement>[randomConstructor]; | 311 randomElement.constructors = <ConstructorElement>[randomConstructor]; |
| 313 FunctionElement sinElement = ElementFactory.functionElement3("sin", | 312 FunctionElement sinElement = ElementFactory.functionElement3("sin", |
| 314 provider.doubleType.element, <ClassElement>[ | 313 provider.doubleType.element, <ClassElement>[provider.numType.element], |
| 315 provider.numType.element | 314 ClassElementImpl.EMPTY_ARRAY); |
| 316 ], ClassElementImpl.EMPTY_ARRAY); | |
| 317 FunctionElement sqrtElement = ElementFactory.functionElement3("sqrt", | 315 FunctionElement sqrtElement = ElementFactory.functionElement3("sqrt", |
| 318 provider.doubleType.element, <ClassElement>[ | 316 provider.doubleType.element, <ClassElement>[provider.numType.element], |
| 319 provider.numType.element | 317 ClassElementImpl.EMPTY_ARRAY); |
| 320 ], ClassElementImpl.EMPTY_ARRAY); | |
| 321 mathUnit.accessors = <PropertyAccessorElement>[ | 318 mathUnit.accessors = <PropertyAccessorElement>[ |
| 322 ln10Element.getter, | 319 ln10Element.getter, |
| 323 piElement.getter | 320 piElement.getter |
| 324 ]; | 321 ]; |
| 325 mathUnit.functions = <FunctionElement>[cosElement, sinElement, sqrtElement]; | 322 mathUnit.functions = <FunctionElement>[cosElement, sinElement, sqrtElement]; |
| 326 mathUnit.topLevelVariables = <TopLevelVariableElement>[ | 323 mathUnit.topLevelVariables = <TopLevelVariableElement>[ |
| 327 ln10Element, | 324 ln10Element, |
| 328 piElement | 325 piElement |
| 329 ]; | 326 ]; |
| 330 mathUnit.types = <ClassElement>[randomElement]; | 327 mathUnit.types = <ClassElement>[randomElement]; |
| (...skipping 1199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1530 ConstructorElementImpl constructor = | 1527 ConstructorElementImpl constructor = |
| 1531 ElementFactory.constructorElement2(classA, constructorName); | 1528 ElementFactory.constructorElement2(classA, constructorName); |
| 1532 String parameterName = "a"; | 1529 String parameterName = "a"; |
| 1533 ParameterElement parameter = ElementFactory.namedParameter(parameterName); | 1530 ParameterElement parameter = ElementFactory.namedParameter(parameterName); |
| 1534 constructor.parameters = <ParameterElement>[parameter]; | 1531 constructor.parameters = <ParameterElement>[parameter]; |
| 1535 classA.constructors = <ConstructorElement>[constructor]; | 1532 classA.constructors = <ConstructorElement>[constructor]; |
| 1536 ConstructorName name = AstFactory.constructorName( | 1533 ConstructorName name = AstFactory.constructorName( |
| 1537 AstFactory.typeName(classA), constructorName); | 1534 AstFactory.typeName(classA), constructorName); |
| 1538 name.staticElement = constructor; | 1535 name.staticElement = constructor; |
| 1539 InstanceCreationExpression creation = AstFactory.instanceCreationExpression( | 1536 InstanceCreationExpression creation = AstFactory.instanceCreationExpression( |
| 1540 Keyword.NEW, name, [ | 1537 Keyword.NEW, name, |
| 1541 AstFactory.namedExpression2(parameterName, AstFactory.integer(0)) | 1538 [AstFactory.namedExpression2(parameterName, AstFactory.integer(0))]); |
| 1542 ]); | |
| 1543 _resolveNode(creation); | 1539 _resolveNode(creation); |
| 1544 expect(creation.staticElement, same(constructor)); | 1540 expect(creation.staticElement, same(constructor)); |
| 1545 expect((creation.argumentList.arguments[ | 1541 expect((creation.argumentList.arguments[ |
| 1546 0] as NamedExpression).name.label.staticElement, same(parameter)); | 1542 0] as NamedExpression).name.label.staticElement, same(parameter)); |
| 1547 _listener.assertNoErrors(); | 1543 _listener.assertNoErrors(); |
| 1548 } | 1544 } |
| 1549 | 1545 |
| 1550 void test_visitMethodInvocation() { | 1546 void test_visitMethodInvocation() { |
| 1551 InterfaceType numType = _typeProvider.numType; | 1547 InterfaceType numType = _typeProvider.numType; |
| 1552 SimpleIdentifier left = AstFactory.identifier3("i"); | 1548 SimpleIdentifier left = AstFactory.identifier3("i"); |
| (...skipping 3099 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4652 ClassElementImpl classI2 = ElementFactory.classElement2("I2"); | 4648 ClassElementImpl classI2 = ElementFactory.classElement2("I2"); |
| 4653 PropertyAccessorElement getter = | 4649 PropertyAccessorElement getter = |
| 4654 ElementFactory.getterElement(methodName, false, _typeProvider.intType); | 4650 ElementFactory.getterElement(methodName, false, _typeProvider.intType); |
| 4655 classI2.accessors = <PropertyAccessorElement>[getter]; | 4651 classI2.accessors = <PropertyAccessorElement>[getter]; |
| 4656 ClassElementImpl classA = ElementFactory.classElement2("A"); | 4652 ClassElementImpl classA = ElementFactory.classElement2("A"); |
| 4657 classA.interfaces = <InterfaceType>[classI2.type, classI1.type]; | 4653 classA.interfaces = <InterfaceType>[classI2.type, classI1.type]; |
| 4658 MemberMap mapA = | 4654 MemberMap mapA = |
| 4659 _inheritanceManager.getMapOfMembersInheritedFromInterfaces(classA); | 4655 _inheritanceManager.getMapOfMembersInheritedFromInterfaces(classA); |
| 4660 expect(mapA.size, _numOfMembersInObject); | 4656 expect(mapA.size, _numOfMembersInObject); |
| 4661 expect(mapA.get(methodName), isNull); | 4657 expect(mapA.get(methodName), isNull); |
| 4662 _assertErrors(classA, [ | 4658 _assertErrors(classA, |
| 4663 StaticWarningCode.INCONSISTENT_METHOD_INHERITANCE_GETTER_AND_METHOD | 4659 [StaticWarningCode.INCONSISTENT_METHOD_INHERITANCE_GETTER_AND_METHOD]); |
| 4664 ]); | |
| 4665 } | 4660 } |
| 4666 | 4661 |
| 4667 void test_getMapOfMembersInheritedFromInterfaces_inconsistentMethodInheritance
_int_str() { | 4662 void test_getMapOfMembersInheritedFromInterfaces_inconsistentMethodInheritance
_int_str() { |
| 4668 // class I1 { int m(); } | 4663 // class I1 { int m(); } |
| 4669 // class I2 { String m(); } | 4664 // class I2 { String m(); } |
| 4670 // class A implements I1, I2 {} | 4665 // class A implements I1, I2 {} |
| 4671 ClassElementImpl classI1 = ElementFactory.classElement2("I1"); | 4666 ClassElementImpl classI1 = ElementFactory.classElement2("I1"); |
| 4672 String methodName = "m"; | 4667 String methodName = "m"; |
| 4673 MethodElement methodM1 = | 4668 MethodElement methodM1 = |
| 4674 ElementFactory.methodElement(methodName, null, [_typeProvider.intType]); | 4669 ElementFactory.methodElement(methodName, null, [_typeProvider.intType]); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 4699 ClassElementImpl classI2 = ElementFactory.classElement2("I2"); | 4694 ClassElementImpl classI2 = ElementFactory.classElement2("I2"); |
| 4700 PropertyAccessorElement getter = | 4695 PropertyAccessorElement getter = |
| 4701 ElementFactory.getterElement(methodName, false, _typeProvider.intType); | 4696 ElementFactory.getterElement(methodName, false, _typeProvider.intType); |
| 4702 classI2.accessors = <PropertyAccessorElement>[getter]; | 4697 classI2.accessors = <PropertyAccessorElement>[getter]; |
| 4703 ClassElementImpl classA = ElementFactory.classElement2("A"); | 4698 ClassElementImpl classA = ElementFactory.classElement2("A"); |
| 4704 classA.interfaces = <InterfaceType>[classI1.type, classI2.type]; | 4699 classA.interfaces = <InterfaceType>[classI1.type, classI2.type]; |
| 4705 MemberMap mapA = | 4700 MemberMap mapA = |
| 4706 _inheritanceManager.getMapOfMembersInheritedFromInterfaces(classA); | 4701 _inheritanceManager.getMapOfMembersInheritedFromInterfaces(classA); |
| 4707 expect(mapA.size, _numOfMembersInObject); | 4702 expect(mapA.size, _numOfMembersInObject); |
| 4708 expect(mapA.get(methodName), isNull); | 4703 expect(mapA.get(methodName), isNull); |
| 4709 _assertErrors(classA, [ | 4704 _assertErrors(classA, |
| 4710 StaticWarningCode.INCONSISTENT_METHOD_INHERITANCE_GETTER_AND_METHOD | 4705 [StaticWarningCode.INCONSISTENT_METHOD_INHERITANCE_GETTER_AND_METHOD]); |
| 4711 ]); | |
| 4712 } | 4706 } |
| 4713 | 4707 |
| 4714 void test_getMapOfMembersInheritedFromInterfaces_inconsistentMethodInheritance
_numOfRequiredParams() { | 4708 void test_getMapOfMembersInheritedFromInterfaces_inconsistentMethodInheritance
_numOfRequiredParams() { |
| 4715 // class I1 { dynamic m(int, [int]); } | 4709 // class I1 { dynamic m(int, [int]); } |
| 4716 // class I2 { dynamic m(int, int, int); } | 4710 // class I2 { dynamic m(int, int, int); } |
| 4717 // class A implements I1, I2 {} | 4711 // class A implements I1, I2 {} |
| 4718 ClassElementImpl classI1 = ElementFactory.classElement2("I1"); | 4712 ClassElementImpl classI1 = ElementFactory.classElement2("I1"); |
| 4719 String methodName = "m"; | 4713 String methodName = "m"; |
| 4720 MethodElementImpl methodM1 = | 4714 MethodElementImpl methodM1 = |
| 4721 ElementFactory.methodElement(methodName, _typeProvider.dynamicType); | 4715 ElementFactory.methodElement(methodName, _typeProvider.dynamicType); |
| (...skipping 1348 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6070 List<LibraryElement> importedLibraries = library.importedLibraries; | 6064 List<LibraryElement> importedLibraries = library.importedLibraries; |
| 6071 assertNamedElements(importedLibraries, ["dart.core", "libB"]); | 6065 assertNamedElements(importedLibraries, ["dart.core", "libB"]); |
| 6072 } | 6066 } |
| 6073 } | 6067 } |
| 6074 | 6068 |
| 6075 @reflectiveTest | 6069 @reflectiveTest |
| 6076 class LibraryScopeTest extends ResolverTestCase { | 6070 class LibraryScopeTest extends ResolverTestCase { |
| 6077 void test_creation_empty() { | 6071 void test_creation_empty() { |
| 6078 LibraryElement definingLibrary = createDefaultTestLibrary(); | 6072 LibraryElement definingLibrary = createDefaultTestLibrary(); |
| 6079 GatheringErrorListener errorListener = new GatheringErrorListener(); | 6073 GatheringErrorListener errorListener = new GatheringErrorListener(); |
| 6080 new LibraryScope(definingLibrary, errorListener); | 6074 new LibraryScope(definingLibrary, |
| 6075 new LibraryImportScope(definingLibrary, errorListener), errorListener); |
| 6081 } | 6076 } |
| 6082 | 6077 |
| 6083 void test_creation_nonEmpty() { | 6078 void test_creation_nonEmpty() { |
| 6084 AnalysisContext context = new AnalysisContextImpl(); | 6079 AnalysisContext context = new AnalysisContextImpl(); |
| 6085 context.sourceFactory = new SourceFactory([]); | 6080 context.sourceFactory = new SourceFactory([]); |
| 6086 String importedTypeName = "A"; | 6081 String importedTypeName = "A"; |
| 6087 ClassElement importedType = | 6082 ClassElement importedType = |
| 6088 new ClassElementImpl.forNode(AstFactory.identifier3(importedTypeName)); | 6083 new ClassElementImpl.forNode(AstFactory.identifier3(importedTypeName)); |
| 6089 LibraryElement importedLibrary = createTestLibrary(context, "imported"); | 6084 LibraryElement importedLibrary = createTestLibrary(context, "imported"); |
| 6090 (importedLibrary.definingCompilationUnit as CompilationUnitElementImpl).type
s = | 6085 (importedLibrary.definingCompilationUnit as CompilationUnitElementImpl).type
s = |
| 6091 <ClassElement>[importedType]; | 6086 <ClassElement>[importedType]; |
| 6092 LibraryElementImpl definingLibrary = | 6087 LibraryElementImpl definingLibrary = |
| 6093 createTestLibrary(context, "importing"); | 6088 createTestLibrary(context, "importing"); |
| 6094 ImportElementImpl importElement = new ImportElementImpl(0); | 6089 ImportElementImpl importElement = new ImportElementImpl(0); |
| 6095 importElement.importedLibrary = importedLibrary; | 6090 importElement.importedLibrary = importedLibrary; |
| 6096 definingLibrary.imports = <ImportElement>[importElement]; | 6091 definingLibrary.imports = <ImportElement>[importElement]; |
| 6097 GatheringErrorListener errorListener = new GatheringErrorListener(); | 6092 GatheringErrorListener errorListener = new GatheringErrorListener(); |
| 6098 Scope scope = new LibraryScope(definingLibrary, errorListener); | 6093 Scope scope = new LibraryScope(definingLibrary, |
| 6094 new LibraryImportScope(definingLibrary, errorListener), errorListener); |
| 6099 expect( | 6095 expect( |
| 6100 scope.lookup(AstFactory.identifier3(importedTypeName), definingLibrary), | 6096 scope.lookup(AstFactory.identifier3(importedTypeName), definingLibrary), |
| 6101 importedType); | 6097 importedType); |
| 6102 } | 6098 } |
| 6103 | 6099 |
| 6104 void test_getErrorListener() { | 6100 void test_getErrorListener() { |
| 6105 LibraryElement definingLibrary = createDefaultTestLibrary(); | 6101 LibraryElement definingLibrary = createDefaultTestLibrary(); |
| 6106 GatheringErrorListener errorListener = new GatheringErrorListener(); | 6102 GatheringErrorListener errorListener = new GatheringErrorListener(); |
| 6107 LibraryScope scope = new LibraryScope(definingLibrary, errorListener); | 6103 LibraryScope scope = new LibraryScope(definingLibrary, |
| 6104 new LibraryImportScope(definingLibrary, errorListener), errorListener); |
| 6108 expect(scope.errorListener, errorListener); | 6105 expect(scope.errorListener, errorListener); |
| 6109 } | 6106 } |
| 6110 } | 6107 } |
| 6111 | 6108 |
| 6112 @reflectiveTest | 6109 @reflectiveTest |
| 6113 class LibraryTest extends EngineTestCase { | 6110 class LibraryTest extends EngineTestCase { |
| 6114 /** | 6111 /** |
| 6115 * The error listener to which all errors will be reported. | 6112 * The error listener to which all errors will be reported. |
| 6116 */ | 6113 */ |
| 6117 GatheringErrorListener _errorListener; | 6114 GatheringErrorListener _errorListener; |
| (...skipping 3870 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9988 FormalParameter p1 = AstFactory.simpleFormalParameter3("p1"); | 9985 FormalParameter p1 = AstFactory.simpleFormalParameter3("p1"); |
| 9989 _setType(p1, dynamicType); | 9986 _setType(p1, dynamicType); |
| 9990 FormalParameter p2 = AstFactory.simpleFormalParameter3("p2"); | 9987 FormalParameter p2 = AstFactory.simpleFormalParameter3("p2"); |
| 9991 _setType(p2, dynamicType); | 9988 _setType(p2, dynamicType); |
| 9992 FunctionExpression node = _resolvedFunctionExpression( | 9989 FunctionExpression node = _resolvedFunctionExpression( |
| 9993 AstFactory.formalParameterList([p1, p2]), | 9990 AstFactory.formalParameterList([p1, p2]), |
| 9994 AstFactory.blockFunctionBody2()); | 9991 AstFactory.blockFunctionBody2()); |
| 9995 _analyze5(p1); | 9992 _analyze5(p1); |
| 9996 _analyze5(p2); | 9993 _analyze5(p2); |
| 9997 DartType resultType = _analyze(node); | 9994 DartType resultType = _analyze(node); |
| 9998 _assertFunctionType(dynamicType, | 9995 _assertFunctionType(dynamicType, <DartType>[ |
| 9999 <DartType>[dynamicType, dynamicType], null, null, resultType); | 9996 dynamicType, |
| 9997 dynamicType |
| 9998 ], null, null, resultType); |
| 10000 _listener.assertNoErrors(); | 9999 _listener.assertNoErrors(); |
| 10001 } | 10000 } |
| 10002 | 10001 |
| 10003 void test_visitFunctionExpression_normal_expression() { | 10002 void test_visitFunctionExpression_normal_expression() { |
| 10004 // (p1, p2) -> 0 | 10003 // (p1, p2) -> 0 |
| 10005 DartType dynamicType = _typeProvider.dynamicType; | 10004 DartType dynamicType = _typeProvider.dynamicType; |
| 10006 FormalParameter p = AstFactory.simpleFormalParameter3("p"); | 10005 FormalParameter p = AstFactory.simpleFormalParameter3("p"); |
| 10007 _setType(p, dynamicType); | 10006 _setType(p, dynamicType); |
| 10008 FunctionExpression node = _resolvedFunctionExpression( | 10007 FunctionExpression node = _resolvedFunctionExpression( |
| 10009 AstFactory.formalParameterList([p]), | 10008 AstFactory.formalParameterList([p]), |
| (...skipping 13 matching lines...) Expand all Loading... |
| 10023 FormalParameter p2 = AstFactory.namedFormalParameter( | 10022 FormalParameter p2 = AstFactory.namedFormalParameter( |
| 10024 AstFactory.simpleFormalParameter3("p2"), _resolvedInteger(0)); | 10023 AstFactory.simpleFormalParameter3("p2"), _resolvedInteger(0)); |
| 10025 _setType(p2, dynamicType); | 10024 _setType(p2, dynamicType); |
| 10026 FunctionExpression node = _resolvedFunctionExpression( | 10025 FunctionExpression node = _resolvedFunctionExpression( |
| 10027 AstFactory.formalParameterList([p1, p2]), | 10026 AstFactory.formalParameterList([p1, p2]), |
| 10028 AstFactory.blockFunctionBody2()); | 10027 AstFactory.blockFunctionBody2()); |
| 10029 _analyze5(p2); | 10028 _analyze5(p2); |
| 10030 DartType resultType = _analyze(node); | 10029 DartType resultType = _analyze(node); |
| 10031 Map<String, DartType> expectedNamedTypes = new HashMap<String, DartType>(); | 10030 Map<String, DartType> expectedNamedTypes = new HashMap<String, DartType>(); |
| 10032 expectedNamedTypes["p2"] = dynamicType; | 10031 expectedNamedTypes["p2"] = dynamicType; |
| 10033 _assertFunctionType(dynamicType, | 10032 _assertFunctionType(dynamicType, <DartType>[dynamicType], null, |
| 10034 <DartType>[dynamicType], null, expectedNamedTypes, resultType); | 10033 expectedNamedTypes, resultType); |
| 10035 _listener.assertNoErrors(); | 10034 _listener.assertNoErrors(); |
| 10036 } | 10035 } |
| 10037 | 10036 |
| 10038 void test_visitFunctionExpression_normalAndNamed_expression() { | 10037 void test_visitFunctionExpression_normalAndNamed_expression() { |
| 10039 // (p1, {p2 : 0}) -> 0 | 10038 // (p1, {p2 : 0}) -> 0 |
| 10040 DartType dynamicType = _typeProvider.dynamicType; | 10039 DartType dynamicType = _typeProvider.dynamicType; |
| 10041 FormalParameter p1 = AstFactory.simpleFormalParameter3("p1"); | 10040 FormalParameter p1 = AstFactory.simpleFormalParameter3("p1"); |
| 10042 _setType(p1, dynamicType); | 10041 _setType(p1, dynamicType); |
| 10043 FormalParameter p2 = AstFactory.namedFormalParameter( | 10042 FormalParameter p2 = AstFactory.namedFormalParameter( |
| 10044 AstFactory.simpleFormalParameter3("p2"), _resolvedInteger(0)); | 10043 AstFactory.simpleFormalParameter3("p2"), _resolvedInteger(0)); |
| 10045 _setType(p2, dynamicType); | 10044 _setType(p2, dynamicType); |
| 10046 FunctionExpression node = _resolvedFunctionExpression( | 10045 FunctionExpression node = _resolvedFunctionExpression( |
| 10047 AstFactory.formalParameterList([p1, p2]), | 10046 AstFactory.formalParameterList([p1, p2]), |
| 10048 AstFactory.expressionFunctionBody(_resolvedInteger(0))); | 10047 AstFactory.expressionFunctionBody(_resolvedInteger(0))); |
| 10049 _analyze5(p2); | 10048 _analyze5(p2); |
| 10050 DartType resultType = _analyze(node); | 10049 DartType resultType = _analyze(node); |
| 10051 Map<String, DartType> expectedNamedTypes = new HashMap<String, DartType>(); | 10050 Map<String, DartType> expectedNamedTypes = new HashMap<String, DartType>(); |
| 10052 expectedNamedTypes["p2"] = dynamicType; | 10051 expectedNamedTypes["p2"] = dynamicType; |
| 10053 _assertFunctionType(_typeProvider.intType, | 10052 _assertFunctionType(_typeProvider.intType, <DartType>[dynamicType], null, |
| 10054 <DartType>[dynamicType], null, expectedNamedTypes, resultType); | 10053 expectedNamedTypes, resultType); |
| 10055 _listener.assertNoErrors(); | 10054 _listener.assertNoErrors(); |
| 10056 } | 10055 } |
| 10057 | 10056 |
| 10058 void test_visitFunctionExpression_normalAndPositional_block() { | 10057 void test_visitFunctionExpression_normalAndPositional_block() { |
| 10059 // (p1, [p2 = 0]) {} | 10058 // (p1, [p2 = 0]) {} |
| 10060 DartType dynamicType = _typeProvider.dynamicType; | 10059 DartType dynamicType = _typeProvider.dynamicType; |
| 10061 FormalParameter p1 = AstFactory.simpleFormalParameter3("p1"); | 10060 FormalParameter p1 = AstFactory.simpleFormalParameter3("p1"); |
| 10062 _setType(p1, dynamicType); | 10061 _setType(p1, dynamicType); |
| 10063 FormalParameter p2 = AstFactory.positionalFormalParameter( | 10062 FormalParameter p2 = AstFactory.positionalFormalParameter( |
| 10064 AstFactory.simpleFormalParameter3("p2"), _resolvedInteger(0)); | 10063 AstFactory.simpleFormalParameter3("p2"), _resolvedInteger(0)); |
| 10065 _setType(p2, dynamicType); | 10064 _setType(p2, dynamicType); |
| 10066 FunctionExpression node = _resolvedFunctionExpression( | 10065 FunctionExpression node = _resolvedFunctionExpression( |
| 10067 AstFactory.formalParameterList([p1, p2]), | 10066 AstFactory.formalParameterList([p1, p2]), |
| 10068 AstFactory.blockFunctionBody2()); | 10067 AstFactory.blockFunctionBody2()); |
| 10069 _analyze5(p1); | 10068 _analyze5(p1); |
| 10070 _analyze5(p2); | 10069 _analyze5(p2); |
| 10071 DartType resultType = _analyze(node); | 10070 DartType resultType = _analyze(node); |
| 10072 _assertFunctionType(dynamicType, | 10071 _assertFunctionType(dynamicType, <DartType>[dynamicType], |
| 10073 <DartType>[dynamicType], <DartType>[dynamicType], null, resultType); | 10072 <DartType>[dynamicType], null, resultType); |
| 10074 _listener.assertNoErrors(); | 10073 _listener.assertNoErrors(); |
| 10075 } | 10074 } |
| 10076 | 10075 |
| 10077 void test_visitFunctionExpression_normalAndPositional_expression() { | 10076 void test_visitFunctionExpression_normalAndPositional_expression() { |
| 10078 // (p1, [p2 = 0]) -> 0 | 10077 // (p1, [p2 = 0]) -> 0 |
| 10079 DartType dynamicType = _typeProvider.dynamicType; | 10078 DartType dynamicType = _typeProvider.dynamicType; |
| 10080 FormalParameter p1 = AstFactory.simpleFormalParameter3("p1"); | 10079 FormalParameter p1 = AstFactory.simpleFormalParameter3("p1"); |
| 10081 _setType(p1, dynamicType); | 10080 _setType(p1, dynamicType); |
| 10082 FormalParameter p2 = AstFactory.positionalFormalParameter( | 10081 FormalParameter p2 = AstFactory.positionalFormalParameter( |
| 10083 AstFactory.simpleFormalParameter3("p2"), _resolvedInteger(0)); | 10082 AstFactory.simpleFormalParameter3("p2"), _resolvedInteger(0)); |
| 10084 _setType(p2, dynamicType); | 10083 _setType(p2, dynamicType); |
| 10085 FunctionExpression node = _resolvedFunctionExpression( | 10084 FunctionExpression node = _resolvedFunctionExpression( |
| 10086 AstFactory.formalParameterList([p1, p2]), | 10085 AstFactory.formalParameterList([p1, p2]), |
| 10087 AstFactory.expressionFunctionBody(_resolvedInteger(0))); | 10086 AstFactory.expressionFunctionBody(_resolvedInteger(0))); |
| 10088 _analyze5(p1); | 10087 _analyze5(p1); |
| 10089 _analyze5(p2); | 10088 _analyze5(p2); |
| 10090 DartType resultType = _analyze(node); | 10089 DartType resultType = _analyze(node); |
| 10091 _assertFunctionType(_typeProvider.intType, | 10090 _assertFunctionType(_typeProvider.intType, <DartType>[dynamicType], |
| 10092 <DartType>[dynamicType], <DartType>[dynamicType], null, resultType); | 10091 <DartType>[dynamicType], null, resultType); |
| 10093 _listener.assertNoErrors(); | 10092 _listener.assertNoErrors(); |
| 10094 } | 10093 } |
| 10095 | 10094 |
| 10096 void test_visitFunctionExpression_positional_block() { | 10095 void test_visitFunctionExpression_positional_block() { |
| 10097 // ([p1 = 0, p2 = 0]) {} | 10096 // ([p1 = 0, p2 = 0]) {} |
| 10098 DartType dynamicType = _typeProvider.dynamicType; | 10097 DartType dynamicType = _typeProvider.dynamicType; |
| 10099 FormalParameter p1 = AstFactory.positionalFormalParameter( | 10098 FormalParameter p1 = AstFactory.positionalFormalParameter( |
| 10100 AstFactory.simpleFormalParameter3("p1"), _resolvedInteger(0)); | 10099 AstFactory.simpleFormalParameter3("p1"), _resolvedInteger(0)); |
| 10101 _setType(p1, dynamicType); | 10100 _setType(p1, dynamicType); |
| 10102 FormalParameter p2 = AstFactory.positionalFormalParameter( | 10101 FormalParameter p2 = AstFactory.positionalFormalParameter( |
| 10103 AstFactory.simpleFormalParameter3("p2"), _resolvedInteger(0)); | 10102 AstFactory.simpleFormalParameter3("p2"), _resolvedInteger(0)); |
| 10104 _setType(p2, dynamicType); | 10103 _setType(p2, dynamicType); |
| 10105 FunctionExpression node = _resolvedFunctionExpression( | 10104 FunctionExpression node = _resolvedFunctionExpression( |
| 10106 AstFactory.formalParameterList([p1, p2]), | 10105 AstFactory.formalParameterList([p1, p2]), |
| 10107 AstFactory.blockFunctionBody2()); | 10106 AstFactory.blockFunctionBody2()); |
| 10108 _analyze5(p1); | 10107 _analyze5(p1); |
| 10109 _analyze5(p2); | 10108 _analyze5(p2); |
| 10110 DartType resultType = _analyze(node); | 10109 DartType resultType = _analyze(node); |
| 10111 _assertFunctionType(dynamicType, | 10110 _assertFunctionType(dynamicType, null, <DartType>[ |
| 10112 null, <DartType>[dynamicType, dynamicType], null, resultType); | 10111 dynamicType, |
| 10112 dynamicType |
| 10113 ], null, resultType); |
| 10113 _listener.assertNoErrors(); | 10114 _listener.assertNoErrors(); |
| 10114 } | 10115 } |
| 10115 | 10116 |
| 10116 void test_visitFunctionExpression_positional_expression() { | 10117 void test_visitFunctionExpression_positional_expression() { |
| 10117 // ([p1 = 0, p2 = 0]) -> 0 | 10118 // ([p1 = 0, p2 = 0]) -> 0 |
| 10118 DartType dynamicType = _typeProvider.dynamicType; | 10119 DartType dynamicType = _typeProvider.dynamicType; |
| 10119 FormalParameter p = AstFactory.positionalFormalParameter( | 10120 FormalParameter p = AstFactory.positionalFormalParameter( |
| 10120 AstFactory.simpleFormalParameter3("p"), _resolvedInteger(0)); | 10121 AstFactory.simpleFormalParameter3("p"), _resolvedInteger(0)); |
| 10121 _setType(p, dynamicType); | 10122 _setType(p, dynamicType); |
| 10122 FunctionExpression node = _resolvedFunctionExpression( | 10123 FunctionExpression node = _resolvedFunctionExpression( |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10205 // new C.m() | 10206 // new C.m() |
| 10206 ClassElementImpl classElement = ElementFactory.classElement2("C"); | 10207 ClassElementImpl classElement = ElementFactory.classElement2("C"); |
| 10207 String constructorName = "m"; | 10208 String constructorName = "m"; |
| 10208 ConstructorElementImpl constructor = | 10209 ConstructorElementImpl constructor = |
| 10209 ElementFactory.constructorElement2(classElement, constructorName); | 10210 ElementFactory.constructorElement2(classElement, constructorName); |
| 10210 constructor.returnType = classElement.type; | 10211 constructor.returnType = classElement.type; |
| 10211 FunctionTypeImpl constructorType = new FunctionTypeImpl.con1(constructor); | 10212 FunctionTypeImpl constructorType = new FunctionTypeImpl.con1(constructor); |
| 10212 constructor.type = constructorType; | 10213 constructor.type = constructorType; |
| 10213 classElement.constructors = <ConstructorElement>[constructor]; | 10214 classElement.constructors = <ConstructorElement>[constructor]; |
| 10214 InstanceCreationExpression node = AstFactory.instanceCreationExpression2( | 10215 InstanceCreationExpression node = AstFactory.instanceCreationExpression2( |
| 10215 null, AstFactory.typeName(classElement), [ | 10216 null, AstFactory.typeName(classElement), |
| 10216 AstFactory.identifier3(constructorName) | 10217 [AstFactory.identifier3(constructorName)]); |
| 10217 ]); | |
| 10218 node.staticElement = constructor; | 10218 node.staticElement = constructor; |
| 10219 expect(_analyze(node), same(classElement.type)); | 10219 expect(_analyze(node), same(classElement.type)); |
| 10220 _listener.assertNoErrors(); | 10220 _listener.assertNoErrors(); |
| 10221 } | 10221 } |
| 10222 | 10222 |
| 10223 void test_visitInstanceCreationExpression_typeParameters() { | 10223 void test_visitInstanceCreationExpression_typeParameters() { |
| 10224 // new C<I>() | 10224 // new C<I>() |
| 10225 ClassElementImpl elementC = ElementFactory.classElement2("C", ["E"]); | 10225 ClassElementImpl elementC = ElementFactory.classElement2("C", ["E"]); |
| 10226 ClassElementImpl elementI = ElementFactory.classElement2("I"); | 10226 ClassElementImpl elementI = ElementFactory.classElement2("I"); |
| 10227 ConstructorElementImpl constructor = | 10227 ConstructorElementImpl constructor = |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10297 DartType resultType = _analyze(node); | 10297 DartType resultType = _analyze(node); |
| 10298 _assertType2(_typeProvider.listType | 10298 _assertType2(_typeProvider.listType |
| 10299 .substitute4(<DartType>[_typeProvider.dynamicType]), resultType); | 10299 .substitute4(<DartType>[_typeProvider.dynamicType]), resultType); |
| 10300 _listener.assertNoErrors(); | 10300 _listener.assertNoErrors(); |
| 10301 } | 10301 } |
| 10302 | 10302 |
| 10303 void test_visitMapLiteral_empty() { | 10303 void test_visitMapLiteral_empty() { |
| 10304 // {} | 10304 // {} |
| 10305 Expression node = AstFactory.mapLiteral2(); | 10305 Expression node = AstFactory.mapLiteral2(); |
| 10306 DartType resultType = _analyze(node); | 10306 DartType resultType = _analyze(node); |
| 10307 _assertType2(_typeProvider.mapType.substitute4(<DartType>[ | 10307 _assertType2(_typeProvider.mapType.substitute4( |
| 10308 _typeProvider.dynamicType, | 10308 <DartType>[_typeProvider.dynamicType, _typeProvider.dynamicType]), |
| 10309 _typeProvider.dynamicType | 10309 resultType); |
| 10310 ]), resultType); | |
| 10311 _listener.assertNoErrors(); | 10310 _listener.assertNoErrors(); |
| 10312 } | 10311 } |
| 10313 | 10312 |
| 10314 void test_visitMapLiteral_nonEmpty() { | 10313 void test_visitMapLiteral_nonEmpty() { |
| 10315 // {"k" : 0} | 10314 // {"k" : 0} |
| 10316 Expression node = AstFactory | 10315 Expression node = AstFactory |
| 10317 .mapLiteral2([AstFactory.mapLiteralEntry("k", _resolvedInteger(0))]); | 10316 .mapLiteral2([AstFactory.mapLiteralEntry("k", _resolvedInteger(0))]); |
| 10318 DartType resultType = _analyze(node); | 10317 DartType resultType = _analyze(node); |
| 10319 _assertType2(_typeProvider.mapType.substitute4(<DartType>[ | 10318 _assertType2(_typeProvider.mapType.substitute4( |
| 10320 _typeProvider.dynamicType, | 10319 <DartType>[_typeProvider.dynamicType, _typeProvider.dynamicType]), |
| 10321 _typeProvider.dynamicType | 10320 resultType); |
| 10322 ]), resultType); | |
| 10323 _listener.assertNoErrors(); | 10321 _listener.assertNoErrors(); |
| 10324 } | 10322 } |
| 10325 | 10323 |
| 10326 void test_visitMethodInvocation_then() { | 10324 void test_visitMethodInvocation_then() { |
| 10327 // then() | 10325 // then() |
| 10328 Expression node = AstFactory.methodInvocation(null, "then"); | 10326 Expression node = AstFactory.methodInvocation(null, "then"); |
| 10329 _analyze(node); | 10327 _analyze(node); |
| 10330 _listener.assertNoErrors(); | 10328 _listener.assertNoErrors(); |
| 10331 } | 10329 } |
| 10332 | 10330 |
| (...skipping 3163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 13496 // check propagated type | 13494 // check propagated type |
| 13497 FunctionType propagatedType = node.propagatedType as FunctionType; | 13495 FunctionType propagatedType = node.propagatedType as FunctionType; |
| 13498 expect(propagatedType.returnType, test.typeProvider.stringType); | 13496 expect(propagatedType.returnType, test.typeProvider.stringType); |
| 13499 } on AnalysisException catch (e, stackTrace) { | 13497 } on AnalysisException catch (e, stackTrace) { |
| 13500 thrownException[0] = new CaughtException(e, stackTrace); | 13498 thrownException[0] = new CaughtException(e, stackTrace); |
| 13501 } | 13499 } |
| 13502 } | 13500 } |
| 13503 return null; | 13501 return null; |
| 13504 } | 13502 } |
| 13505 } | 13503 } |
| OLD | NEW |