| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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.type_system; | 5 library analyzer.src.generated.type_system; |
| 6 | 6 |
| 7 import 'dart:collection'; | 7 import 'dart:collection'; |
| 8 import 'dart:math' as math; | 8 import 'dart:math' as math; |
| 9 | 9 |
| 10 import 'package:analyzer/dart/ast/token.dart' show TokenType; | 10 import 'package:analyzer/dart/ast/token.dart' show TokenType; |
| (...skipping 1408 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1419 // we choose the upper bound as being the most useful. | 1419 // we choose the upper bound as being the most useful. |
| 1420 // | 1420 // |
| 1421 // Otherwise we choose the more precise lower bound. | 1421 // Otherwise we choose the more precise lower bound. |
| 1422 _TypeParameterVariance variance = | 1422 _TypeParameterVariance variance = |
| 1423 new _TypeParameterVariance.from(typeParam, fnType.returnType); | 1423 new _TypeParameterVariance.from(typeParam, fnType.returnType); |
| 1424 | 1424 |
| 1425 _TypeParameterBound bound = _bounds[typeParam]; | 1425 _TypeParameterBound bound = _bounds[typeParam]; |
| 1426 inferredTypes[i] = | 1426 inferredTypes[i] = |
| 1427 variance.passedIn || bound.lower.isBottom ? bound.upper : bound.lower; | 1427 variance.passedIn || bound.lower.isBottom ? bound.upper : bound.lower; |
| 1428 | 1428 |
| 1429 // See if the constraints on the type variable are satisfied. | 1429 // See if the bounds can be satisfied. |
| 1430 // | 1430 if (bound.upper.isBottom || |
| 1431 // If not, bail out of the analysis, unless a partial solution was | 1431 !_typeSystem.isSubtypeOf(bound.lower, bound.upper)) { |
| 1432 // requested. If we are willing to accept a partial solution, fall back to | |
| 1433 // the known upper bound (if any) or `dynamic` for this unsolvable type | |
| 1434 // variable. | |
| 1435 if (inferredTypes[i].isBottom || | |
| 1436 !isSubtypeOf(inferredTypes[i], | |
| 1437 bound.upper.substitute2(inferredTypes, fnTypeParams)) || | |
| 1438 !isSubtypeOf(bound.lower.substitute2(inferredTypes, fnTypeParams), | |
| 1439 inferredTypes[i])) { | |
| 1440 // Inference failed. Bail. | 1432 // Inference failed. Bail. |
| 1441 return null; | 1433 return null; |
| 1442 } | 1434 } |
| 1443 } | 1435 } |
| 1444 | 1436 |
| 1445 // Return the instantiated type. | 1437 // Return the instantiated type. |
| 1446 return fnType.instantiate(inferredTypes); | 1438 return fnType.instantiate(inferredTypes); |
| 1447 } | 1439 } |
| 1448 | 1440 |
| 1449 @override | 1441 @override |
| (...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1689 } | 1681 } |
| 1690 | 1682 |
| 1691 bool _isBottom(DartType t, {bool dynamicIsBottom: false}) { | 1683 bool _isBottom(DartType t, {bool dynamicIsBottom: false}) { |
| 1692 return (t.isDynamic && dynamicIsBottom) || t.isBottom; | 1684 return (t.isDynamic && dynamicIsBottom) || t.isBottom; |
| 1693 } | 1685 } |
| 1694 | 1686 |
| 1695 bool _isTop(DartType t, {bool dynamicIsBottom: false}) { | 1687 bool _isTop(DartType t, {bool dynamicIsBottom: false}) { |
| 1696 // TODO(leafp): Document the rules in play here | 1688 // TODO(leafp): Document the rules in play here |
| 1697 return (t.isDynamic && !dynamicIsBottom) || t.isObject; | 1689 return (t.isDynamic && !dynamicIsBottom) || t.isObject; |
| 1698 } | 1690 } |
| OLD | NEW |