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/element/element.dart'; | 9 import 'package:analyzer/dart/element/element.dart'; |
10 import 'package:analyzer/dart/element/type.dart'; | 10 import 'package:analyzer/dart/element/type.dart'; |
(...skipping 9705 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9716 * @param potentialType the potential type of the elements | 9716 * @param potentialType the potential type of the elements |
9717 */ | 9717 */ |
9718 void _promote(Expression expression, DartType potentialType) { | 9718 void _promote(Expression expression, DartType potentialType) { |
9719 VariableElement element = getPromotionStaticElement(expression); | 9719 VariableElement element = getPromotionStaticElement(expression); |
9720 if (element != null) { | 9720 if (element != null) { |
9721 // may be mutated somewhere in closure | 9721 // may be mutated somewhere in closure |
9722 if (element.isPotentiallyMutatedInClosure) { | 9722 if (element.isPotentiallyMutatedInClosure) { |
9723 return; | 9723 return; |
9724 } | 9724 } |
9725 // prepare current variable type | 9725 // prepare current variable type |
9726 DartType type = _promoteManager.getType(element); | 9726 DartType type = _promoteManager.getType(element) ?? |
9727 if (type == null) { | 9727 expression.staticType ?? |
9728 type = expression.staticType; | 9728 DynamicTypeImpl.instance; |
| 9729 |
| 9730 potentialType ??= DynamicTypeImpl.instance; |
| 9731 |
| 9732 // Check if we can promote to potentialType from type. |
| 9733 if (typeSystem.canPromoteToType(potentialType, type)) { |
| 9734 // Do promote type of variable. |
| 9735 _promoteManager.setType(element, potentialType); |
9729 } | 9736 } |
9730 // Declared type should not be "dynamic". | |
9731 if (type == null || type.isDynamic) { | |
9732 return; | |
9733 } | |
9734 // Promoted type should not be "dynamic". | |
9735 if (potentialType == null || potentialType.isDynamic) { | |
9736 return; | |
9737 } | |
9738 // Promoted type should be more specific than declared. | |
9739 if (!potentialType.isMoreSpecificThan(type)) { | |
9740 return; | |
9741 } | |
9742 // Do promote type of variable. | |
9743 _promoteManager.setType(element, potentialType); | |
9744 } | 9737 } |
9745 } | 9738 } |
9746 | 9739 |
9747 /** | 9740 /** |
9748 * Promotes type information using given condition. | 9741 * Promotes type information using given condition. |
9749 */ | 9742 */ |
9750 void _promoteTypes(Expression condition) { | 9743 void _promoteTypes(Expression condition) { |
9751 if (condition is BinaryExpression) { | 9744 if (condition is BinaryExpression) { |
9752 BinaryExpression binary = condition; | 9745 BinaryExpression binary = condition; |
9753 if (binary.operator.type == TokenType.AMPERSAND_AMPERSAND) { | 9746 if (binary.operator.type == TokenType.AMPERSAND_AMPERSAND) { |
(...skipping 3851 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
13605 nonFields.add(node); | 13598 nonFields.add(node); |
13606 return null; | 13599 return null; |
13607 } | 13600 } |
13608 | 13601 |
13609 @override | 13602 @override |
13610 Object visitNode(AstNode node) => node.accept(TypeResolverVisitor_this); | 13603 Object visitNode(AstNode node) => node.accept(TypeResolverVisitor_this); |
13611 | 13604 |
13612 @override | 13605 @override |
13613 Object visitWithClause(WithClause node) => null; | 13606 Object visitWithClause(WithClause node) => null; |
13614 } | 13607 } |
OLD | NEW |