| 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 analyzer.test.generated.resolver_test; | 5 library analyzer.test.generated.resolver_test; |
| 6 | 6 |
| 7 import 'dart:collection'; | 7 import 'dart:collection'; |
| 8 | 8 |
| 9 import 'package:analyzer/dart/ast/ast.dart'; | 9 import 'package:analyzer/dart/ast/ast.dart'; |
| 10 import 'package:analyzer/dart/ast/token.dart'; | 10 import 'package:analyzer/dart/ast/token.dart'; |
| (...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 230 futureElement.constructors = <ConstructorElement>[futureConstructor]; | 230 futureElement.constructors = <ConstructorElement>[futureConstructor]; |
| 231 // Future then(onValue(T value), { Function onError }); | 231 // Future then(onValue(T value), { Function onError }); |
| 232 TypeDefiningElement futureThenR = DynamicElementImpl.instance; | 232 TypeDefiningElement futureThenR = DynamicElementImpl.instance; |
| 233 if (context.analysisOptions.strongMode) { | 233 if (context.analysisOptions.strongMode) { |
| 234 futureThenR = ElementFactory.typeParameterWithType('R'); | 234 futureThenR = ElementFactory.typeParameterWithType('R'); |
| 235 } | 235 } |
| 236 FunctionElementImpl thenOnValue = ElementFactory.functionElement3( | 236 FunctionElementImpl thenOnValue = ElementFactory.functionElement3( |
| 237 'onValue', futureThenR, [futureElement.typeParameters[0]], null); | 237 'onValue', futureThenR, [futureElement.typeParameters[0]], null); |
| 238 thenOnValue.synthetic = true; | 238 thenOnValue.synthetic = true; |
| 239 | 239 |
| 240 DartType futureRType = futureElement.type.substitute4([futureThenR.type]); | 240 DartType futureRType = futureElement.type.instantiate([futureThenR.type]); |
| 241 MethodElementImpl thenMethod = ElementFactory | 241 MethodElementImpl thenMethod = ElementFactory |
| 242 .methodElementWithParameters(futureElement, "then", futureRType, [ | 242 .methodElementWithParameters(futureElement, "then", futureRType, [ |
| 243 ElementFactory.requiredParameter2("onValue", thenOnValue.type), | 243 ElementFactory.requiredParameter2("onValue", thenOnValue.type), |
| 244 ElementFactory.namedParameter2("onError", provider.functionType) | 244 ElementFactory.namedParameter2("onError", provider.functionType) |
| 245 ]); | 245 ]); |
| 246 if (!futureThenR.type.isDynamic) { | 246 if (!futureThenR.type.isDynamic) { |
| 247 thenMethod.typeParameters = [futureThenR]; | 247 thenMethod.typeParameters = [futureThenR]; |
| 248 } | 248 } |
| 249 thenOnValue.enclosingElement = thenMethod; | 249 thenOnValue.enclosingElement = thenMethod; |
| 250 thenOnValue.type = new FunctionTypeImpl(thenOnValue); | 250 thenOnValue.type = new FunctionTypeImpl(thenOnValue); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 264 // StreamSubscription | 264 // StreamSubscription |
| 265 ClassElementImpl streamSubscriptionElement = | 265 ClassElementImpl streamSubscriptionElement = |
| 266 ElementFactory.classElement2("StreamSubscription", ["T"]); | 266 ElementFactory.classElement2("StreamSubscription", ["T"]); |
| 267 // Stream | 267 // Stream |
| 268 ClassElementImpl streamElement = | 268 ClassElementImpl streamElement = |
| 269 ElementFactory.classElement2("Stream", ["T"]); | 269 ElementFactory.classElement2("Stream", ["T"]); |
| 270 streamElement.constructors = <ConstructorElement>[ | 270 streamElement.constructors = <ConstructorElement>[ |
| 271 ElementFactory.constructorElement2(streamElement, null) | 271 ElementFactory.constructorElement2(streamElement, null) |
| 272 ]; | 272 ]; |
| 273 DartType returnType = streamSubscriptionElement.type | 273 DartType returnType = streamSubscriptionElement.type |
| 274 .substitute4(streamElement.type.typeArguments); | 274 .instantiate(streamElement.type.typeArguments); |
| 275 FunctionElementImpl listenOnData = ElementFactory.functionElement3( | 275 FunctionElementImpl listenOnData = ElementFactory.functionElement3( |
| 276 'onData', | 276 'onData', |
| 277 VoidTypeImpl.instance.element, | 277 VoidTypeImpl.instance.element, |
| 278 <TypeDefiningElement>[streamElement.typeParameters[0]], | 278 <TypeDefiningElement>[streamElement.typeParameters[0]], |
| 279 null); | 279 null); |
| 280 listenOnData.synthetic = true; | 280 listenOnData.synthetic = true; |
| 281 List<DartType> parameterTypes = <DartType>[listenOnData.type,]; | 281 List<DartType> parameterTypes = <DartType>[listenOnData.type,]; |
| 282 // TODO(brianwilkerson) This is missing the optional parameters. | 282 // TODO(brianwilkerson) This is missing the optional parameters. |
| 283 MethodElementImpl listenMethod = | 283 MethodElementImpl listenMethod = |
| 284 ElementFactory.methodElement('listen', returnType, parameterTypes); | 284 ElementFactory.methodElement('listen', returnType, parameterTypes); |
| (...skipping 10302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10587 super.setUp(); | 10587 super.setUp(); |
| 10588 _listener = new GatheringErrorListener(); | 10588 _listener = new GatheringErrorListener(); |
| 10589 _analyzer = _createAnalyzer(); | 10589 _analyzer = _createAnalyzer(); |
| 10590 } | 10590 } |
| 10591 | 10591 |
| 10592 void test_flatten_derived() { | 10592 void test_flatten_derived() { |
| 10593 // class Derived<T> extends Future<T> { ... } | 10593 // class Derived<T> extends Future<T> { ... } |
| 10594 ClassElementImpl derivedClass = | 10594 ClassElementImpl derivedClass = |
| 10595 ElementFactory.classElement2('Derived', ['T']); | 10595 ElementFactory.classElement2('Derived', ['T']); |
| 10596 derivedClass.supertype = _typeProvider.futureType | 10596 derivedClass.supertype = _typeProvider.futureType |
| 10597 .substitute4([derivedClass.typeParameters[0].type]); | 10597 .instantiate([derivedClass.typeParameters[0].type]); |
| 10598 InterfaceType intType = _typeProvider.intType; | 10598 InterfaceType intType = _typeProvider.intType; |
| 10599 DartType dynamicType = _typeProvider.dynamicType; | 10599 DartType dynamicType = _typeProvider.dynamicType; |
| 10600 InterfaceType derivedIntType = derivedClass.type.substitute4([intType]); | 10600 InterfaceType derivedIntType = derivedClass.type.instantiate([intType]); |
| 10601 // flatten(Derived) = dynamic | 10601 // flatten(Derived) = dynamic |
| 10602 InterfaceType derivedDynamicType = | 10602 InterfaceType derivedDynamicType = |
| 10603 derivedClass.type.substitute4([dynamicType]); | 10603 derivedClass.type.instantiate([dynamicType]); |
| 10604 expect(_flatten(derivedDynamicType), dynamicType); | 10604 expect(_flatten(derivedDynamicType), dynamicType); |
| 10605 // flatten(Derived<int>) = int | 10605 // flatten(Derived<int>) = int |
| 10606 expect(_flatten(derivedIntType), intType); | 10606 expect(_flatten(derivedIntType), intType); |
| 10607 // flatten(Derived<Derived>) = Derived | 10607 // flatten(Derived<Derived>) = Derived |
| 10608 expect(_flatten(derivedClass.type.substitute4([derivedDynamicType])), | 10608 expect(_flatten(derivedClass.type.instantiate([derivedDynamicType])), |
| 10609 derivedDynamicType); | 10609 derivedDynamicType); |
| 10610 // flatten(Derived<Derived<int>>) = Derived<int> | 10610 // flatten(Derived<Derived<int>>) = Derived<int> |
| 10611 expect(_flatten(derivedClass.type.substitute4([derivedIntType])), | 10611 expect(_flatten(derivedClass.type.instantiate([derivedIntType])), |
| 10612 derivedIntType); | 10612 derivedIntType); |
| 10613 } | 10613 } |
| 10614 | 10614 |
| 10615 void test_flatten_inhibit_recursion() { | 10615 void test_flatten_inhibit_recursion() { |
| 10616 // class A extends B | 10616 // class A extends B |
| 10617 // class B extends A | 10617 // class B extends A |
| 10618 ClassElementImpl classA = ElementFactory.classElement2('A', []); | 10618 ClassElementImpl classA = ElementFactory.classElement2('A', []); |
| 10619 ClassElementImpl classB = ElementFactory.classElement2('B', []); | 10619 ClassElementImpl classB = ElementFactory.classElement2('B', []); |
| 10620 classA.supertype = classB.type; | 10620 classA.supertype = classB.type; |
| 10621 classB.supertype = classA.type; | 10621 classB.supertype = classA.type; |
| 10622 // flatten(A) = A and flatten(B) = B, since neither class contains Future | 10622 // flatten(A) = A and flatten(B) = B, since neither class contains Future |
| 10623 // in its class hierarchy. Even though there is a loop in the class | 10623 // in its class hierarchy. Even though there is a loop in the class |
| 10624 // hierarchy, flatten() should terminate. | 10624 // hierarchy, flatten() should terminate. |
| 10625 expect(_flatten(classA.type), classA.type); | 10625 expect(_flatten(classA.type), classA.type); |
| 10626 expect(_flatten(classB.type), classB.type); | 10626 expect(_flatten(classB.type), classB.type); |
| 10627 } | 10627 } |
| 10628 | 10628 |
| 10629 void test_flatten_related_derived_types() { | 10629 void test_flatten_related_derived_types() { |
| 10630 InterfaceType intType = _typeProvider.intType; | 10630 InterfaceType intType = _typeProvider.intType; |
| 10631 InterfaceType numType = _typeProvider.numType; | 10631 InterfaceType numType = _typeProvider.numType; |
| 10632 // class Derived<T> extends Future<T> | 10632 // class Derived<T> extends Future<T> |
| 10633 ClassElementImpl derivedClass = | 10633 ClassElementImpl derivedClass = |
| 10634 ElementFactory.classElement2('Derived', ['T']); | 10634 ElementFactory.classElement2('Derived', ['T']); |
| 10635 derivedClass.supertype = _typeProvider.futureType | 10635 derivedClass.supertype = _typeProvider.futureType |
| 10636 .substitute4([derivedClass.typeParameters[0].type]); | 10636 .instantiate([derivedClass.typeParameters[0].type]); |
| 10637 InterfaceType derivedType = derivedClass.type; | 10637 InterfaceType derivedType = derivedClass.type; |
| 10638 // class A extends Derived<int> implements Derived<num> { ... } | 10638 // class A extends Derived<int> implements Derived<num> { ... } |
| 10639 ClassElementImpl classA = | 10639 ClassElementImpl classA = |
| 10640 ElementFactory.classElement('A', derivedType.substitute4([intType])); | 10640 ElementFactory.classElement('A', derivedType.instantiate([intType])); |
| 10641 classA.interfaces = <InterfaceType>[ | 10641 classA.interfaces = <InterfaceType>[ |
| 10642 derivedType.substitute4([numType]) | 10642 derivedType.instantiate([numType]) |
| 10643 ]; | 10643 ]; |
| 10644 // class B extends Future<num> implements Future<int> { ... } | 10644 // class B extends Future<num> implements Future<int> { ... } |
| 10645 ClassElementImpl classB = | 10645 ClassElementImpl classB = |
| 10646 ElementFactory.classElement('B', derivedType.substitute4([numType])); | 10646 ElementFactory.classElement('B', derivedType.instantiate([numType])); |
| 10647 classB.interfaces = <InterfaceType>[ | 10647 classB.interfaces = <InterfaceType>[ |
| 10648 derivedType.substitute4([intType]) | 10648 derivedType.instantiate([intType]) |
| 10649 ]; | 10649 ]; |
| 10650 // flatten(A) = flatten(B) = int, since int is more specific than num. | 10650 // flatten(A) = flatten(B) = int, since int is more specific than num. |
| 10651 // The code in flatten() that inhibits infinite recursion shouldn't be | 10651 // The code in flatten() that inhibits infinite recursion shouldn't be |
| 10652 // fooled by the fact that Derived appears twice in the type hierarchy. | 10652 // fooled by the fact that Derived appears twice in the type hierarchy. |
| 10653 expect(_flatten(classA.type), intType); | 10653 expect(_flatten(classA.type), intType); |
| 10654 expect(_flatten(classB.type), intType); | 10654 expect(_flatten(classB.type), intType); |
| 10655 } | 10655 } |
| 10656 | 10656 |
| 10657 void test_flatten_related_types() { | 10657 void test_flatten_related_types() { |
| 10658 InterfaceType futureType = _typeProvider.futureType; | 10658 InterfaceType futureType = _typeProvider.futureType; |
| 10659 InterfaceType intType = _typeProvider.intType; | 10659 InterfaceType intType = _typeProvider.intType; |
| 10660 InterfaceType numType = _typeProvider.numType; | 10660 InterfaceType numType = _typeProvider.numType; |
| 10661 // class A extends Future<int> implements Future<num> { ... } | 10661 // class A extends Future<int> implements Future<num> { ... } |
| 10662 ClassElementImpl classA = | 10662 ClassElementImpl classA = |
| 10663 ElementFactory.classElement('A', futureType.substitute4([intType])); | 10663 ElementFactory.classElement('A', futureType.instantiate([intType])); |
| 10664 classA.interfaces = <InterfaceType>[ | 10664 classA.interfaces = <InterfaceType>[ |
| 10665 futureType.substitute4([numType]) | 10665 futureType.instantiate([numType]) |
| 10666 ]; | 10666 ]; |
| 10667 // class B extends Future<num> implements Future<int> { ... } | 10667 // class B extends Future<num> implements Future<int> { ... } |
| 10668 ClassElementImpl classB = | 10668 ClassElementImpl classB = |
| 10669 ElementFactory.classElement('B', futureType.substitute4([numType])); | 10669 ElementFactory.classElement('B', futureType.instantiate([numType])); |
| 10670 classB.interfaces = <InterfaceType>[ | 10670 classB.interfaces = <InterfaceType>[ |
| 10671 futureType.substitute4([intType]) | 10671 futureType.instantiate([intType]) |
| 10672 ]; | 10672 ]; |
| 10673 // flatten(A) = flatten(B) = int, since int is more specific than num. | 10673 // flatten(A) = flatten(B) = int, since int is more specific than num. |
| 10674 expect(_flatten(classA.type), intType); | 10674 expect(_flatten(classA.type), intType); |
| 10675 expect(_flatten(classB.type), intType); | 10675 expect(_flatten(classB.type), intType); |
| 10676 } | 10676 } |
| 10677 | 10677 |
| 10678 void test_flatten_simple() { | 10678 void test_flatten_simple() { |
| 10679 InterfaceType intType = _typeProvider.intType; | 10679 InterfaceType intType = _typeProvider.intType; |
| 10680 DartType dynamicType = _typeProvider.dynamicType; | 10680 DartType dynamicType = _typeProvider.dynamicType; |
| 10681 InterfaceType futureDynamicType = _typeProvider.futureDynamicType; | 10681 InterfaceType futureDynamicType = _typeProvider.futureDynamicType; |
| 10682 InterfaceType futureIntType = | 10682 InterfaceType futureIntType = |
| 10683 _typeProvider.futureType.substitute4([intType]); | 10683 _typeProvider.futureType.instantiate([intType]); |
| 10684 InterfaceType futureFutureDynamicType = | 10684 InterfaceType futureFutureDynamicType = |
| 10685 _typeProvider.futureType.substitute4([futureDynamicType]); | 10685 _typeProvider.futureType.instantiate([futureDynamicType]); |
| 10686 InterfaceType futureFutureIntType = | 10686 InterfaceType futureFutureIntType = |
| 10687 _typeProvider.futureType.substitute4([futureIntType]); | 10687 _typeProvider.futureType.instantiate([futureIntType]); |
| 10688 // flatten(int) = int | 10688 // flatten(int) = int |
| 10689 expect(_flatten(intType), intType); | 10689 expect(_flatten(intType), intType); |
| 10690 // flatten(dynamic) = dynamic | 10690 // flatten(dynamic) = dynamic |
| 10691 expect(_flatten(dynamicType), dynamicType); | 10691 expect(_flatten(dynamicType), dynamicType); |
| 10692 // flatten(Future) = dynamic | 10692 // flatten(Future) = dynamic |
| 10693 expect(_flatten(futureDynamicType), dynamicType); | 10693 expect(_flatten(futureDynamicType), dynamicType); |
| 10694 // flatten(Future<int>) = int | 10694 // flatten(Future<int>) = int |
| 10695 expect(_flatten(futureIntType), intType); | 10695 expect(_flatten(futureIntType), intType); |
| 10696 // flatten(Future<Future>) = dynamic | 10696 // flatten(Future<Future>) = dynamic |
| 10697 expect(_flatten(futureFutureDynamicType), dynamicType); | 10697 expect(_flatten(futureFutureDynamicType), dynamicType); |
| 10698 // flatten(Future<Future<int>>) = int | 10698 // flatten(Future<Future<int>>) = int |
| 10699 expect(_flatten(futureFutureIntType), intType); | 10699 expect(_flatten(futureFutureIntType), intType); |
| 10700 } | 10700 } |
| 10701 | 10701 |
| 10702 void test_flatten_unrelated_types() { | 10702 void test_flatten_unrelated_types() { |
| 10703 InterfaceType futureType = _typeProvider.futureType; | 10703 InterfaceType futureType = _typeProvider.futureType; |
| 10704 InterfaceType intType = _typeProvider.intType; | 10704 InterfaceType intType = _typeProvider.intType; |
| 10705 InterfaceType stringType = _typeProvider.stringType; | 10705 InterfaceType stringType = _typeProvider.stringType; |
| 10706 // class A extends Future<int> implements Future<String> { ... } | 10706 // class A extends Future<int> implements Future<String> { ... } |
| 10707 ClassElementImpl classA = | 10707 ClassElementImpl classA = |
| 10708 ElementFactory.classElement('A', futureType.substitute4([intType])); | 10708 ElementFactory.classElement('A', futureType.instantiate([intType])); |
| 10709 classA.interfaces = <InterfaceType>[ | 10709 classA.interfaces = <InterfaceType>[ |
| 10710 futureType.substitute4([stringType]) | 10710 futureType.instantiate([stringType]) |
| 10711 ]; | 10711 ]; |
| 10712 // class B extends Future<String> implements Future<int> { ... } | 10712 // class B extends Future<String> implements Future<int> { ... } |
| 10713 ClassElementImpl classB = | 10713 ClassElementImpl classB = |
| 10714 ElementFactory.classElement('B', futureType.substitute4([stringType])); | 10714 ElementFactory.classElement('B', futureType.instantiate([stringType])); |
| 10715 classB.interfaces = <InterfaceType>[ | 10715 classB.interfaces = <InterfaceType>[ |
| 10716 futureType.substitute4([intType]) | 10716 futureType.instantiate([intType]) |
| 10717 ]; | 10717 ]; |
| 10718 // flatten(A) = A and flatten(B) = B, since neither string nor int is more | 10718 // flatten(A) = A and flatten(B) = B, since neither string nor int is more |
| 10719 // specific than the other. | 10719 // specific than the other. |
| 10720 expect(_flatten(classA.type), classA.type); | 10720 expect(_flatten(classA.type), classA.type); |
| 10721 expect(_flatten(classB.type), classB.type); | 10721 expect(_flatten(classB.type), classB.type); |
| 10722 } | 10722 } |
| 10723 | 10723 |
| 10724 void test_visitAdjacentStrings() { | 10724 void test_visitAdjacentStrings() { |
| 10725 // "a" "b" | 10725 // "a" "b" |
| 10726 Expression node = AstFactory | 10726 Expression node = AstFactory |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10779 Expression node = AstFactory.assignmentExpression( | 10779 Expression node = AstFactory.assignmentExpression( |
| 10780 _resolvedVariable(intType, "i"), TokenType.EQ, _resolvedInteger(0)); | 10780 _resolvedVariable(intType, "i"), TokenType.EQ, _resolvedInteger(0)); |
| 10781 expect(_analyze(node), same(intType)); | 10781 expect(_analyze(node), same(intType)); |
| 10782 _listener.assertNoErrors(); | 10782 _listener.assertNoErrors(); |
| 10783 } | 10783 } |
| 10784 | 10784 |
| 10785 void test_visitAwaitExpression_flattened() { | 10785 void test_visitAwaitExpression_flattened() { |
| 10786 // await e, where e has type Future<Future<int>> | 10786 // await e, where e has type Future<Future<int>> |
| 10787 InterfaceType intType = _typeProvider.intType; | 10787 InterfaceType intType = _typeProvider.intType; |
| 10788 InterfaceType futureIntType = | 10788 InterfaceType futureIntType = |
| 10789 _typeProvider.futureType.substitute4(<DartType>[intType]); | 10789 _typeProvider.futureType.instantiate(<DartType>[intType]); |
| 10790 InterfaceType futureFutureIntType = | 10790 InterfaceType futureFutureIntType = |
| 10791 _typeProvider.futureType.substitute4(<DartType>[futureIntType]); | 10791 _typeProvider.futureType.instantiate(<DartType>[futureIntType]); |
| 10792 Expression node = | 10792 Expression node = |
| 10793 AstFactory.awaitExpression(_resolvedVariable(futureFutureIntType, 'e')); | 10793 AstFactory.awaitExpression(_resolvedVariable(futureFutureIntType, 'e')); |
| 10794 expect(_analyze(node), same(intType)); | 10794 expect(_analyze(node), same(intType)); |
| 10795 _listener.assertNoErrors(); | 10795 _listener.assertNoErrors(); |
| 10796 } | 10796 } |
| 10797 | 10797 |
| 10798 void test_visitAwaitExpression_simple() { | 10798 void test_visitAwaitExpression_simple() { |
| 10799 // await e, where e has type Future<int> | 10799 // await e, where e has type Future<int> |
| 10800 InterfaceType intType = _typeProvider.intType; | 10800 InterfaceType intType = _typeProvider.intType; |
| 10801 InterfaceType futureIntType = | 10801 InterfaceType futureIntType = |
| 10802 _typeProvider.futureType.substitute4(<DartType>[intType]); | 10802 _typeProvider.futureType.instantiate(<DartType>[intType]); |
| 10803 Expression node = | 10803 Expression node = |
| 10804 AstFactory.awaitExpression(_resolvedVariable(futureIntType, 'e')); | 10804 AstFactory.awaitExpression(_resolvedVariable(futureIntType, 'e')); |
| 10805 expect(_analyze(node), same(intType)); | 10805 expect(_analyze(node), same(intType)); |
| 10806 _listener.assertNoErrors(); | 10806 _listener.assertNoErrors(); |
| 10807 } | 10807 } |
| 10808 | 10808 |
| 10809 void test_visitBinaryExpression_equals() { | 10809 void test_visitBinaryExpression_equals() { |
| 10810 // 2 == 3 | 10810 // 2 == 3 |
| 10811 Expression node = AstFactory.binaryExpression( | 10811 Expression node = AstFactory.binaryExpression( |
| 10812 _resolvedInteger(2), TokenType.EQ_EQ, _resolvedInteger(3)); | 10812 _resolvedInteger(2), TokenType.EQ_EQ, _resolvedInteger(3)); |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10988 DartType resultType = _analyze(node); | 10988 DartType resultType = _analyze(node); |
| 10989 _assertFunctionType( | 10989 _assertFunctionType( |
| 10990 _typeProvider.futureDynamicType, null, null, null, resultType); | 10990 _typeProvider.futureDynamicType, null, null, null, resultType); |
| 10991 _listener.assertNoErrors(); | 10991 _listener.assertNoErrors(); |
| 10992 } | 10992 } |
| 10993 | 10993 |
| 10994 void test_visitFunctionExpression_async_expression() { | 10994 void test_visitFunctionExpression_async_expression() { |
| 10995 // () async => e, where e has type int | 10995 // () async => e, where e has type int |
| 10996 InterfaceType intType = _typeProvider.intType; | 10996 InterfaceType intType = _typeProvider.intType; |
| 10997 InterfaceType futureIntType = | 10997 InterfaceType futureIntType = |
| 10998 _typeProvider.futureType.substitute4(<DartType>[intType]); | 10998 _typeProvider.futureType.instantiate(<DartType>[intType]); |
| 10999 Expression expression = _resolvedVariable(intType, 'e'); | 10999 Expression expression = _resolvedVariable(intType, 'e'); |
| 11000 ExpressionFunctionBody body = AstFactory.expressionFunctionBody(expression); | 11000 ExpressionFunctionBody body = AstFactory.expressionFunctionBody(expression); |
| 11001 body.keyword = TokenFactory.tokenFromString('async'); | 11001 body.keyword = TokenFactory.tokenFromString('async'); |
| 11002 FunctionExpression node = | 11002 FunctionExpression node = |
| 11003 _resolvedFunctionExpression(AstFactory.formalParameterList([]), body); | 11003 _resolvedFunctionExpression(AstFactory.formalParameterList([]), body); |
| 11004 DartType resultType = _analyze(node); | 11004 DartType resultType = _analyze(node); |
| 11005 _assertFunctionType(futureIntType, null, null, null, resultType); | 11005 _assertFunctionType(futureIntType, null, null, null, resultType); |
| 11006 _listener.assertNoErrors(); | 11006 _listener.assertNoErrors(); |
| 11007 } | 11007 } |
| 11008 | 11008 |
| 11009 void test_visitFunctionExpression_async_expression_flatten() { | 11009 void test_visitFunctionExpression_async_expression_flatten() { |
| 11010 // () async => e, where e has type Future<int> | 11010 // () async => e, where e has type Future<int> |
| 11011 InterfaceType intType = _typeProvider.intType; | 11011 InterfaceType intType = _typeProvider.intType; |
| 11012 InterfaceType futureIntType = | 11012 InterfaceType futureIntType = |
| 11013 _typeProvider.futureType.substitute4(<DartType>[intType]); | 11013 _typeProvider.futureType.instantiate(<DartType>[intType]); |
| 11014 Expression expression = _resolvedVariable(futureIntType, 'e'); | 11014 Expression expression = _resolvedVariable(futureIntType, 'e'); |
| 11015 ExpressionFunctionBody body = AstFactory.expressionFunctionBody(expression); | 11015 ExpressionFunctionBody body = AstFactory.expressionFunctionBody(expression); |
| 11016 body.keyword = TokenFactory.tokenFromString('async'); | 11016 body.keyword = TokenFactory.tokenFromString('async'); |
| 11017 FunctionExpression node = | 11017 FunctionExpression node = |
| 11018 _resolvedFunctionExpression(AstFactory.formalParameterList([]), body); | 11018 _resolvedFunctionExpression(AstFactory.formalParameterList([]), body); |
| 11019 DartType resultType = _analyze(node); | 11019 DartType resultType = _analyze(node); |
| 11020 _assertFunctionType(futureIntType, null, null, null, resultType); | 11020 _assertFunctionType(futureIntType, null, null, null, resultType); |
| 11021 _listener.assertNoErrors(); | 11021 _listener.assertNoErrors(); |
| 11022 } | 11022 } |
| 11023 | 11023 |
| 11024 void test_visitFunctionExpression_async_expression_flatten_twice() { | 11024 void test_visitFunctionExpression_async_expression_flatten_twice() { |
| 11025 // () async => e, where e has type Future<Future<int>> | 11025 // () async => e, where e has type Future<Future<int>> |
| 11026 InterfaceType intType = _typeProvider.intType; | 11026 InterfaceType intType = _typeProvider.intType; |
| 11027 InterfaceType futureIntType = | 11027 InterfaceType futureIntType = |
| 11028 _typeProvider.futureType.substitute4(<DartType>[intType]); | 11028 _typeProvider.futureType.instantiate(<DartType>[intType]); |
| 11029 InterfaceType futureFutureIntType = | 11029 InterfaceType futureFutureIntType = |
| 11030 _typeProvider.futureType.substitute4(<DartType>[futureIntType]); | 11030 _typeProvider.futureType.instantiate(<DartType>[futureIntType]); |
| 11031 Expression expression = _resolvedVariable(futureFutureIntType, 'e'); | 11031 Expression expression = _resolvedVariable(futureFutureIntType, 'e'); |
| 11032 ExpressionFunctionBody body = AstFactory.expressionFunctionBody(expression); | 11032 ExpressionFunctionBody body = AstFactory.expressionFunctionBody(expression); |
| 11033 body.keyword = TokenFactory.tokenFromString('async'); | 11033 body.keyword = TokenFactory.tokenFromString('async'); |
| 11034 FunctionExpression node = | 11034 FunctionExpression node = |
| 11035 _resolvedFunctionExpression(AstFactory.formalParameterList([]), body); | 11035 _resolvedFunctionExpression(AstFactory.formalParameterList([]), body); |
| 11036 DartType resultType = _analyze(node); | 11036 DartType resultType = _analyze(node); |
| 11037 _assertFunctionType(futureIntType, null, null, null, resultType); | 11037 _assertFunctionType(futureIntType, null, null, null, resultType); |
| 11038 _listener.assertNoErrors(); | 11038 _listener.assertNoErrors(); |
| 11039 } | 11039 } |
| 11040 | 11040 |
| (...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 11281 | 11281 |
| 11282 void test_visitIndexExpression_typeParameters() { | 11282 void test_visitIndexExpression_typeParameters() { |
| 11283 // List<int> list = ... | 11283 // List<int> list = ... |
| 11284 // list[0] | 11284 // list[0] |
| 11285 InterfaceType intType = _typeProvider.intType; | 11285 InterfaceType intType = _typeProvider.intType; |
| 11286 InterfaceType listType = _typeProvider.listType; | 11286 InterfaceType listType = _typeProvider.listType; |
| 11287 // (int) -> E | 11287 // (int) -> E |
| 11288 MethodElement methodElement = getMethod(listType, "[]"); | 11288 MethodElement methodElement = getMethod(listType, "[]"); |
| 11289 // "list" has type List<int> | 11289 // "list" has type List<int> |
| 11290 SimpleIdentifier identifier = AstFactory.identifier3("list"); | 11290 SimpleIdentifier identifier = AstFactory.identifier3("list"); |
| 11291 InterfaceType listOfIntType = listType.substitute4(<DartType>[intType]); | 11291 InterfaceType listOfIntType = listType.instantiate(<DartType>[intType]); |
| 11292 identifier.staticType = listOfIntType; | 11292 identifier.staticType = listOfIntType; |
| 11293 // list[0] has MethodElement element (int) -> E | 11293 // list[0] has MethodElement element (int) -> E |
| 11294 IndexExpression indexExpression = | 11294 IndexExpression indexExpression = |
| 11295 AstFactory.indexExpression(identifier, AstFactory.integer(0)); | 11295 AstFactory.indexExpression(identifier, AstFactory.integer(0)); |
| 11296 MethodElement indexMethod = MethodMember.from(methodElement, listOfIntType); | 11296 MethodElement indexMethod = MethodMember.from(methodElement, listOfIntType); |
| 11297 indexExpression.staticElement = indexMethod; | 11297 indexExpression.staticElement = indexMethod; |
| 11298 // analyze and assert result of the index expression | 11298 // analyze and assert result of the index expression |
| 11299 expect(_analyze(indexExpression), same(intType)); | 11299 expect(_analyze(indexExpression), same(intType)); |
| 11300 _listener.assertNoErrors(); | 11300 _listener.assertNoErrors(); |
| 11301 } | 11301 } |
| 11302 | 11302 |
| 11303 void test_visitIndexExpression_typeParameters_inSetterContext() { | 11303 void test_visitIndexExpression_typeParameters_inSetterContext() { |
| 11304 // List<int> list = ... | 11304 // List<int> list = ... |
| 11305 // list[0] = 0; | 11305 // list[0] = 0; |
| 11306 InterfaceType intType = _typeProvider.intType; | 11306 InterfaceType intType = _typeProvider.intType; |
| 11307 InterfaceType listType = _typeProvider.listType; | 11307 InterfaceType listType = _typeProvider.listType; |
| 11308 // (int, E) -> void | 11308 // (int, E) -> void |
| 11309 MethodElement methodElement = getMethod(listType, "[]="); | 11309 MethodElement methodElement = getMethod(listType, "[]="); |
| 11310 // "list" has type List<int> | 11310 // "list" has type List<int> |
| 11311 SimpleIdentifier identifier = AstFactory.identifier3("list"); | 11311 SimpleIdentifier identifier = AstFactory.identifier3("list"); |
| 11312 InterfaceType listOfIntType = listType.substitute4(<DartType>[intType]); | 11312 InterfaceType listOfIntType = listType.instantiate(<DartType>[intType]); |
| 11313 identifier.staticType = listOfIntType; | 11313 identifier.staticType = listOfIntType; |
| 11314 // list[0] has MethodElement element (int) -> E | 11314 // list[0] has MethodElement element (int) -> E |
| 11315 IndexExpression indexExpression = | 11315 IndexExpression indexExpression = |
| 11316 AstFactory.indexExpression(identifier, AstFactory.integer(0)); | 11316 AstFactory.indexExpression(identifier, AstFactory.integer(0)); |
| 11317 MethodElement indexMethod = MethodMember.from(methodElement, listOfIntType); | 11317 MethodElement indexMethod = MethodMember.from(methodElement, listOfIntType); |
| 11318 indexExpression.staticElement = indexMethod; | 11318 indexExpression.staticElement = indexMethod; |
| 11319 // list[0] should be in a setter context | 11319 // list[0] should be in a setter context |
| 11320 AstFactory.assignmentExpression( | 11320 AstFactory.assignmentExpression( |
| 11321 indexExpression, TokenType.EQ, AstFactory.integer(0)); | 11321 indexExpression, TokenType.EQ, AstFactory.integer(0)); |
| 11322 // analyze and assert result of the index expression | 11322 // analyze and assert result of the index expression |
| (...skipping 25 matching lines...) Expand all Loading... |
| 11348 ClassElementImpl elementC = ElementFactory.classElement2("C", ["E"]); | 11348 ClassElementImpl elementC = ElementFactory.classElement2("C", ["E"]); |
| 11349 ClassElementImpl elementI = ElementFactory.classElement2("I"); | 11349 ClassElementImpl elementI = ElementFactory.classElement2("I"); |
| 11350 ConstructorElementImpl constructor = | 11350 ConstructorElementImpl constructor = |
| 11351 ElementFactory.constructorElement2(elementC, null); | 11351 ElementFactory.constructorElement2(elementC, null); |
| 11352 elementC.constructors = <ConstructorElement>[constructor]; | 11352 elementC.constructors = <ConstructorElement>[constructor]; |
| 11353 constructor.returnType = elementC.type; | 11353 constructor.returnType = elementC.type; |
| 11354 FunctionTypeImpl constructorType = new FunctionTypeImpl(constructor); | 11354 FunctionTypeImpl constructorType = new FunctionTypeImpl(constructor); |
| 11355 constructor.type = constructorType; | 11355 constructor.type = constructorType; |
| 11356 TypeName typeName = | 11356 TypeName typeName = |
| 11357 AstFactory.typeName(elementC, [AstFactory.typeName(elementI)]); | 11357 AstFactory.typeName(elementC, [AstFactory.typeName(elementI)]); |
| 11358 typeName.type = elementC.type.substitute4(<DartType>[elementI.type]); | 11358 typeName.type = elementC.type.instantiate(<DartType>[elementI.type]); |
| 11359 InstanceCreationExpression node = | 11359 InstanceCreationExpression node = |
| 11360 AstFactory.instanceCreationExpression2(null, typeName); | 11360 AstFactory.instanceCreationExpression2(null, typeName); |
| 11361 node.staticElement = constructor; | 11361 node.staticElement = constructor; |
| 11362 InterfaceType interfaceType = _analyze(node) as InterfaceType; | 11362 InterfaceType interfaceType = _analyze(node) as InterfaceType; |
| 11363 List<DartType> typeArgs = interfaceType.typeArguments; | 11363 List<DartType> typeArgs = interfaceType.typeArguments; |
| 11364 expect(typeArgs.length, 1); | 11364 expect(typeArgs.length, 1); |
| 11365 expect(typeArgs[0], elementI.type); | 11365 expect(typeArgs[0], elementI.type); |
| 11366 _listener.assertNoErrors(); | 11366 _listener.assertNoErrors(); |
| 11367 } | 11367 } |
| 11368 | 11368 |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 11404 expect(_analyze(node), same(_typeProvider.boolType)); | 11404 expect(_analyze(node), same(_typeProvider.boolType)); |
| 11405 _listener.assertNoErrors(); | 11405 _listener.assertNoErrors(); |
| 11406 } | 11406 } |
| 11407 | 11407 |
| 11408 void test_visitListLiteral_empty() { | 11408 void test_visitListLiteral_empty() { |
| 11409 // [] | 11409 // [] |
| 11410 Expression node = AstFactory.listLiteral(); | 11410 Expression node = AstFactory.listLiteral(); |
| 11411 DartType resultType = _analyze(node); | 11411 DartType resultType = _analyze(node); |
| 11412 _assertType2( | 11412 _assertType2( |
| 11413 _typeProvider.listType | 11413 _typeProvider.listType |
| 11414 .substitute4(<DartType>[_typeProvider.dynamicType]), | 11414 .instantiate(<DartType>[_typeProvider.dynamicType]), |
| 11415 resultType); | 11415 resultType); |
| 11416 _listener.assertNoErrors(); | 11416 _listener.assertNoErrors(); |
| 11417 } | 11417 } |
| 11418 | 11418 |
| 11419 void test_visitListLiteral_nonEmpty() { | 11419 void test_visitListLiteral_nonEmpty() { |
| 11420 // [0] | 11420 // [0] |
| 11421 Expression node = AstFactory.listLiteral([_resolvedInteger(0)]); | 11421 Expression node = AstFactory.listLiteral([_resolvedInteger(0)]); |
| 11422 DartType resultType = _analyze(node); | 11422 DartType resultType = _analyze(node); |
| 11423 _assertType2( | 11423 _assertType2( |
| 11424 _typeProvider.listType | 11424 _typeProvider.listType |
| 11425 .substitute4(<DartType>[_typeProvider.dynamicType]), | 11425 .instantiate(<DartType>[_typeProvider.dynamicType]), |
| 11426 resultType); | 11426 resultType); |
| 11427 _listener.assertNoErrors(); | 11427 _listener.assertNoErrors(); |
| 11428 } | 11428 } |
| 11429 | 11429 |
| 11430 void test_visitMapLiteral_empty() { | 11430 void test_visitMapLiteral_empty() { |
| 11431 // {} | 11431 // {} |
| 11432 Expression node = AstFactory.mapLiteral2(); | 11432 Expression node = AstFactory.mapLiteral2(); |
| 11433 DartType resultType = _analyze(node); | 11433 DartType resultType = _analyze(node); |
| 11434 _assertType2( | 11434 _assertType2( |
| 11435 _typeProvider.mapType.substitute4( | 11435 _typeProvider.mapType.instantiate( |
| 11436 <DartType>[_typeProvider.dynamicType, _typeProvider.dynamicType]), | 11436 <DartType>[_typeProvider.dynamicType, _typeProvider.dynamicType]), |
| 11437 resultType); | 11437 resultType); |
| 11438 _listener.assertNoErrors(); | 11438 _listener.assertNoErrors(); |
| 11439 } | 11439 } |
| 11440 | 11440 |
| 11441 void test_visitMapLiteral_nonEmpty() { | 11441 void test_visitMapLiteral_nonEmpty() { |
| 11442 // {"k" : 0} | 11442 // {"k" : 0} |
| 11443 Expression node = AstFactory | 11443 Expression node = AstFactory |
| 11444 .mapLiteral2([AstFactory.mapLiteralEntry("k", _resolvedInteger(0))]); | 11444 .mapLiteral2([AstFactory.mapLiteralEntry("k", _resolvedInteger(0))]); |
| 11445 DartType resultType = _analyze(node); | 11445 DartType resultType = _analyze(node); |
| 11446 _assertType2( | 11446 _assertType2( |
| 11447 _typeProvider.mapType.substitute4( | 11447 _typeProvider.mapType.instantiate( |
| 11448 <DartType>[_typeProvider.dynamicType, _typeProvider.dynamicType]), | 11448 <DartType>[_typeProvider.dynamicType, _typeProvider.dynamicType]), |
| 11449 resultType); | 11449 resultType); |
| 11450 _listener.assertNoErrors(); | 11450 _listener.assertNoErrors(); |
| 11451 } | 11451 } |
| 11452 | 11452 |
| 11453 void test_visitMethodInvocation_then() { | 11453 void test_visitMethodInvocation_then() { |
| 11454 // then() | 11454 // then() |
| 11455 Expression node = AstFactory.methodInvocation(null, "then"); | 11455 Expression node = AstFactory.methodInvocation(null, "then"); |
| 11456 _analyze(node); | 11456 _analyze(node); |
| 11457 _listener.assertNoErrors(); | 11457 _listener.assertNoErrors(); |
| (...skipping 2301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 13759 var x = cOfString.f/*<int>*/('hi'); | 13759 var x = cOfString.f/*<int>*/('hi'); |
| 13760 } | 13760 } |
| 13761 '''); | 13761 '''); |
| 13762 MethodInvocation f = _findIdentifier('f/*<int>*/').parent; | 13762 MethodInvocation f = _findIdentifier('f/*<int>*/').parent; |
| 13763 FunctionType ft = f.staticInvokeType; | 13763 FunctionType ft = f.staticInvokeType; |
| 13764 expect(ft.toString(), '(String) → List<int>'); | 13764 expect(ft.toString(), '(String) → List<int>'); |
| 13765 expect('${ft.typeArguments}/${ft.typeParameters}', '[String, int]/[E, T]'); | 13765 expect('${ft.typeArguments}/${ft.typeParameters}', '[String, int]/[E, T]'); |
| 13766 | 13766 |
| 13767 SimpleIdentifier x = _findIdentifier('x'); | 13767 SimpleIdentifier x = _findIdentifier('x'); |
| 13768 expect(x.staticType, | 13768 expect(x.staticType, |
| 13769 typeProvider.listType.substitute4([typeProvider.intType])); | 13769 typeProvider.listType.instantiate([typeProvider.intType])); |
| 13770 } | 13770 } |
| 13771 | 13771 |
| 13772 void test_genericMethod_functionExpressionInvocation_explicit() { | 13772 void test_genericMethod_functionExpressionInvocation_explicit() { |
| 13773 _resolveTestUnit(r''' | 13773 _resolveTestUnit(r''' |
| 13774 class C<E> { | 13774 class C<E> { |
| 13775 /*=T*/ f/*<T>*/(/*=T*/ e) => null; | 13775 /*=T*/ f/*<T>*/(/*=T*/ e) => null; |
| 13776 static /*=T*/ g/*<T>*/(/*=T*/ e) => null; | 13776 static /*=T*/ g/*<T>*/(/*=T*/ e) => null; |
| 13777 static final h = g; | 13777 static final h = g; |
| 13778 } | 13778 } |
| 13779 | 13779 |
| (...skipping 1469 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 15249 await for (var e in stream) { | 15249 await for (var e in stream) { |
| 15250 e; | 15250 e; |
| 15251 } | 15251 } |
| 15252 }'''; | 15252 }'''; |
| 15253 Source source = addSource(code); | 15253 Source source = addSource(code); |
| 15254 LibraryElement library = resolve2(source); | 15254 LibraryElement library = resolve2(source); |
| 15255 assertNoErrors(source); | 15255 assertNoErrors(source); |
| 15256 verify([source]); | 15256 verify([source]); |
| 15257 CompilationUnit unit = resolveCompilationUnit(source, library); | 15257 CompilationUnit unit = resolveCompilationUnit(source, library); |
| 15258 InterfaceType listOfStringType = | 15258 InterfaceType listOfStringType = |
| 15259 typeProvider.listType.substitute4([typeProvider.stringType]); | 15259 typeProvider.listType.instantiate([typeProvider.stringType]); |
| 15260 // in the declaration | 15260 // in the declaration |
| 15261 { | 15261 { |
| 15262 SimpleIdentifier identifier = EngineTestCase.findNode( | 15262 SimpleIdentifier identifier = EngineTestCase.findNode( |
| 15263 unit, code, "e in", (node) => node is SimpleIdentifier); | 15263 unit, code, "e in", (node) => node is SimpleIdentifier); |
| 15264 expect(identifier.propagatedType, equals(listOfStringType)); | 15264 expect(identifier.propagatedType, equals(listOfStringType)); |
| 15265 } | 15265 } |
| 15266 // in the loop body | 15266 // in the loop body |
| 15267 { | 15267 { |
| 15268 SimpleIdentifier identifier = EngineTestCase.findNode( | 15268 SimpleIdentifier identifier = EngineTestCase.findNode( |
| 15269 unit, code, "e;", (node) => node is SimpleIdentifier); | 15269 unit, code, "e;", (node) => node is SimpleIdentifier); |
| (...skipping 2124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 17394 | 17394 |
| 17395 void _resolveTestUnit(String code) { | 17395 void _resolveTestUnit(String code) { |
| 17396 testCode = code; | 17396 testCode = code; |
| 17397 testSource = addSource(testCode); | 17397 testSource = addSource(testCode); |
| 17398 LibraryElement library = resolve2(testSource); | 17398 LibraryElement library = resolve2(testSource); |
| 17399 assertNoErrors(testSource); | 17399 assertNoErrors(testSource); |
| 17400 verify([testSource]); | 17400 verify([testSource]); |
| 17401 testUnit = resolveCompilationUnit(testSource, library); | 17401 testUnit = resolveCompilationUnit(testSource, library); |
| 17402 } | 17402 } |
| 17403 } | 17403 } |
| OLD | NEW |