Skip to content

Commit c6ef596

Browse files
committed
[Sema] Don't crash in matchCallArguments if autoclosure type is not a function type
During code completion, the function type may be a placeholder type. Don't crash in those cases.
1 parent d082ebb commit c6ef596

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

lib/Sema/CSSimplify.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1815,7 +1815,6 @@ static ConstraintSystem::TypeMatchResult matchCallArguments(
18151815
auto *argExpr = getArgumentExpr(locator.getAnchor(), argIdx);
18161816
if (param.isAutoClosure() && !isSynthesizedArgument(argument)) {
18171817
auto &ctx = cs.getASTContext();
1818-
auto *fnType = paramTy->castTo<FunctionType>();
18191818

18201819
// If this is a call to a function with a closure argument and the
18211820
// parameter is an autoclosure, let's just increment the score here
@@ -1835,7 +1834,9 @@ static ConstraintSystem::TypeMatchResult matchCallArguments(
18351834
if (ctx.isSwiftVersionAtLeast(5) || !isAutoClosureArgument(argExpr)) {
18361835
// In Swift >= 5 mode there is no @autoclosure forwarding,
18371836
// so let's match result types.
1838-
paramTy = fnType->getResult();
1837+
if (auto *fnType = paramTy->getAs<FunctionType>()) {
1838+
paramTy = fnType->getResult();
1839+
}
18391840
} else {
18401841
// Matching @autoclosure argument to @autoclosure parameter
18411842
// directly would mean introducting a function conversion

0 commit comments

Comments
 (0)