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

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

Issue 1021773002: Fix static type analysis of function invocation expressions. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 9 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 | Annotate | Revision Log
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/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
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
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
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
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 4834 matching lines...) Expand 10 before | Expand all | Expand 10 after
9556 foo(); 9550 foo();
9557 } 9551 }
9558 """; 9552 """;
9559 _resolveTestUnit(code); 9553 _resolveTestUnit(code);
9560 // "foo" should be resolved to the "Foo" type 9554 // "foo" should be resolved to the "Foo" type
9561 SimpleIdentifier identifier = _findIdentifier("foo();"); 9555 SimpleIdentifier identifier = _findIdentifier("foo();");
9562 DartType type = identifier.staticType; 9556 DartType type = identifier.staticType;
9563 expect(type, new isInstanceOf<FunctionType>()); 9557 expect(type, new isInstanceOf<FunctionType>());
9564 } 9558 }
9565 9559
9560 void test_FunctionExpressionInvocation_block() {
9561 String code = r'''
9562 main() {
9563 var foo = (() { return 1; })();
9564 }
9565 ''';
9566 _resolveTestUnit(code);
9567 SimpleIdentifier identifier = _findIdentifier('foo');
9568 VariableDeclaration declaration =
9569 identifier.getAncestor((node) => node is VariableDeclaration);
9570 expect(declaration.initializer.staticType.isDynamic, isTrue);
9571 expect(declaration.initializer.propagatedType, isNull);
9572 }
9573
9574 void test_FunctionExpressionInvocation_expression() {
9575 String code = r'''
9576 main() {
9577 var foo = (() => 1)();
9578 }
9579 ''';
9580 _resolveTestUnit(code);
9581 SimpleIdentifier identifier = _findIdentifier('foo');
9582 VariableDeclaration declaration =
9583 identifier.getAncestor((node) => node is VariableDeclaration);
9584 expect(declaration.initializer.staticType.name, 'int');
9585 expect(declaration.initializer.propagatedType, isNull);
9586 }
9587
9588 void test_FunctionExpressionInvocation_curried() {
9589 String code = r'''
9590 typedef int F();
9591 F f() => null;
9592 main() {
9593 var foo = f()();
9594 }
9595 ''';
9596 _resolveTestUnit(code);
9597 SimpleIdentifier identifier = _findIdentifier('foo');
9598 VariableDeclaration declaration =
9599 identifier.getAncestor((node) => node is VariableDeclaration);
9600 expect(declaration.initializer.staticType.name, 'int');
9601 expect(declaration.initializer.propagatedType, isNull);
9602 }
9603
9566 void test_MethodInvocation_nameType_parameter_FunctionTypeAlias() { 9604 void test_MethodInvocation_nameType_parameter_FunctionTypeAlias() {
9567 String code = r""" 9605 String code = r"""
9568 typedef Foo(); 9606 typedef Foo();
9569 main(Foo foo) { 9607 main(Foo foo) {
9570 foo(); 9608 foo();
9571 } 9609 }
9572 """; 9610 """;
9573 _resolveTestUnit(code); 9611 _resolveTestUnit(code);
9574 // "foo" should be resolved to the "Foo" type 9612 // "foo" should be resolved to the "Foo" type
9575 SimpleIdentifier identifier = _findIdentifier("foo();"); 9613 SimpleIdentifier identifier = _findIdentifier("foo();");
(...skipping 412 matching lines...) Expand 10 before | Expand all | Expand 10 after
9988 FormalParameter p1 = AstFactory.simpleFormalParameter3("p1"); 10026 FormalParameter p1 = AstFactory.simpleFormalParameter3("p1");
9989 _setType(p1, dynamicType); 10027 _setType(p1, dynamicType);
9990 FormalParameter p2 = AstFactory.simpleFormalParameter3("p2"); 10028 FormalParameter p2 = AstFactory.simpleFormalParameter3("p2");
9991 _setType(p2, dynamicType); 10029 _setType(p2, dynamicType);
9992 FunctionExpression node = _resolvedFunctionExpression( 10030 FunctionExpression node = _resolvedFunctionExpression(
9993 AstFactory.formalParameterList([p1, p2]), 10031 AstFactory.formalParameterList([p1, p2]),
9994 AstFactory.blockFunctionBody2()); 10032 AstFactory.blockFunctionBody2());
9995 _analyze5(p1); 10033 _analyze5(p1);
9996 _analyze5(p2); 10034 _analyze5(p2);
9997 DartType resultType = _analyze(node); 10035 DartType resultType = _analyze(node);
9998 _assertFunctionType(dynamicType, 10036 _assertFunctionType(dynamicType, <DartType>[
9999 <DartType>[dynamicType, dynamicType], null, null, resultType); 10037 dynamicType,
10038 dynamicType
10039 ], null, null, resultType);
10000 _listener.assertNoErrors(); 10040 _listener.assertNoErrors();
10001 } 10041 }
10002 10042
10003 void test_visitFunctionExpression_normal_expression() { 10043 void test_visitFunctionExpression_normal_expression() {
10004 // (p1, p2) -> 0 10044 // (p1, p2) -> 0
10005 DartType dynamicType = _typeProvider.dynamicType; 10045 DartType dynamicType = _typeProvider.dynamicType;
10006 FormalParameter p = AstFactory.simpleFormalParameter3("p"); 10046 FormalParameter p = AstFactory.simpleFormalParameter3("p");
10007 _setType(p, dynamicType); 10047 _setType(p, dynamicType);
10008 FunctionExpression node = _resolvedFunctionExpression( 10048 FunctionExpression node = _resolvedFunctionExpression(
10009 AstFactory.formalParameterList([p]), 10049 AstFactory.formalParameterList([p]),
(...skipping 13 matching lines...) Expand all
10023 FormalParameter p2 = AstFactory.namedFormalParameter( 10063 FormalParameter p2 = AstFactory.namedFormalParameter(
10024 AstFactory.simpleFormalParameter3("p2"), _resolvedInteger(0)); 10064 AstFactory.simpleFormalParameter3("p2"), _resolvedInteger(0));
10025 _setType(p2, dynamicType); 10065 _setType(p2, dynamicType);
10026 FunctionExpression node = _resolvedFunctionExpression( 10066 FunctionExpression node = _resolvedFunctionExpression(
10027 AstFactory.formalParameterList([p1, p2]), 10067 AstFactory.formalParameterList([p1, p2]),
10028 AstFactory.blockFunctionBody2()); 10068 AstFactory.blockFunctionBody2());
10029 _analyze5(p2); 10069 _analyze5(p2);
10030 DartType resultType = _analyze(node); 10070 DartType resultType = _analyze(node);
10031 Map<String, DartType> expectedNamedTypes = new HashMap<String, DartType>(); 10071 Map<String, DartType> expectedNamedTypes = new HashMap<String, DartType>();
10032 expectedNamedTypes["p2"] = dynamicType; 10072 expectedNamedTypes["p2"] = dynamicType;
10033 _assertFunctionType(dynamicType, 10073 _assertFunctionType(dynamicType, <DartType>[dynamicType], null,
10034 <DartType>[dynamicType], null, expectedNamedTypes, resultType); 10074 expectedNamedTypes, resultType);
10035 _listener.assertNoErrors(); 10075 _listener.assertNoErrors();
10036 } 10076 }
10037 10077
10038 void test_visitFunctionExpression_normalAndNamed_expression() { 10078 void test_visitFunctionExpression_normalAndNamed_expression() {
10039 // (p1, {p2 : 0}) -> 0 10079 // (p1, {p2 : 0}) -> 0
10040 DartType dynamicType = _typeProvider.dynamicType; 10080 DartType dynamicType = _typeProvider.dynamicType;
10041 FormalParameter p1 = AstFactory.simpleFormalParameter3("p1"); 10081 FormalParameter p1 = AstFactory.simpleFormalParameter3("p1");
10042 _setType(p1, dynamicType); 10082 _setType(p1, dynamicType);
10043 FormalParameter p2 = AstFactory.namedFormalParameter( 10083 FormalParameter p2 = AstFactory.namedFormalParameter(
10044 AstFactory.simpleFormalParameter3("p2"), _resolvedInteger(0)); 10084 AstFactory.simpleFormalParameter3("p2"), _resolvedInteger(0));
10045 _setType(p2, dynamicType); 10085 _setType(p2, dynamicType);
10046 FunctionExpression node = _resolvedFunctionExpression( 10086 FunctionExpression node = _resolvedFunctionExpression(
10047 AstFactory.formalParameterList([p1, p2]), 10087 AstFactory.formalParameterList([p1, p2]),
10048 AstFactory.expressionFunctionBody(_resolvedInteger(0))); 10088 AstFactory.expressionFunctionBody(_resolvedInteger(0)));
10049 _analyze5(p2); 10089 _analyze5(p2);
10050 DartType resultType = _analyze(node); 10090 DartType resultType = _analyze(node);
10051 Map<String, DartType> expectedNamedTypes = new HashMap<String, DartType>(); 10091 Map<String, DartType> expectedNamedTypes = new HashMap<String, DartType>();
10052 expectedNamedTypes["p2"] = dynamicType; 10092 expectedNamedTypes["p2"] = dynamicType;
10053 _assertFunctionType(_typeProvider.intType, 10093 _assertFunctionType(_typeProvider.intType, <DartType>[dynamicType], null,
10054 <DartType>[dynamicType], null, expectedNamedTypes, resultType); 10094 expectedNamedTypes, resultType);
10055 _listener.assertNoErrors(); 10095 _listener.assertNoErrors();
10056 } 10096 }
10057 10097
10058 void test_visitFunctionExpression_normalAndPositional_block() { 10098 void test_visitFunctionExpression_normalAndPositional_block() {
10059 // (p1, [p2 = 0]) {} 10099 // (p1, [p2 = 0]) {}
10060 DartType dynamicType = _typeProvider.dynamicType; 10100 DartType dynamicType = _typeProvider.dynamicType;
10061 FormalParameter p1 = AstFactory.simpleFormalParameter3("p1"); 10101 FormalParameter p1 = AstFactory.simpleFormalParameter3("p1");
10062 _setType(p1, dynamicType); 10102 _setType(p1, dynamicType);
10063 FormalParameter p2 = AstFactory.positionalFormalParameter( 10103 FormalParameter p2 = AstFactory.positionalFormalParameter(
10064 AstFactory.simpleFormalParameter3("p2"), _resolvedInteger(0)); 10104 AstFactory.simpleFormalParameter3("p2"), _resolvedInteger(0));
10065 _setType(p2, dynamicType); 10105 _setType(p2, dynamicType);
10066 FunctionExpression node = _resolvedFunctionExpression( 10106 FunctionExpression node = _resolvedFunctionExpression(
10067 AstFactory.formalParameterList([p1, p2]), 10107 AstFactory.formalParameterList([p1, p2]),
10068 AstFactory.blockFunctionBody2()); 10108 AstFactory.blockFunctionBody2());
10069 _analyze5(p1); 10109 _analyze5(p1);
10070 _analyze5(p2); 10110 _analyze5(p2);
10071 DartType resultType = _analyze(node); 10111 DartType resultType = _analyze(node);
10072 _assertFunctionType(dynamicType, 10112 _assertFunctionType(dynamicType, <DartType>[dynamicType],
10073 <DartType>[dynamicType], <DartType>[dynamicType], null, resultType); 10113 <DartType>[dynamicType], null, resultType);
10074 _listener.assertNoErrors(); 10114 _listener.assertNoErrors();
10075 } 10115 }
10076 10116
10077 void test_visitFunctionExpression_normalAndPositional_expression() { 10117 void test_visitFunctionExpression_normalAndPositional_expression() {
10078 // (p1, [p2 = 0]) -> 0 10118 // (p1, [p2 = 0]) -> 0
10079 DartType dynamicType = _typeProvider.dynamicType; 10119 DartType dynamicType = _typeProvider.dynamicType;
10080 FormalParameter p1 = AstFactory.simpleFormalParameter3("p1"); 10120 FormalParameter p1 = AstFactory.simpleFormalParameter3("p1");
10081 _setType(p1, dynamicType); 10121 _setType(p1, dynamicType);
10082 FormalParameter p2 = AstFactory.positionalFormalParameter( 10122 FormalParameter p2 = AstFactory.positionalFormalParameter(
10083 AstFactory.simpleFormalParameter3("p2"), _resolvedInteger(0)); 10123 AstFactory.simpleFormalParameter3("p2"), _resolvedInteger(0));
10084 _setType(p2, dynamicType); 10124 _setType(p2, dynamicType);
10085 FunctionExpression node = _resolvedFunctionExpression( 10125 FunctionExpression node = _resolvedFunctionExpression(
10086 AstFactory.formalParameterList([p1, p2]), 10126 AstFactory.formalParameterList([p1, p2]),
10087 AstFactory.expressionFunctionBody(_resolvedInteger(0))); 10127 AstFactory.expressionFunctionBody(_resolvedInteger(0)));
10088 _analyze5(p1); 10128 _analyze5(p1);
10089 _analyze5(p2); 10129 _analyze5(p2);
10090 DartType resultType = _analyze(node); 10130 DartType resultType = _analyze(node);
10091 _assertFunctionType(_typeProvider.intType, 10131 _assertFunctionType(_typeProvider.intType, <DartType>[dynamicType],
10092 <DartType>[dynamicType], <DartType>[dynamicType], null, resultType); 10132 <DartType>[dynamicType], null, resultType);
10093 _listener.assertNoErrors(); 10133 _listener.assertNoErrors();
10094 } 10134 }
10095 10135
10096 void test_visitFunctionExpression_positional_block() { 10136 void test_visitFunctionExpression_positional_block() {
10097 // ([p1 = 0, p2 = 0]) {} 10137 // ([p1 = 0, p2 = 0]) {}
10098 DartType dynamicType = _typeProvider.dynamicType; 10138 DartType dynamicType = _typeProvider.dynamicType;
10099 FormalParameter p1 = AstFactory.positionalFormalParameter( 10139 FormalParameter p1 = AstFactory.positionalFormalParameter(
10100 AstFactory.simpleFormalParameter3("p1"), _resolvedInteger(0)); 10140 AstFactory.simpleFormalParameter3("p1"), _resolvedInteger(0));
10101 _setType(p1, dynamicType); 10141 _setType(p1, dynamicType);
10102 FormalParameter p2 = AstFactory.positionalFormalParameter( 10142 FormalParameter p2 = AstFactory.positionalFormalParameter(
10103 AstFactory.simpleFormalParameter3("p2"), _resolvedInteger(0)); 10143 AstFactory.simpleFormalParameter3("p2"), _resolvedInteger(0));
10104 _setType(p2, dynamicType); 10144 _setType(p2, dynamicType);
10105 FunctionExpression node = _resolvedFunctionExpression( 10145 FunctionExpression node = _resolvedFunctionExpression(
10106 AstFactory.formalParameterList([p1, p2]), 10146 AstFactory.formalParameterList([p1, p2]),
10107 AstFactory.blockFunctionBody2()); 10147 AstFactory.blockFunctionBody2());
10108 _analyze5(p1); 10148 _analyze5(p1);
10109 _analyze5(p2); 10149 _analyze5(p2);
10110 DartType resultType = _analyze(node); 10150 DartType resultType = _analyze(node);
10111 _assertFunctionType(dynamicType, 10151 _assertFunctionType(dynamicType, null, <DartType>[
10112 null, <DartType>[dynamicType, dynamicType], null, resultType); 10152 dynamicType,
10153 dynamicType
10154 ], null, resultType);
10113 _listener.assertNoErrors(); 10155 _listener.assertNoErrors();
10114 } 10156 }
10115 10157
10116 void test_visitFunctionExpression_positional_expression() { 10158 void test_visitFunctionExpression_positional_expression() {
10117 // ([p1 = 0, p2 = 0]) -> 0 10159 // ([p1 = 0, p2 = 0]) -> 0
10118 DartType dynamicType = _typeProvider.dynamicType; 10160 DartType dynamicType = _typeProvider.dynamicType;
10119 FormalParameter p = AstFactory.positionalFormalParameter( 10161 FormalParameter p = AstFactory.positionalFormalParameter(
10120 AstFactory.simpleFormalParameter3("p"), _resolvedInteger(0)); 10162 AstFactory.simpleFormalParameter3("p"), _resolvedInteger(0));
10121 _setType(p, dynamicType); 10163 _setType(p, dynamicType);
10122 FunctionExpression node = _resolvedFunctionExpression( 10164 FunctionExpression node = _resolvedFunctionExpression(
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
10205 // new C.m() 10247 // new C.m()
10206 ClassElementImpl classElement = ElementFactory.classElement2("C"); 10248 ClassElementImpl classElement = ElementFactory.classElement2("C");
10207 String constructorName = "m"; 10249 String constructorName = "m";
10208 ConstructorElementImpl constructor = 10250 ConstructorElementImpl constructor =
10209 ElementFactory.constructorElement2(classElement, constructorName); 10251 ElementFactory.constructorElement2(classElement, constructorName);
10210 constructor.returnType = classElement.type; 10252 constructor.returnType = classElement.type;
10211 FunctionTypeImpl constructorType = new FunctionTypeImpl.con1(constructor); 10253 FunctionTypeImpl constructorType = new FunctionTypeImpl.con1(constructor);
10212 constructor.type = constructorType; 10254 constructor.type = constructorType;
10213 classElement.constructors = <ConstructorElement>[constructor]; 10255 classElement.constructors = <ConstructorElement>[constructor];
10214 InstanceCreationExpression node = AstFactory.instanceCreationExpression2( 10256 InstanceCreationExpression node = AstFactory.instanceCreationExpression2(
10215 null, AstFactory.typeName(classElement), [ 10257 null, AstFactory.typeName(classElement),
10216 AstFactory.identifier3(constructorName) 10258 [AstFactory.identifier3(constructorName)]);
10217 ]);
10218 node.staticElement = constructor; 10259 node.staticElement = constructor;
10219 expect(_analyze(node), same(classElement.type)); 10260 expect(_analyze(node), same(classElement.type));
10220 _listener.assertNoErrors(); 10261 _listener.assertNoErrors();
10221 } 10262 }
10222 10263
10223 void test_visitInstanceCreationExpression_typeParameters() { 10264 void test_visitInstanceCreationExpression_typeParameters() {
10224 // new C<I>() 10265 // new C<I>()
10225 ClassElementImpl elementC = ElementFactory.classElement2("C", ["E"]); 10266 ClassElementImpl elementC = ElementFactory.classElement2("C", ["E"]);
10226 ClassElementImpl elementI = ElementFactory.classElement2("I"); 10267 ClassElementImpl elementI = ElementFactory.classElement2("I");
10227 ConstructorElementImpl constructor = 10268 ConstructorElementImpl constructor =
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
10297 DartType resultType = _analyze(node); 10338 DartType resultType = _analyze(node);
10298 _assertType2(_typeProvider.listType 10339 _assertType2(_typeProvider.listType
10299 .substitute4(<DartType>[_typeProvider.dynamicType]), resultType); 10340 .substitute4(<DartType>[_typeProvider.dynamicType]), resultType);
10300 _listener.assertNoErrors(); 10341 _listener.assertNoErrors();
10301 } 10342 }
10302 10343
10303 void test_visitMapLiteral_empty() { 10344 void test_visitMapLiteral_empty() {
10304 // {} 10345 // {}
10305 Expression node = AstFactory.mapLiteral2(); 10346 Expression node = AstFactory.mapLiteral2();
10306 DartType resultType = _analyze(node); 10347 DartType resultType = _analyze(node);
10307 _assertType2(_typeProvider.mapType.substitute4(<DartType>[ 10348 _assertType2(_typeProvider.mapType.substitute4(
10308 _typeProvider.dynamicType, 10349 <DartType>[_typeProvider.dynamicType, _typeProvider.dynamicType]),
10309 _typeProvider.dynamicType 10350 resultType);
10310 ]), resultType);
10311 _listener.assertNoErrors(); 10351 _listener.assertNoErrors();
10312 } 10352 }
10313 10353
10314 void test_visitMapLiteral_nonEmpty() { 10354 void test_visitMapLiteral_nonEmpty() {
10315 // {"k" : 0} 10355 // {"k" : 0}
10316 Expression node = AstFactory 10356 Expression node = AstFactory
10317 .mapLiteral2([AstFactory.mapLiteralEntry("k", _resolvedInteger(0))]); 10357 .mapLiteral2([AstFactory.mapLiteralEntry("k", _resolvedInteger(0))]);
10318 DartType resultType = _analyze(node); 10358 DartType resultType = _analyze(node);
10319 _assertType2(_typeProvider.mapType.substitute4(<DartType>[ 10359 _assertType2(_typeProvider.mapType.substitute4(
10320 _typeProvider.dynamicType, 10360 <DartType>[_typeProvider.dynamicType, _typeProvider.dynamicType]),
10321 _typeProvider.dynamicType 10361 resultType);
10322 ]), resultType);
10323 _listener.assertNoErrors(); 10362 _listener.assertNoErrors();
10324 } 10363 }
10325 10364
10326 void test_visitMethodInvocation_then() { 10365 void test_visitMethodInvocation_then() {
10327 // then() 10366 // then()
10328 Expression node = AstFactory.methodInvocation(null, "then"); 10367 Expression node = AstFactory.methodInvocation(null, "then");
10329 _analyze(node); 10368 _analyze(node);
10330 _listener.assertNoErrors(); 10369 _listener.assertNoErrors();
10331 } 10370 }
10332 10371
(...skipping 3163 matching lines...) Expand 10 before | Expand all | Expand 10 after
13496 // check propagated type 13535 // check propagated type
13497 FunctionType propagatedType = node.propagatedType as FunctionType; 13536 FunctionType propagatedType = node.propagatedType as FunctionType;
13498 expect(propagatedType.returnType, test.typeProvider.stringType); 13537 expect(propagatedType.returnType, test.typeProvider.stringType);
13499 } on AnalysisException catch (e, stackTrace) { 13538 } on AnalysisException catch (e, stackTrace) {
13500 thrownException[0] = new CaughtException(e, stackTrace); 13539 thrownException[0] = new CaughtException(e, stackTrace);
13501 } 13540 }
13502 } 13541 }
13503 return null; 13542 return null;
13504 } 13543 }
13505 } 13544 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698