mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
[Constaint system] Add a predicate for when to check closures in enclosing expr
Introduce a new predicate, shouldTypeCheckInEnclosingExpression(), to determine when the body of a closure should be checked as part of the enclosing expression rather than separately, and use it in the various places where "hasSingleExpressionBody()" was used for that purpose.
This commit is contained in:
@@ -7157,14 +7157,13 @@ bool ConstraintSystem::resolveClosure(TypeVariableType *typeVar,
|
||||
}
|
||||
}
|
||||
|
||||
bool hasReturn = hasExplicitResult(closure);
|
||||
// If this closure should be type-checked as part of this expression,
|
||||
// generate constraints for it now.
|
||||
auto &ctx = getASTContext();
|
||||
// If this is a multi-statement closure its body doesn't participate
|
||||
// in type-checking.
|
||||
if (closure->hasSingleExpressionBody()) {
|
||||
if (shouldTypeCheckInEnclosingExpression(closure)) {
|
||||
if (generateConstraints(closure, closureType->getResult()))
|
||||
return false;
|
||||
} else if (!hasReturn) {
|
||||
} 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
|
||||
|
||||
Reference in New Issue
Block a user