[CS] Extract the check into a separate lambda

This commit is contained in:
Suyash Srijan
2019-08-27 22:54:02 +01:00
parent 06607644f2
commit b33c5208c1

View File

@@ -2189,31 +2189,31 @@ void ConstraintSystem::resolveOverload(ConstraintLocator *locator,
openedFullType,
refType};
// If we have something like '(s.foo)()', where 's.foo()' returns an IUO,
// then we need to only create a single constraint that binds the
// type to an optional.
auto isIUOCallWrappedInParens = [&]() {
auto paren = getParentExpr(locator->getAnchor());
auto call = getParentExpr(paren);
if (call && isa<CallExpr>(call)) {
auto callExpr = cast<CallExpr>(call);
if (callExpr->getFn() != callExpr->getSemanticFn()) {
return true;
}
}
return false;
};
// In some cases we already created the appropriate bind constraints.
if (!bindConstraintCreated) {
if (choice.isImplicitlyUnwrappedValueOrReturnValue()) {
if (choice.isImplicitlyUnwrappedValueOrReturnValue() &&
!isIUOCallWrappedInParens()) {
// Build the disjunction to attempt binding both T? and T (or
// function returning T? and function returning T).
// If we have something like '(s.foo)()', where 's.foo()' returns an IUO,
// then we need to only create a single constraint that binds the
// type to an optional.
auto createdSingleConstraint = false;
auto paren = getParentExpr(locator->getAnchor());
auto call = getParentExpr(paren);
if (call && isa<CallExpr>(call)) {
auto callExpr = cast<CallExpr>(call);
if (callExpr->getFn() != callExpr->getSemanticFn()) {
addConstraint(ConstraintKind::Bind, boundType, refType, locator);
createdSingleConstraint = true;
}
}
if (!createdSingleConstraint) {
buildDisjunctionForImplicitlyUnwrappedOptional(boundType, refType,
locator);
}
buildDisjunctionForImplicitlyUnwrappedOptional(boundType, refType,
locator);
} else {
// Add the type binding constraint.
addConstraint(ConstraintKind::Bind, boundType, refType, locator);