Revert "[CSSolver] Use correct locator when matching function result types re…"

This commit is contained in:
Pavel Yaskevich
2018-03-07 23:19:30 -08:00
committed by GitHub
parent c4c5b7130e
commit d8b355dbae
7 changed files with 14 additions and 174 deletions

View File

@@ -1212,8 +1212,10 @@ ConstraintSystem::matchFunctionTypes(FunctionType *func1, FunctionType *func2,
return result;
// Result type can be covariant (or equal).
return matchTypes(func1->getResult(), func2->getResult(), subKind, subflags,
locator.withPathElement(ConstraintLocator::FunctionResult));
return matchTypes(func1->getResult(), func2->getResult(), subKind,
subflags,
locator.withPathElement(
ConstraintLocator::FunctionResult));
}
ConstraintSystem::TypeMatchResult
@@ -1499,8 +1501,6 @@ ConstraintSystem::TypeMatchResult
ConstraintSystem::matchTypes(Type type1, Type type2, ConstraintKind kind,
TypeMatchOptions flags,
ConstraintLocatorBuilder locator) {
auto origType1 = type1;
bool isArgumentTupleConversion
= kind == ConstraintKind::ArgumentTupleConversion ||
kind == ConstraintKind::OperatorArgumentTupleConversion;
@@ -2243,32 +2243,7 @@ ConstraintSystem::matchTypes(Type type1, Type type2, ConstraintKind kind,
// Allow '() -> T' to '() -> ()' and '() -> Never' to '() -> T' for closure
// literals.
if (auto elt = locator.last()) {
auto isClosureResult = [&]() {
if (elt->getKind() == ConstraintLocator::ClosureResult)
return true;
// If constraint is matching function results where
// left-hand side is a 'closure result' we need to allow
// certain implicit conversions.
if (elt->getKind() != ConstraintLocator::FunctionResult)
return false;
if (auto *typeVar = origType1->getAs<TypeVariableType>()) {
auto *locator = typeVar->getImpl().getLocator();
if (!locator)
return false;
auto path = locator->getPath();
if (path.empty())
return false;
return path.back().getKind() == ConstraintLocator::ClosureResult;
}
return false;
};
if (isClosureResult()) {
if (elt->getKind() == ConstraintLocator::ClosureResult) {
if (concrete && kind >= ConstraintKind::Subtype &&
(type1->isUninhabited() || type2->isVoid())) {
increaseScore(SK_FunctionConversion);