| 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 engine.resolver; | 5 library engine.resolver; |
| 6 | 6 |
| 7 import 'dart:collection'; | 7 import 'dart:collection'; |
| 8 | 8 |
| 9 import 'ast.dart'; | 9 import 'ast.dart'; |
| 10 import 'constant.dart'; | 10 import 'constant.dart'; |
| (...skipping 10511 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10522 * @param element the element whose type might be overridden | 10522 * @param element the element whose type might be overridden |
| 10523 * @param potentialType the potential type of the element | 10523 * @param potentialType the potential type of the element |
| 10524 * @param allowPrecisionLoss true if `potentialType` is allowed to be less pre
cise than the | 10524 * @param allowPrecisionLoss true if `potentialType` is allowed to be less pre
cise than the |
| 10525 * current best type | 10525 * current best type |
| 10526 * | 10526 * |
| 10527 * Return a new better [DartType], or `null` if [potentialType] is not better | 10527 * Return a new better [DartType], or `null` if [potentialType] is not better |
| 10528 * than the current [element] type. | 10528 * than the current [element] type. |
| 10529 */ | 10529 */ |
| 10530 DartType overrideVariable(VariableElement element, DartType potentialType, | 10530 DartType overrideVariable(VariableElement element, DartType potentialType, |
| 10531 bool allowPrecisionLoss) { | 10531 bool allowPrecisionLoss) { |
| 10532 // TODO(scheglov) type propagation for instance/top-level fields |
| 10533 // was disabled because it depends on the order or visiting. |
| 10534 // If both field and its client are in the same unit, and we visit |
| 10535 // the client before the field, then propagated type is not set yet. |
| 10536 if (element is PropertyInducingElement) { |
| 10537 return null; |
| 10538 } |
| 10539 |
| 10532 if (potentialType == null || potentialType.isBottom) { | 10540 if (potentialType == null || potentialType.isBottom) { |
| 10533 return null; | 10541 return null; |
| 10534 } | 10542 } |
| 10535 DartType currentType = _overrideManager.getBestType(element); | 10543 DartType currentType = _overrideManager.getBestType(element); |
| 10536 | 10544 |
| 10537 if (potentialType == currentType) { | 10545 if (potentialType == currentType) { |
| 10538 return null; | 10546 return null; |
| 10539 } | 10547 } |
| 10540 | 10548 |
| 10541 // If we aren't allowing precision loss then the third and fourth conditions | 10549 // If we aren't allowing precision loss then the third and fourth conditions |
| (...skipping 12 matching lines...) Expand all Loading... |
| 10554 // It also covers an important case that is not applicable in the spec: | 10562 // It also covers an important case that is not applicable in the spec: |
| 10555 // for union types, we want an is-check to promote from an union type to | 10563 // for union types, we want an is-check to promote from an union type to |
| 10556 // (a subtype of) any of its members. | 10564 // (a subtype of) any of its members. |
| 10557 // | 10565 // |
| 10558 // The first check, that [! (C << P)], covers the case where [P] and [C] are | 10566 // The first check, that [! (C << P)], covers the case where [P] and [C] are |
| 10559 // unrelated types; This case is not addressed in the spec for static types. | 10567 // unrelated types; This case is not addressed in the spec for static types. |
| 10560 if (currentType == null || | 10568 if (currentType == null || |
| 10561 allowPrecisionLoss || | 10569 allowPrecisionLoss || |
| 10562 !currentType.isMoreSpecificThan(potentialType) || | 10570 !currentType.isMoreSpecificThan(potentialType) || |
| 10563 potentialType.isMoreSpecificThan(currentType)) { | 10571 potentialType.isMoreSpecificThan(currentType)) { |
| 10564 // TODO(scheglov) type propagation for instance/top-level fields | |
| 10565 // was disabled because it depends on the order or visiting. | |
| 10566 // If both field and its client are in the same unit, and we visit | |
| 10567 // the client before the field, then propagated type is not set yet. | |
| 10568 // if (element is PropertyInducingElement) { | |
| 10569 // PropertyInducingElement variable = element; | |
| 10570 // if (!variable.isConst && !variable.isFinal) { | |
| 10571 // return; | |
| 10572 // } | |
| 10573 // (variable as PropertyInducingElementImpl).propagatedType = | |
| 10574 // potentialType; | |
| 10575 // } | |
| 10576 _overrideManager.setType(element, potentialType); | 10572 _overrideManager.setType(element, potentialType); |
| 10577 return potentialType; | 10573 return potentialType; |
| 10578 } | 10574 } |
| 10579 return null; | 10575 return null; |
| 10580 } | 10576 } |
| 10581 | 10577 |
| 10582 /** | 10578 /** |
| 10583 * A client is about to resolve a member in the given class declaration. | 10579 * A client is about to resolve a member in the given class declaration. |
| 10584 */ | 10580 */ |
| 10585 void prepareToResolveMembersInClass(ClassDeclaration node) { | 10581 void prepareToResolveMembersInClass(ClassDeclaration node) { |
| (...skipping 5345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 15931 nonFields.add(node); | 15927 nonFields.add(node); |
| 15932 return null; | 15928 return null; |
| 15933 } | 15929 } |
| 15934 | 15930 |
| 15935 @override | 15931 @override |
| 15936 Object visitNode(AstNode node) => node.accept(TypeResolverVisitor_this); | 15932 Object visitNode(AstNode node) => node.accept(TypeResolverVisitor_this); |
| 15937 | 15933 |
| 15938 @override | 15934 @override |
| 15939 Object visitWithClause(WithClause node) => null; | 15935 Object visitWithClause(WithClause node) => null; |
| 15940 } | 15936 } |
| OLD | NEW |