[CSClosure] Initial support for multi-statement closures

Implement constraint generation for brace statements and
refactor closure contraint generation to accept multi-statement
closures.
This commit is contained in:
Pavel Yaskevich
2021-07-22 13:23:08 -07:00
parent 28d1bacdce
commit 91eecdb6d0
2 changed files with 164 additions and 29 deletions

View File

@@ -9132,26 +9132,8 @@ bool ConstraintSystem::resolveClosure(TypeVariableType *typeVar,
}
}
// If this closure should be type-checked as part of this expression,
// generate constraints for it now.
auto &ctx = getASTContext();
if (shouldTypeCheckInEnclosingExpression(closure)) {
if (generateConstraints(closure))
return false;
} else if (!hasExplicitResult(closure)) {
// If this closure has an empty body and no explicit result type
// let's bind result type to `Void` since that's the only type empty body
// can produce. Otherwise, if (multi-statement) closure doesn't have
// an explicit result (no `return` statements) let's default it to `Void`.
auto constraintKind = (closure->hasEmptyBody() && !closure->hasExplicitResultType())
? ConstraintKind::Bind
: ConstraintKind::Defaultable;
addConstraint(
constraintKind, inferredClosureType->getResult(), ctx.TheEmptyTupleType,
getConstraintLocator(closure, ConstraintLocator::ClosureResult));
}
return true;
// Generate constraints from the body of this closure.
return !generateConstraints(closure);
}
ConstraintSystem::SolutionKind