Skip to content

Commit 9509eef

Browse files
committed
[TypeChecker/Constness] Diagnostics: Walk into multi-statement closures when inference is enabled
When multi-statement closure inference is enabled it's body is type-checked together with enclosing context, so they could be walked directly just like single-expressions ones.
1 parent 3555299 commit 9509eef

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

lib/Sema/ConstantnessSemaDiagnostics.cpp

+7-4
Original file line numberDiff line numberDiff line change
@@ -359,10 +359,13 @@ void swift::diagnoseConstantArgumentRequirement(
359359
}
360360

361361
std::pair<bool, Expr *> walkToClosureExprPre(ClosureExpr *closure) {
362-
if (closure->hasSingleExpressionBody()) {
363-
// Single expression closure bodies are not visited directly
364-
// by the ASTVisitor, so we must descend into the body manually
365-
// and set the DeclContext to that of the closure.
362+
auto &ctx = DC->getASTContext();
363+
364+
if (closure->hasSingleExpressionBody() ||
365+
ctx.TypeCheckerOpts.EnableMultiStatementClosureInference) {
366+
// Closure bodies are not visited directly by the ASTVisitor,
367+
// so we must descend into the body manuall and set the
368+
// DeclContext to that of the closure.
366369
DC = closure;
367370
return {true, closure};
368371
}

0 commit comments

Comments
 (0)