| Index: pkg/analyzer/test/generated/resolver_test.dart
|
| diff --git a/pkg/analyzer/test/generated/resolver_test.dart b/pkg/analyzer/test/generated/resolver_test.dart
|
| index 396df79a7279c0e04689ae66faf4043785a20dc0..edf712e6b008fcfa73c6c29cbf8350bc3066598d 100644
|
| --- a/pkg/analyzer/test/generated/resolver_test.dart
|
| +++ b/pkg/analyzer/test/generated/resolver_test.dart
|
| @@ -2383,9 +2383,7 @@ C toSpan(dynamic element) {
|
| }
|
| return null;
|
| }''');
|
| - SimpleIdentifier y = _findIdentifier('y = ');
|
| - expect(y.staticType.toString(), 'dynamic');
|
| - expect(y.propagatedType.toString(), 'List<dynamic>');
|
| + _expectIdentifierType('y = ', 'dynamic', 'List<dynamic>');
|
| }
|
| }
|
|
|
| @@ -10141,11 +10139,7 @@ main() {
|
| }
|
| ''';
|
| _resolveTestUnit(code);
|
| - SimpleIdentifier identifier = _findIdentifier('foo');
|
| - VariableDeclaration declaration =
|
| - identifier.getAncestor((node) => node is VariableDeclaration);
|
| - expect(declaration.initializer.staticType.isDynamic, isTrue);
|
| - expect(declaration.initializer.propagatedType, isNull);
|
| + _expectInitializerType('foo', 'dynamic', isNull);
|
| }
|
|
|
| void test_FunctionExpressionInvocation_curried() {
|
| @@ -10157,11 +10151,7 @@ main() {
|
| }
|
| ''';
|
| _resolveTestUnit(code);
|
| - SimpleIdentifier identifier = _findIdentifier('foo');
|
| - VariableDeclaration declaration =
|
| - identifier.getAncestor((node) => node is VariableDeclaration);
|
| - expect(declaration.initializer.staticType.name, 'int');
|
| - expect(declaration.initializer.propagatedType, isNull);
|
| + _expectInitializerType('foo', 'int', isNull);
|
| }
|
|
|
| void test_FunctionExpressionInvocation_expression() {
|
| @@ -10171,11 +10161,7 @@ main() {
|
| }
|
| ''';
|
| _resolveTestUnit(code);
|
| - SimpleIdentifier identifier = _findIdentifier('foo');
|
| - VariableDeclaration declaration =
|
| - identifier.getAncestor((node) => node is VariableDeclaration);
|
| - expect(declaration.initializer.staticType.name, 'int');
|
| - expect(declaration.initializer.propagatedType, isNull);
|
| + _expectInitializerType('foo', 'int', isNull);
|
| }
|
|
|
| void test_MethodInvocation_nameType_localVariable() {
|
| @@ -10188,9 +10174,7 @@ main() {
|
| """;
|
| _resolveTestUnit(code);
|
| // "foo" should be resolved to the "Foo" type
|
| - SimpleIdentifier identifier = _findIdentifier("foo();");
|
| - DartType type = identifier.staticType;
|
| - expect(type, new isInstanceOf<FunctionType>());
|
| + _expectIdentifierType("foo();", new isInstanceOf<FunctionType>());
|
| }
|
|
|
| void test_MethodInvocation_nameType_parameter_FunctionTypeAlias() {
|
| @@ -10202,9 +10186,7 @@ main(Foo foo) {
|
| """;
|
| _resolveTestUnit(code);
|
| // "foo" should be resolved to the "Foo" type
|
| - SimpleIdentifier identifier = _findIdentifier("foo();");
|
| - DartType type = identifier.staticType;
|
| - expect(type, new isInstanceOf<FunctionType>());
|
| + _expectIdentifierType("foo();", new isInstanceOf<FunctionType>());
|
| }
|
|
|
| void test_MethodInvocation_nameType_parameter_propagatedType() {
|
| @@ -10217,13 +10199,8 @@ main(p) {
|
| }
|
| """;
|
| _resolveTestUnit(code);
|
| - SimpleIdentifier identifier = _findIdentifier("p()");
|
| - expect(identifier.staticType, DynamicTypeImpl.instance);
|
| - {
|
| - FunctionType type = identifier.propagatedType;
|
| - expect(type, isNotNull);
|
| - expect(type.name, 'Foo');
|
| - }
|
| + _expectIdentifierType("p()", DynamicTypeImpl.instance,
|
| + predicate((type) => type.name == 'Foo'));
|
| }
|
|
|
| void test_staticMethods_classTypeParameters() {
|
| @@ -10236,15 +10213,7 @@ main() {
|
| }
|
| ''';
|
| _resolveTestUnit(code);
|
| - SimpleIdentifier identifier = _findIdentifier('m);');
|
| - FunctionTypeImpl type = identifier.staticType;
|
| - expect(type.toString(), '() → void');
|
| - expect(type.typeParameters, isEmpty,
|
| - reason: 'static methods should not have type parameters');
|
| - expect(type.typeArguments, isEmpty,
|
| - reason: 'static methods should not have type arguments');
|
| - expect(type.typeFormals, isEmpty,
|
| - reason: 'this static method is not generic');
|
| + _expectFunctionType('m);', '() → void');
|
| }
|
|
|
| void test_staticMethods_classTypeParameters_genericMethod() {
|
| @@ -10260,15 +10229,11 @@ main() {
|
| }
|
| ''';
|
| _resolveTestUnit(code);
|
| + _expectFunctionType('m);', '<S>(S) → void',
|
| + elementTypeParams: '[S]', typeFormals: '[S]');
|
| +
|
| SimpleIdentifier identifier = _findIdentifier('m);');
|
| FunctionTypeImpl type = identifier.staticType;
|
| - expect(type.toString(), '<S>(S) → void');
|
| - expect(type.typeParameters, isEmpty,
|
| - reason: 'static methods should not have type parameters');
|
| - expect(type.typeArguments, isEmpty,
|
| - reason: 'static methods should not have type arguments');
|
| - expect(type.typeFormals.toString(), '[S]');
|
| -
|
| type = type.instantiate([DynamicTypeImpl.instance]);
|
| expect(type.toString(), '(dynamic) → void');
|
| expect(type.typeParameters.toString(), '[S]');
|
| @@ -13336,20 +13301,13 @@ void test/*<S>*/(/*=T*/ pf/*<T>*/(/*=T*/ e)) {
|
| var paramTearOffInst = pf/*<int>*/;
|
| }
|
| ''');
|
| - expect(_findIdentifier('methodTearOffInst').staticType.toString(),
|
| - "(int) → int");
|
| - expect(_findIdentifier('staticTearOffInst').staticType.toString(),
|
| - "(int) → int");
|
| - expect(_findIdentifier('staticFieldTearOffInst').staticType.toString(),
|
| - "(int) → int");
|
| - expect(_findIdentifier('topFunTearOffInst').staticType.toString(),
|
| - "(int) → int");
|
| - expect(_findIdentifier('topFieldTearOffInst').staticType.toString(),
|
| - "(int) → int");
|
| - expect(_findIdentifier('localTearOffInst').staticType.toString(),
|
| - "(int) → int");
|
| - expect(_findIdentifier('paramTearOffInst').staticType.toString(),
|
| - "(int) → int");
|
| + _expectIdentifierType('methodTearOffInst', "(int) → int");
|
| + _expectIdentifierType('staticTearOffInst', "(int) → int");
|
| + _expectIdentifierType('staticFieldTearOffInst', "(int) → int");
|
| + _expectIdentifierType('topFunTearOffInst', "(int) → int");
|
| + _expectIdentifierType('topFieldTearOffInst', "(int) → int");
|
| + _expectIdentifierType('localTearOffInst', "(int) → int");
|
| + _expectIdentifierType('paramTearOffInst', "(int) → int");
|
| }
|
|
|
| void setUp() {
|
| @@ -13367,12 +13325,7 @@ main() {
|
| }
|
| ''';
|
| _resolveTestUnit(code);
|
| -
|
| - SimpleIdentifier identifier = _findIdentifier('foo');
|
| - VariableDeclaration declaration =
|
| - identifier.getAncestor((node) => node is VariableDeclaration);
|
| - expect(declaration.initializer.staticType.name, 'int');
|
| - expect(declaration.initializer.propagatedType, isNull);
|
| + _expectInitializerType('foo', 'int', isNull);
|
| }
|
|
|
| void test_dynamicObjectMethod_toString() {
|
| @@ -13383,47 +13336,34 @@ main() {
|
| }
|
| ''';
|
| _resolveTestUnit(code);
|
| -
|
| - SimpleIdentifier identifier = _findIdentifier('foo');
|
| - VariableDeclaration declaration =
|
| - identifier.getAncestor((node) => node is VariableDeclaration);
|
| - expect(declaration.initializer.staticType.name, 'String');
|
| - expect(declaration.initializer.propagatedType, isNull);
|
| + _expectInitializerType('foo', 'String', isNull);
|
| }
|
|
|
| void test_genericFunction() {
|
| _resolveTestUnit(r'/*=T*/ f/*<T>*/(/*=T*/ x) => null;');
|
| + _expectFunctionType('f', '<T>(T) → T',
|
| + elementTypeParams: '[T]', typeFormals: '[T]');
|
| SimpleIdentifier f = _findIdentifier('f');
|
| FunctionElementImpl e = f.staticElement;
|
| - expect(e.typeParameters.toString(), '[T]');
|
| - expect(e.type.typeFormals.toString(), '[T]');
|
| - expect(e.type.typeParameters.toString(), '[]');
|
| - expect(e.type.toString(), '<T>(T) → T');
|
| -
|
| FunctionType ft = e.type.instantiate([typeProvider.stringType]);
|
| expect(ft.toString(), '(String) → String');
|
| }
|
|
|
| void test_genericFunction_bounds() {
|
| _resolveTestUnit(r'/*=T*/ f/*<T extends num>*/(/*=T*/ x) => null;');
|
| - SimpleIdentifier f = _findIdentifier('f');
|
| - FunctionElementImpl e = f.staticElement;
|
| - expect(e.typeParameters.toString(), '[T extends num]');
|
| - expect(e.type.typeFormals.toString(), '[T extends num]');
|
| - expect(e.type.typeParameters.toString(), '[]');
|
| - expect(e.type.toString(), '<T extends num>(T) → T');
|
| + _expectFunctionType('f', '<T extends num>(T) → T',
|
| + elementTypeParams: '[T extends num]', typeFormals: '[T extends num]');
|
| }
|
|
|
| void test_genericFunction_parameter() {
|
| _resolveTestUnit(r'''
|
| void g(/*=T*/ f/*<T>*/(/*=T*/ x)) {}
|
| ''');
|
| + _expectFunctionType('f', '<T>(T) → T',
|
| + elementTypeParams: '[T]', typeFormals: '[T]');
|
| SimpleIdentifier f = _findIdentifier('f');
|
| ParameterElementImpl e = f.staticElement;
|
| FunctionType type = e.type;
|
| - expect(e.typeParameters.toString(), '[T]');
|
| - expect(type.typeFormals.toString(), '[T]');
|
| - expect(type.toString(), '<T>(T) → T');
|
| FunctionType ft = type.instantiate([typeProvider.stringType]);
|
| expect(ft.toString(), '(String) → String');
|
| }
|
| @@ -13434,14 +13374,10 @@ class C<E> {
|
| static /*=T*/ f/*<T>*/(/*=T*/ x) => null;
|
| }
|
| ''');
|
| + _expectFunctionType('f', '<T>(T) → T',
|
| + elementTypeParams: '[T]', typeFormals: '[T]');
|
| SimpleIdentifier f = _findIdentifier('f');
|
| MethodElementImpl e = f.staticElement;
|
| - expect(e.typeParameters.toString(), '[T]');
|
| - expect(e.type.typeFormals.toString(), '[T]');
|
| - expect(e.type.typeParameters.toString(), '[]');
|
| - expect(e.type.typeArguments.toString(), '[]');
|
| - expect(e.type.toString(), '<T>(T) → T');
|
| -
|
| FunctionType ft = e.type.instantiate([typeProvider.stringType]);
|
| expect(ft.toString(), '(String) → String');
|
| }
|
| @@ -13479,46 +13415,18 @@ class D<S> {
|
| ''';
|
| _resolveTestUnit(code);
|
|
|
| - {
|
| - List<Statement> statements =
|
| - AstFinder.getStatementsInMethod(testUnit, "C", "g");
|
| -
|
| - ExpressionStatement exps0 = statements[1];
|
| - ExpressionStatement exps1 = statements[2];
|
| - ExpressionStatement exps2 = statements[3];
|
| - ExpressionStatement exps3 = statements[4];
|
| - ExpressionStatement exps4 = statements[5];
|
| - Expression exp0 = exps0.expression;
|
| - Expression exp1 = exps1.expression;
|
| - Expression exp2 = exps2.expression;
|
| - Expression exp3 = exps3.expression;
|
| - Expression exp4 = exps4.expression;
|
| - expect(exp0.staticType, typeProvider.dynamicType);
|
| - expect(exp1.staticType, typeProvider.dynamicType);
|
| - expect(exp2.staticType, typeProvider.dynamicType);
|
| - expect(exp3.staticType, typeProvider.dynamicType);
|
| - expect(exp4.staticType, typeProvider.dynamicType);
|
| - }
|
| - {
|
| + checkBody(String className) {
|
| List<Statement> statements =
|
| - AstFinder.getStatementsInMethod(testUnit, "D", "g");
|
| -
|
| - ExpressionStatement exps0 = statements[1];
|
| - ExpressionStatement exps1 = statements[2];
|
| - ExpressionStatement exps2 = statements[3];
|
| - ExpressionStatement exps3 = statements[4];
|
| - ExpressionStatement exps4 = statements[5];
|
| - Expression exp0 = exps0.expression;
|
| - Expression exp1 = exps1.expression;
|
| - Expression exp2 = exps2.expression;
|
| - Expression exp3 = exps3.expression;
|
| - Expression exp4 = exps4.expression;
|
| - expect(exp0.staticType, typeProvider.dynamicType);
|
| - expect(exp1.staticType, typeProvider.dynamicType);
|
| - expect(exp2.staticType, typeProvider.dynamicType);
|
| - expect(exp3.staticType, typeProvider.dynamicType);
|
| - expect(exp4.staticType, typeProvider.dynamicType);
|
| + AstFinder.getStatementsInMethod(testUnit, className, "g");
|
| +
|
| + for (int i = 1; i <= 5; i++) {
|
| + Expression exp = (statements[i] as ExpressionStatement).expression;
|
| + expect(exp.staticType, typeProvider.dynamicType);
|
| + }
|
| }
|
| +
|
| + checkBody("C");
|
| + checkBody("D");
|
| }
|
|
|
| void test_genericMethod() {
|
| @@ -13530,14 +13438,11 @@ main() {
|
| C<String> cOfString;
|
| }
|
| ''');
|
| - SimpleIdentifier f = _findIdentifier('f');
|
| - MethodElementImpl e = f.staticElement;
|
| - expect(e.typeParameters.toString(), '[T]');
|
| - expect(e.type.typeFormals.toString(), '[T]');
|
| - expect(e.type.typeParameters.toString(), '[E]');
|
| - expect(e.type.typeArguments.toString(), '[E]');
|
| - expect(e.type.toString(), '<T>(E) → List<T>');
|
| -
|
| + _expectFunctionType('f', '<T>(E) → List<T>',
|
| + elementTypeParams: '[T]',
|
| + typeParams: '[E]',
|
| + typeArgs: '[E]',
|
| + typeFormals: '[T]');
|
| SimpleIdentifier c = _findIdentifier('cOfString');
|
| FunctionType ft = (c.staticType as InterfaceType).getMethod('f').type;
|
| expect(ft.toString(), '<T>(String) → List<T>');
|
| @@ -13590,14 +13495,14 @@ void test/*<S>*/(/*=T*/ pf/*<T>*/(/*=T*/ e)) {
|
| var paramCall = (pf)/*<int>*/(3);
|
| }
|
| ''');
|
| - expect(_findIdentifier('methodCall').staticType.toString(), "int");
|
| - expect(_findIdentifier('staticCall').staticType.toString(), "int");
|
| - expect(_findIdentifier('staticFieldCall').staticType.toString(), "int");
|
| - expect(_findIdentifier('topFunCall').staticType.toString(), "int");
|
| - expect(_findIdentifier('topFieldCall').staticType.toString(), "int");
|
| - expect(_findIdentifier('localCall').staticType.toString(), "int");
|
| - expect(_findIdentifier('paramCall').staticType.toString(), "int");
|
| - expect(_findIdentifier('lambdaCall').staticType.toString(), "int");
|
| + _expectIdentifierType('methodCall', "int");
|
| + _expectIdentifierType('staticCall', "int");
|
| + _expectIdentifierType('staticFieldCall', "int");
|
| + _expectIdentifierType('topFunCall', "int");
|
| + _expectIdentifierType('topFieldCall', "int");
|
| + _expectIdentifierType('localCall', "int");
|
| + _expectIdentifierType('paramCall', "int");
|
| + _expectIdentifierType('lambdaCall', "int");
|
| }
|
|
|
| void test_genericMethod_functionExpressionInvocation_inferred() {
|
| @@ -13624,14 +13529,14 @@ void test/*<S>*/(/*=T*/ pf/*<T>*/(/*=T*/ e)) {
|
| var paramCall = (pf)(3);
|
| }
|
| ''');
|
| - expect(_findIdentifier('methodCall').staticType.toString(), "int");
|
| - expect(_findIdentifier('staticCall').staticType.toString(), "int");
|
| - expect(_findIdentifier('staticFieldCall').staticType.toString(), "int");
|
| - expect(_findIdentifier('topFunCall').staticType.toString(), "int");
|
| - expect(_findIdentifier('topFieldCall').staticType.toString(), "int");
|
| - expect(_findIdentifier('localCall').staticType.toString(), "int");
|
| - expect(_findIdentifier('paramCall').staticType.toString(), "int");
|
| - expect(_findIdentifier('lambdaCall').staticType.toString(), "int");
|
| + _expectIdentifierType('methodCall', "int");
|
| + _expectIdentifierType('staticCall', "int");
|
| + _expectIdentifierType('staticFieldCall', "int");
|
| + _expectIdentifierType('topFunCall', "int");
|
| + _expectIdentifierType('topFieldCall', "int");
|
| + _expectIdentifierType('localCall', "int");
|
| + _expectIdentifierType('paramCall', "int");
|
| + _expectIdentifierType('lambdaCall', "int");
|
| }
|
|
|
| void test_genericMethod_functionInvocation_explicit() {
|
| @@ -13656,13 +13561,13 @@ void test/*<S>*/(/*=T*/ pf/*<T>*/(/*=T*/ e)) {
|
| var paramCall = pf/*<int>*/(3);
|
| }
|
| ''');
|
| - expect(_findIdentifier('methodCall').staticType.toString(), "int");
|
| - expect(_findIdentifier('staticCall').staticType.toString(), "int");
|
| - expect(_findIdentifier('staticFieldCall').staticType.toString(), "int");
|
| - expect(_findIdentifier('topFunCall').staticType.toString(), "int");
|
| - expect(_findIdentifier('topFieldCall').staticType.toString(), "int");
|
| - expect(_findIdentifier('localCall').staticType.toString(), "int");
|
| - expect(_findIdentifier('paramCall').staticType.toString(), "int");
|
| + _expectIdentifierType('methodCall', "int");
|
| + _expectIdentifierType('staticCall', "int");
|
| + _expectIdentifierType('staticFieldCall', "int");
|
| + _expectIdentifierType('topFunCall', "int");
|
| + _expectIdentifierType('topFieldCall', "int");
|
| + _expectIdentifierType('localCall', "int");
|
| + _expectIdentifierType('paramCall', "int");
|
| }
|
|
|
| void test_genericMethod_functionInvocation_inferred() {
|
| @@ -13687,13 +13592,13 @@ void test/*<S>*/(/*=T*/ pf/*<T>*/(/*=T*/ e)) {
|
| var paramCall = pf(3);
|
| }
|
| ''');
|
| - expect(_findIdentifier('methodCall').staticType.toString(), "int");
|
| - expect(_findIdentifier('staticCall').staticType.toString(), "int");
|
| - expect(_findIdentifier('staticFieldCall').staticType.toString(), "int");
|
| - expect(_findIdentifier('topFunCall').staticType.toString(), "int");
|
| - expect(_findIdentifier('topFieldCall').staticType.toString(), "int");
|
| - expect(_findIdentifier('localCall').staticType.toString(), "int");
|
| - expect(_findIdentifier('paramCall').staticType.toString(), "int");
|
| + _expectIdentifierType('methodCall', "int");
|
| + _expectIdentifierType('staticCall', "int");
|
| + _expectIdentifierType('staticFieldCall', "int");
|
| + _expectIdentifierType('topFunCall', "int");
|
| + _expectIdentifierType('topFieldCall', "int");
|
| + _expectIdentifierType('localCall', "int");
|
| + _expectIdentifierType('paramCall', "int");
|
| }
|
|
|
| void test_genericMethod_functionTypedParameter() {
|
| @@ -13705,13 +13610,11 @@ main() {
|
| C<String> cOfString;
|
| }
|
| ''');
|
| - SimpleIdentifier f = _findIdentifier('f');
|
| - MethodElementImpl e = f.staticElement;
|
| - expect(e.typeParameters.toString(), '[T]');
|
| - expect(e.type.typeFormals.toString(), '[T]');
|
| - expect(e.type.typeParameters.toString(), '[E]');
|
| - expect(e.type.typeArguments.toString(), '[E]');
|
| - expect(e.type.toString(), '<T>((E) → T) → List<T>');
|
| + _expectFunctionType('f', '<T>((E) → T) → List<T>',
|
| + elementTypeParams: '[T]',
|
| + typeParams: '[E]',
|
| + typeArgs: '[E]',
|
| + typeFormals: '[T]');
|
|
|
| SimpleIdentifier c = _findIdentifier('cOfString');
|
| FunctionType ft = (c.staticType as InterfaceType).getMethod('f').type;
|
| @@ -13733,17 +13636,13 @@ void foo() {
|
| list.map((e) => e);
|
| list.map((e) => 3);
|
| }''');
|
| + _expectIdentifierType('map((e) => e);', '<T>((dynamic) → T) → T', isNull);
|
| + _expectIdentifierType('map((e) => 3);', '<T>((dynamic) → T) → T', isNull);
|
|
|
| - SimpleIdentifier map1 = _findIdentifier('map((e) => e);');
|
| - MethodInvocation m1 = map1.parent;
|
| + MethodInvocation m1 = _findIdentifier('map((e) => e);').parent;
|
| expect(m1.staticInvokeType.toString(), '((dynamic) → dynamic) → dynamic');
|
| - expect(map1.staticType.toString(), '<T>((dynamic) → T) → T');
|
| - expect(map1.propagatedType, isNull);
|
| - SimpleIdentifier map2 = _findIdentifier('map((e) => 3);');
|
| - MethodInvocation m2 = map2.parent;
|
| + MethodInvocation m2 = _findIdentifier('map((e) => 3);').parent;
|
| expect(m2.staticInvokeType.toString(), '((dynamic) → int) → int');
|
| - expect(map2.staticType.toString(), '<T>((dynamic) → T) → T');
|
| - expect(map2.propagatedType, isNull);
|
| }
|
|
|
| void test_genericMethod_max_doubleDouble() {
|
| @@ -13754,12 +13653,7 @@ main() {
|
| }
|
| ''';
|
| _resolveTestUnit(code);
|
| -
|
| - SimpleIdentifier identifier = _findIdentifier('foo');
|
| - VariableDeclaration declaration =
|
| - identifier.getAncestor((node) => node is VariableDeclaration);
|
| - expect(declaration.initializer.staticType.name, 'double');
|
| - expect(declaration.initializer.propagatedType, isNull);
|
| + _expectInitializerType('foo', 'double', isNull);
|
| }
|
|
|
| void test_genericMethod_max_doubleDouble_prefixed() {
|
| @@ -13770,12 +13664,7 @@ main() {
|
| }
|
| ''';
|
| _resolveTestUnit(code);
|
| -
|
| - SimpleIdentifier identifier = _findIdentifier('foo');
|
| - VariableDeclaration declaration =
|
| - identifier.getAncestor((node) => node is VariableDeclaration);
|
| - expect(declaration.initializer.staticType.name, 'double');
|
| - expect(declaration.initializer.propagatedType, isNull);
|
| + _expectInitializerType('foo', 'double', isNull);
|
| }
|
|
|
| void test_genericMethod_max_doubleInt() {
|
| @@ -13786,12 +13675,7 @@ main() {
|
| }
|
| ''';
|
| _resolveTestUnit(code);
|
| -
|
| - SimpleIdentifier identifier = _findIdentifier('foo');
|
| - VariableDeclaration declaration =
|
| - identifier.getAncestor((node) => node is VariableDeclaration);
|
| - expect(declaration.initializer.staticType.name, 'num');
|
| - expect(declaration.initializer.propagatedType, isNull);
|
| + _expectInitializerType('foo', 'num', isNull);
|
| }
|
|
|
| void test_genericMethod_max_intDouble() {
|
| @@ -13802,12 +13686,7 @@ main() {
|
| }
|
| ''';
|
| _resolveTestUnit(code);
|
| -
|
| - SimpleIdentifier identifier = _findIdentifier('foo');
|
| - VariableDeclaration declaration =
|
| - identifier.getAncestor((node) => node is VariableDeclaration);
|
| - expect(declaration.initializer.staticType.name, 'num');
|
| - expect(declaration.initializer.propagatedType, isNull);
|
| + _expectInitializerType('foo', 'num', isNull);
|
| }
|
|
|
| void test_genericMethod_max_intInt() {
|
| @@ -13818,12 +13697,7 @@ main() {
|
| }
|
| ''';
|
| _resolveTestUnit(code);
|
| -
|
| - SimpleIdentifier identifier = _findIdentifier('foo');
|
| - VariableDeclaration declaration =
|
| - identifier.getAncestor((node) => node is VariableDeclaration);
|
| - expect(declaration.initializer.staticType.name, 'int');
|
| - expect(declaration.initializer.propagatedType, isNull);
|
| + _expectInitializerType('foo', 'int', isNull);
|
| }
|
|
|
| void test_genericMethod_nestedBound() {
|
| @@ -13853,8 +13727,7 @@ class C<T> {
|
| FunctionType ft = f.staticInvokeType;
|
| expect('${ft.typeArguments}/${ft.typeParameters}', '[S, int]/[T, S]');
|
|
|
| - SimpleIdentifier f2 = _findIdentifier('f;');
|
| - expect(f2.staticType.toString(), '<S₀>(S₀) → S');
|
| + _expectIdentifierType('f;', '<S₀>(S₀) → S');
|
| }
|
|
|
| void test_genericMethod_nestedFunctions() {
|
| @@ -13864,10 +13737,8 @@ class C<T> {
|
| return null;
|
| }
|
| ''');
|
| - SimpleIdentifier g = _findIdentifier('f');
|
| - expect(g.staticType.toString(), '<S>(S) → S');
|
| - SimpleIdentifier f = _findIdentifier('g');
|
| - expect(f.staticType.toString(), '<S>(S) → dynamic');
|
| + _expectIdentifierType('f', '<S>(S) → S');
|
| + _expectIdentifierType('g', '<S>(S) → dynamic');
|
| }
|
|
|
| void test_genericMethod_override() {
|
| @@ -13879,13 +13750,11 @@ class D extends C {
|
| /*=T*/ f/*<T>*/(/*=T*/ x) => null; // from D
|
| }
|
| ''');
|
| + _expectFunctionType('f/*<T>*/(/*=T*/ x) => null; // from D', '<T>(T) → T',
|
| + elementTypeParams: '[T]', typeFormals: '[T]');
|
| SimpleIdentifier f =
|
| _findIdentifier('f/*<T>*/(/*=T*/ x) => null; // from D');
|
| MethodElementImpl e = f.staticElement;
|
| - expect(e.typeParameters.toString(), '[T]');
|
| - expect(e.type.typeFormals.toString(), '[T]');
|
| - expect(e.type.toString(), '<T>(T) → T');
|
| -
|
| FunctionType ft = e.type.instantiate([typeProvider.stringType]);
|
| expect(ft.toString(), '(String) → String');
|
| }
|
| @@ -13982,9 +13851,7 @@ C toSpan(dynamic element) {
|
| }
|
| return null;
|
| }''');
|
| - SimpleIdentifier y = _findIdentifier('y = ');
|
| - expect(y.staticType.toString(), 'List<C>');
|
| - expect(y.propagatedType, isNull);
|
| + _expectIdentifierType('y = ', 'List<C>', isNull);
|
| }
|
|
|
| void test_genericMethod_tearoff() {
|
| @@ -14009,18 +13876,13 @@ void test/*<S>*/(/*=T*/ pf/*<T>*/(/*=T*/ e)) {
|
| var paramTearOff = pf;
|
| }
|
| ''');
|
| - expect(
|
| - _findIdentifier('methodTearOff').staticType.toString(), "<T>(int) → T");
|
| - expect(
|
| - _findIdentifier('staticTearOff').staticType.toString(), "<T>(T) → T");
|
| - expect(_findIdentifier('staticFieldTearOff').staticType.toString(),
|
| - "<T>(T) → T");
|
| - expect(
|
| - _findIdentifier('topFunTearOff').staticType.toString(), "<T>(T) → T");
|
| - expect(
|
| - _findIdentifier('topFieldTearOff').staticType.toString(), "<T>(T) → T");
|
| - expect(_findIdentifier('localTearOff').staticType.toString(), "<T>(T) → T");
|
| - expect(_findIdentifier('paramTearOff').staticType.toString(), "<T>(T) → T");
|
| + _expectIdentifierType('methodTearOff', "<T>(int) → T");
|
| + _expectIdentifierType('staticTearOff', "<T>(T) → T");
|
| + _expectIdentifierType('staticFieldTearOff', "<T>(T) → T");
|
| + _expectIdentifierType('topFunTearOff', "<T>(T) → T");
|
| + _expectIdentifierType('topFieldTearOff', "<T>(T) → T");
|
| + _expectIdentifierType('localTearOff', "<T>(T) → T");
|
| + _expectIdentifierType('paramTearOff', "<T>(T) → T");
|
| }
|
|
|
| void test_genericMethod_then() {
|
| @@ -14033,13 +13895,7 @@ main() {
|
| }
|
| ''';
|
| _resolveTestUnit(code);
|
| -
|
| - SimpleIdentifier identifier = _findIdentifier('foo');
|
| - VariableDeclaration declaration =
|
| - identifier.getAncestor((node) => node is VariableDeclaration);
|
| -
|
| - expect(declaration.initializer.staticType.toString(), "Future<String>");
|
| - expect(declaration.initializer.propagatedType, isNull);
|
| + _expectInitializerType('foo', 'Future<String>', isNull);
|
| }
|
|
|
| void test_genericMethod_then_prefixed() {
|
| @@ -14052,13 +13908,7 @@ main() {
|
| }
|
| ''';
|
| _resolveTestUnit(code);
|
| -
|
| - SimpleIdentifier identifier = _findIdentifier('foo');
|
| - VariableDeclaration declaration =
|
| - identifier.getAncestor((node) => node is VariableDeclaration);
|
| -
|
| - expect(declaration.initializer.staticType.toString(), "Future<String>");
|
| - expect(declaration.initializer.propagatedType, isNull);
|
| + _expectInitializerType('foo', 'Future<String>', isNull);
|
| }
|
|
|
| void test_genericMethod_then_propagatedType() {
|
| @@ -14072,9 +13922,7 @@ void main() {
|
| ''';
|
| // This should produce no hints or warnings.
|
| _resolveTestUnit(code);
|
| - VariableDeclaration foo = _findIdentifier('foo').parent;
|
| - expect(foo.initializer.staticType.toString(), "Future<String>");
|
| - expect(foo.initializer.propagatedType, isNull);
|
| + _expectInitializerType('foo', 'Future<String>', isNull);
|
| }
|
|
|
| void test_setterWithDynamicTypeIsError() {
|
| @@ -14157,12 +14005,7 @@ main() {
|
| }
|
| ''';
|
| _resolveTestUnit(code);
|
| -
|
| - SimpleIdentifier identifier = _findIdentifier('foo');
|
| - VariableDeclaration declaration =
|
| - identifier.getAncestor((node) => node is VariableDeclaration);
|
| - expect(declaration.initializer.staticType.name, 'int');
|
| - expect(declaration.initializer.propagatedType, isNull);
|
| + _expectInitializerType('foo', 'int', isNull);
|
| }
|
|
|
| void test_ternaryOperator_null_right() {
|
| @@ -14172,12 +14015,7 @@ main() {
|
| }
|
| ''';
|
| _resolveTestUnit(code);
|
| -
|
| - SimpleIdentifier identifier = _findIdentifier('foo');
|
| - VariableDeclaration declaration =
|
| - identifier.getAncestor((node) => node is VariableDeclaration);
|
| - expect(declaration.initializer.staticType.name, 'int');
|
| - expect(declaration.initializer.propagatedType, isNull);
|
| + _expectInitializerType('foo', 'int', isNull);
|
| }
|
| }
|
|
|
| @@ -17093,6 +16931,81 @@ class _StaticTypeAnalyzer2TestShared extends ResolverTestCase {
|
| return identifier;
|
| }
|
|
|
| + /**
|
| + * Looks up the identifier with [name] and validates its static [type].
|
| + *
|
| + * If [type] is a string, validates that the identifier's static type
|
| + * stringifies to that text. Otherwise, [type] is used directly a [Matcher]
|
| + * to match the type.
|
| + *
|
| + * If [propagatedType] is given, also validate's the identifier's propagated
|
| + * type.
|
| + */
|
| + void _expectIdentifierType(String name, type, [propagatedType]) {
|
| + SimpleIdentifier identifier = _findIdentifier(name);
|
| + _expectType(identifier.staticType, type);
|
| + if (propagatedType != null) {
|
| + _expectType(identifier.propagatedType, propagatedType);
|
| + }
|
| + }
|
| +
|
| + /**
|
| + * Looks up the initializer for the declaration containing [identifier] and
|
| + * validates its static [type].
|
| + *
|
| + * If [type] is a string, validates that the identifier's static type
|
| + * stringifies to that text. Otherwise, [type] is used directly a [Matcher]
|
| + * to match the type.
|
| + *
|
| + * If [propagatedType] is given, also validate's the identifier's propagated
|
| + * type.
|
| + */
|
| + void _expectInitializerType(String name, type, [propagatedType]) {
|
| + SimpleIdentifier identifier = _findIdentifier(name);
|
| + VariableDeclaration declaration =
|
| + identifier.getAncestor((node) => node is VariableDeclaration);
|
| + Expression initializer = declaration.initializer;
|
| + _expectType(initializer.staticType, type);
|
| + if (propagatedType != null) {
|
| + _expectType(initializer.propagatedType, propagatedType);
|
| + }
|
| + }
|
| +
|
| + /**
|
| + * Looks up the identifier with [name] and validates that its type type
|
| + * stringifies to [type] and that its generics match the given stringified
|
| + * output.
|
| + */
|
| + _expectFunctionType(String name, String type,
|
| + {String elementTypeParams: '[]',
|
| + String typeParams: '[]',
|
| + String typeArgs: '[]',
|
| + String typeFormals: '[]'}) {
|
| + SimpleIdentifier identifier = _findIdentifier(name);
|
| + // Element is either ExecutableElement or ParameterElement.
|
| + var element = identifier.staticElement;
|
| + FunctionTypeImpl functionType = identifier.staticType;
|
| + expect(functionType.toString(), type);
|
| + expect(element.typeParameters.toString(), elementTypeParams);
|
| + expect(functionType.typeParameters.toString(), typeParams);
|
| + expect(functionType.typeArguments.toString(), typeArgs);
|
| + expect(functionType.typeFormals.toString(), typeFormals);
|
| + }
|
| +
|
| + /**
|
| + * Validates that [type] matches [expected].
|
| + *
|
| + * If [expected] is a string, validates that the type stringifies to that
|
| + * text. Otherwise, [expected] is used directly a [Matcher] to match the type.
|
| + */
|
| + _expectType(DartType type, expected) {
|
| + if (expected is String) {
|
| + expect(type.toString(), expected);
|
| + } else {
|
| + expect(type, expected);
|
| + }
|
| + }
|
| +
|
| void _resolveTestUnit(String code) {
|
| testCode = code;
|
| testSource = addSource(testCode);
|
|
|