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 6002 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6013 * If the given [type] is valid, strongly more specific than the | 6013 * If the given [type] is valid, strongly more specific than the |
6014 * existing static type of the given [expression], record it as a propagated | 6014 * existing static type of the given [expression], record it as a propagated |
6015 * type of the given [expression]. Otherwise, reset it to `null`. | 6015 * type of the given [expression]. Otherwise, reset it to `null`. |
6016 * | 6016 * |
6017 * If [hasOldPropagatedType] is `true` then the existing propagated type | 6017 * If [hasOldPropagatedType] is `true` then the existing propagated type |
6018 * should also is checked. | 6018 * should also is checked. |
6019 */ | 6019 */ |
6020 void recordPropagatedTypeIfBetter(Expression expression, DartType type, | 6020 void recordPropagatedTypeIfBetter(Expression expression, DartType type, |
6021 [bool hasOldPropagatedType = false]) { | 6021 [bool hasOldPropagatedType = false]) { |
6022 // Ensure that propagated type invalid. | 6022 // Ensure that propagated type invalid. |
6023 if (type == null || type.isDynamic || type.isBottom) { | 6023 if (strongMode || type == null || type.isDynamic || type.isBottom) { |
6024 if (!hasOldPropagatedType) { | 6024 if (!hasOldPropagatedType) { |
6025 expression.propagatedType = null; | 6025 expression.propagatedType = null; |
6026 } | 6026 } |
6027 return; | 6027 return; |
6028 } | 6028 } |
6029 // Ensure that propagated type is more specific than the static type. | 6029 // Ensure that propagated type is more specific than the static type. |
6030 DartType staticType = expression.staticType; | 6030 DartType staticType = expression.staticType; |
6031 if (type == staticType || !type.isMoreSpecificThan(staticType)) { | 6031 if (type == staticType || !type.isMoreSpecificThan(staticType)) { |
6032 expression.propagatedType = null; | 6032 expression.propagatedType = null; |
6033 return; | 6033 return; |
(...skipping 1381 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7415 !FunctionTypeImpl.relate( | 7415 !FunctionTypeImpl.relate( |
7416 expectedClosureType, | 7416 expectedClosureType, |
7417 staticClosureType, | 7417 staticClosureType, |
7418 (DartType t, DartType s, _, __) => | 7418 (DartType t, DartType s, _, __) => |
7419 (t as TypeImpl).isMoreSpecificThan(s), | 7419 (t as TypeImpl).isMoreSpecificThan(s), |
7420 new TypeSystemImpl().instantiateToBounds, | 7420 new TypeSystemImpl().instantiateToBounds, |
7421 returnRelation: (s, t) => true)) { | 7421 returnRelation: (s, t) => true)) { |
7422 return; | 7422 return; |
7423 } | 7423 } |
7424 // set propagated type for the closure | 7424 // set propagated type for the closure |
7425 closure.propagatedType = expectedClosureType; | 7425 if (!strongMode) { |
| 7426 closure.propagatedType = expectedClosureType; |
| 7427 } |
7426 // set inferred types for parameters | 7428 // set inferred types for parameters |
7427 NodeList<FormalParameter> parameters = closure.parameters.parameters; | 7429 NodeList<FormalParameter> parameters = closure.parameters.parameters; |
7428 List<ParameterElement> expectedParameters = expectedClosureType.parameters; | 7430 List<ParameterElement> expectedParameters = expectedClosureType.parameters; |
7429 for (int i = 0; | 7431 for (int i = 0; |
7430 i < parameters.length && i < expectedParameters.length; | 7432 i < parameters.length && i < expectedParameters.length; |
7431 i++) { | 7433 i++) { |
7432 FormalParameter parameter = parameters[i]; | 7434 FormalParameter parameter = parameters[i]; |
7433 ParameterElement element = parameter.element; | 7435 ParameterElement element = parameter.element; |
7434 DartType currentType = _overrideManager.getBestType(element); | 7436 DartType currentType = _overrideManager.getBestType(element); |
7435 // may be override the type | 7437 // may be override the type |
(...skipping 3835 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
11271 return null; | 11273 return null; |
11272 } | 11274 } |
11273 if (identical(node.staticElement, variable)) { | 11275 if (identical(node.staticElement, variable)) { |
11274 if (node.inSetterContext()) { | 11276 if (node.inSetterContext()) { |
11275 result = true; | 11277 result = true; |
11276 } | 11278 } |
11277 } | 11279 } |
11278 return null; | 11280 return null; |
11279 } | 11281 } |
11280 } | 11282 } |
OLD | NEW |