Skip to content

Commit 7ce8a44

Browse files
committed
[CSSimplify] Increase fix impact when passing closure to a non-function type parameter
In overloaded context it's possible that there is an overload that expects a closure but it can have other issues e.g. different number of parameters, so in order to pick a better solution let's always increase a score for overloads where closure is matched against a non-function type parameter.
1 parent bd010c3 commit 7ce8a44

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

lib/Sema/CSSimplify.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11393,6 +11393,16 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyFixConstraint(
1139311393
}))
1139411394
impact += 3;
1139511395

11396+
// Passing a closure to a parameter that doesn't expect one should
11397+
// be scored lower because there might be an overload that expects
11398+
// a closure but has other issues e.g. wrong number of parameters.
11399+
if (!type2->lookThroughAllOptionalTypes()->is<FunctionType>()) {
11400+
auto argument = simplifyLocatorToAnchor(fix->getLocator());
11401+
if (isExpr<ClosureExpr>(argument)) {
11402+
impact += 2;
11403+
}
11404+
}
11405+
1139611406
return recordFix(fix, impact) ? SolutionKind::Error : SolutionKind::Solved;
1139711407
}
1139811408

0 commit comments

Comments
 (0)