mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
[CS] Extract the check into a separate lambda
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user