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.src.generated.resolver; | 5 library analyzer.src.generated.resolver; |
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 8143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8154 _enclosingFunction = outerFunction; | 8154 _enclosingFunction = outerFunction; |
8155 } | 8155 } |
8156 return null; | 8156 return null; |
8157 } | 8157 } |
8158 | 8158 |
8159 @override | 8159 @override |
8160 Object visitFunctionExpressionInvocation(FunctionExpressionInvocation node) { | 8160 Object visitFunctionExpressionInvocation(FunctionExpressionInvocation node) { |
8161 safelyVisit(node.function); | 8161 safelyVisit(node.function); |
8162 node.accept(elementResolver); | 8162 node.accept(elementResolver); |
8163 _inferFunctionExpressionsParametersTypes(node.argumentList); | 8163 _inferFunctionExpressionsParametersTypes(node.argumentList); |
8164 InferenceContext.setType(node.argumentList, node.function.staticType); | 8164 _inferArgumentTypesFromContext(node); |
8165 safelyVisit(node.argumentList); | 8165 safelyVisit(node.argumentList); |
8166 node.accept(typeAnalyzer); | 8166 node.accept(typeAnalyzer); |
8167 return null; | 8167 return null; |
8168 } | 8168 } |
8169 | 8169 |
8170 @override | 8170 @override |
8171 Object visitFunctionTypeAlias(FunctionTypeAlias node) { | 8171 Object visitFunctionTypeAlias(FunctionTypeAlias node) { |
8172 // Resolve the metadata in the library scope. | 8172 // Resolve the metadata in the library scope. |
8173 if (node.metadata != null) { | 8173 if (node.metadata != null) { |
8174 node.metadata.accept(this); | 8174 node.metadata.accept(this); |
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8373 @override | 8373 @override |
8374 Object visitMethodInvocation(MethodInvocation node) { | 8374 Object visitMethodInvocation(MethodInvocation node) { |
8375 // | 8375 // |
8376 // We visit the target and argument list, but do not visit the method name | 8376 // We visit the target and argument list, but do not visit the method name |
8377 // because it needs to be visited in the context of the invocation. | 8377 // because it needs to be visited in the context of the invocation. |
8378 // | 8378 // |
8379 safelyVisit(node.target); | 8379 safelyVisit(node.target); |
8380 safelyVisit(node.typeArguments); | 8380 safelyVisit(node.typeArguments); |
8381 node.accept(elementResolver); | 8381 node.accept(elementResolver); |
8382 _inferFunctionExpressionsParametersTypes(node.argumentList); | 8382 _inferFunctionExpressionsParametersTypes(node.argumentList); |
8383 DartType contextType = node.staticInvokeType; | 8383 _inferArgumentTypesFromContext(node); |
8384 if (contextType is FunctionType) { | |
8385 InferenceContext.setType(node.argumentList, contextType); | |
8386 } | |
8387 safelyVisit(node.argumentList); | 8384 safelyVisit(node.argumentList); |
8388 node.accept(typeAnalyzer); | 8385 node.accept(typeAnalyzer); |
8389 return null; | 8386 return null; |
8390 } | 8387 } |
8391 | 8388 |
| 8389 void _inferArgumentTypesFromContext(InvocationExpression node) { |
| 8390 DartType contextType = node.staticInvokeType; |
| 8391 if (contextType is FunctionType) { |
| 8392 DartType originalType = node.invocationTarget.staticType; |
| 8393 DartType returnContextType = InferenceContext.getType(node); |
| 8394 TypeSystem ts = typeSystem; |
| 8395 if (returnContextType != null && |
| 8396 node.typeArguments == null && |
| 8397 originalType is FunctionType && |
| 8398 originalType.typeFormals.isNotEmpty && |
| 8399 ts is StrongTypeSystemImpl) { |
| 8400 |
| 8401 contextType = ts.inferGenericFunctionCall(typeProvider, originalType, |
| 8402 DartType.EMPTY_LIST, DartType.EMPTY_LIST, returnContextType); |
| 8403 } |
| 8404 |
| 8405 InferenceContext.setType(node.argumentList, contextType); |
| 8406 } |
| 8407 } |
| 8408 |
8392 @override | 8409 @override |
8393 Object visitNamedExpression(NamedExpression node) { | 8410 Object visitNamedExpression(NamedExpression node) { |
8394 InferenceContext.setType(node.expression, InferenceContext.getType(node)); | 8411 InferenceContext.setType(node.expression, InferenceContext.getType(node)); |
8395 return super.visitNamedExpression(node); | 8412 return super.visitNamedExpression(node); |
8396 } | 8413 } |
8397 | 8414 |
8398 @override | 8415 @override |
8399 Object visitNode(AstNode node) { | 8416 Object visitNode(AstNode node) { |
8400 node.visitChildren(this); | 8417 node.visitChildren(this); |
8401 node.accept(elementResolver); | 8418 node.accept(elementResolver); |
(...skipping 4380 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
12782 nonFields.add(node); | 12799 nonFields.add(node); |
12783 return null; | 12800 return null; |
12784 } | 12801 } |
12785 | 12802 |
12786 @override | 12803 @override |
12787 Object visitNode(AstNode node) => node.accept(TypeResolverVisitor_this); | 12804 Object visitNode(AstNode node) => node.accept(TypeResolverVisitor_this); |
12788 | 12805 |
12789 @override | 12806 @override |
12790 Object visitWithClause(WithClause node) => null; | 12807 Object visitWithClause(WithClause node) => null; |
12791 } | 12808 } |
OLD | NEW |