Skip to content

Commit e50537d

Browse files
committed
[CSApply] Handle @autoclosure arg/param conversions in Swift versions < 5
Since it was allowed to pass function types to @autoclosure parameters in Swift versions < 5, it has to be handled as a regular function coversion by `coerceToType`.
1 parent 6c8513f commit e50537d

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

lib/Sema/CSApply.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5639,12 +5639,20 @@ Expr *ExprRewriter::coerceCallArguments(
56395639
continue;
56405640
}
56415641

5642-
Expr *convertedArg = nullptr;
5642+
auto isAutoClosureArg = [](Expr *arg) -> bool {
5643+
if (auto *DRE = dyn_cast<DeclRefExpr>(arg)) {
5644+
if (auto *PD = dyn_cast<ParamDecl>(DRE->getDecl()))
5645+
return PD->isAutoClosure();
5646+
}
5647+
return false;
5648+
};
56435649

5650+
Expr *convertedArg = nullptr;
56445651
// Since it was allowed to pass function types to @autoclosure
56455652
// parameters in Swift versions < 5, it has to be handled as
56465653
// a regular function coversion by `coerceToType`.
5647-
if (param.isAutoClosure() && !argType->is<FunctionType>()) {
5654+
if (param.isAutoClosure() && (!argType->is<FunctionType>() ||
5655+
!isAutoClosureArg(arg))) {
56485656
// If parameter is an autoclosure, we need to make sure that:
56495657
// - argument type is coerced to parameter result type
56505658
// - impilict autoclosure is created to wrap argument expression

0 commit comments

Comments
 (0)