Chromium Code Reviews| 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/standard_resolution_map.dart'; | 10 import 'package:analyzer/dart/ast/standard_resolution_map.dart'; |
| (...skipping 5200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5211 } | 5211 } |
| 5212 | 5212 |
| 5213 /** | 5213 /** |
| 5214 * Prepares this [ResolverVisitor] to using it for incremental resolution. | 5214 * Prepares this [ResolverVisitor] to using it for incremental resolution. |
| 5215 */ | 5215 */ |
| 5216 void initForIncrementalResolution() { | 5216 void initForIncrementalResolution() { |
| 5217 _overrideManager.enterScope(); | 5217 _overrideManager.enterScope(); |
| 5218 } | 5218 } |
| 5219 | 5219 |
| 5220 /** | 5220 /** |
| 5221 * TODO(leafp): Eliminate this when code is switched to using FutureOr | |
|
Jennifer Messerly
2017/02/03 18:31:51
nit: this should go outside of the doc comment
Leaf
2017/02/03 21:28:56
Done.
| |
| 5222 * | |
| 5223 * Returns true if this method is `Future.then` or an override thereof. | |
| 5224 * | |
| 5225 * If so we will apply special typing rules in strong mode, to handle the | |
| 5226 * implicit union of `S | Future<S>` | |
| 5227 */ | |
| 5228 bool isFutureThen(Element element) { | |
| 5229 // If we are a method named then | |
| 5230 if (element is MethodElement && element.name == 'then') { | |
| 5231 DartType type = element.enclosingElement.type; | |
| 5232 // On Future or a subtype, then we're good. | |
| 5233 return (type.isDartAsyncFuture || isSubtypeOfFuture(type)); | |
| 5234 } | |
| 5235 return false; | |
| 5236 } | |
| 5237 | |
| 5238 /** | |
| 5239 * TODO(leafp): Eliminate this when code is switched to using FutureOr | |
| 5221 * Returns true if this type is any subtype of the built in Future type. | 5240 * Returns true if this type is any subtype of the built in Future type. |
| 5222 */ | 5241 */ |
| 5223 bool isSubtypeOfFuture(DartType type) => | 5242 bool isSubtypeOfFuture(DartType type) => |
| 5224 typeSystem.isSubtypeOf(type, typeProvider.futureDynamicType); | 5243 typeSystem.isSubtypeOf(type, typeProvider.futureDynamicType); |
| 5225 | 5244 |
| 5226 /** | 5245 /** |
| 5227 * Given a downward inference type [fnType], and the declared | 5246 * Given a downward inference type [fnType], and the declared |
| 5228 * [typeParameterList] for a function expression, determines if we can enable | 5247 * [typeParameterList] for a function expression, determines if we can enable |
| 5229 * downward inference and if so, returns the function type to use for | 5248 * downward inference and if so, returns the function type to use for |
| 5230 * inference. | 5249 * inference. |
| (...skipping 822 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 6053 _currentFunctionBody = node.body; | 6072 _currentFunctionBody = node.body; |
| 6054 _enclosingFunction = node.element; | 6073 _enclosingFunction = node.element; |
| 6055 _overrideManager.enterScope(); | 6074 _overrideManager.enterScope(); |
| 6056 try { | 6075 try { |
| 6057 DartType functionType = InferenceContext.getType(node); | 6076 DartType functionType = InferenceContext.getType(node); |
| 6058 if (functionType is FunctionType) { | 6077 if (functionType is FunctionType) { |
| 6059 functionType = | 6078 functionType = |
| 6060 matchFunctionTypeParameters(node.typeParameters, functionType); | 6079 matchFunctionTypeParameters(node.typeParameters, functionType); |
| 6061 if (functionType is FunctionType) { | 6080 if (functionType is FunctionType) { |
| 6062 _inferFormalParameterList(node.parameters, functionType); | 6081 _inferFormalParameterList(node.parameters, functionType); |
| 6063 InferenceContext.setType( | 6082 DartType returnType; |
| 6064 node.body, _computeReturnOrYieldType(functionType.returnType)); | 6083 ParameterElement parameterElement = |
| 6084 resolutionMap.staticParameterElementForExpression(node); | |
| 6085 if (isFutureThen(parameterElement?.enclosingElement)) { | |
| 6086 var futureThenType = | |
| 6087 InferenceContext.getContext(node.parent) as FunctionType; | |
| 6088 | |
| 6089 // TODO(leafp): Get rid of this once code has been updated to use | |
| 6090 // FutureOr | |
| 6091 // Pretend the return type of Future<T>.then<S> first parameter is | |
|
Jennifer Messerly
2017/02/03 18:31:51
this comment is obsolete now, I think... should sa
Leaf
2017/02/03 21:28:56
Done.
| |
| 6092 // | |
| 6093 // T -> (S | Future<S>) | |
| 6094 // | |
| 6095 // We can't represent this in Dart so we populate it here during | |
| 6096 // inference. | |
| 6097 if (futureThenType.parameters.isNotEmpty) { | |
| 6098 if (!futureThenType.parameters[0].type.isDartAsyncFutureOr) { | |
| 6099 var typeParamS = | |
| 6100 futureThenType.returnType.flattenFutures(typeSystem); | |
| 6101 returnType = _createFutureOr(typeParamS); | |
| 6102 } | |
| 6103 } | |
| 6104 } | |
| 6105 returnType ??= _computeReturnOrYieldType(functionType.returnType); | |
| 6106 InferenceContext.setType(node.body, returnType); | |
| 6065 } | 6107 } |
| 6066 } | 6108 } |
| 6067 super.visitFunctionExpression(node); | 6109 super.visitFunctionExpression(node); |
| 6068 } finally { | 6110 } finally { |
| 6069 _overrideManager.exitScope(); | 6111 _overrideManager.exitScope(); |
| 6070 } | 6112 } |
| 6071 } finally { | 6113 } finally { |
| 6072 _currentFunctionBody = outerFunctionBody; | 6114 _currentFunctionBody = outerFunctionBody; |
| 6073 _enclosingFunction = outerFunction; | 6115 _enclosingFunction = outerFunction; |
| 6074 } | 6116 } |
| (...skipping 4776 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 10851 return null; | 10893 return null; |
| 10852 } | 10894 } |
| 10853 if (identical(node.staticElement, variable)) { | 10895 if (identical(node.staticElement, variable)) { |
| 10854 if (node.inSetterContext()) { | 10896 if (node.inSetterContext()) { |
| 10855 result = true; | 10897 result = true; |
| 10856 } | 10898 } |
| 10857 } | 10899 } |
| 10858 return null; | 10900 return null; |
| 10859 } | 10901 } |
| 10860 } | 10902 } |
| OLD | NEW |