Skip to content

Commit 1cccbc8

Browse files
[CSSimplify] Difavor function type overload when trying to match no arg function type with a closure with a anonimous implicit var closure
1 parent cc4bfe8 commit 1cccbc8

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

lib/Sema/CSSimplify.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1722,6 +1722,21 @@ ConstraintSystem::matchFunctionTypes(FunctionType *func1, FunctionType *func2,
17221722
}
17231723
}
17241724
}
1725+
1726+
// If we have an anonymous closure e.g. { return }
1727+
// trying an ArgumentConversion to generic function param
1728+
// let's disfavor an attempt to match a function type with
1729+
// a generic parameter e.g. (A) -> B. This should ideally
1730+
// only matches types with no param like () -> B otherwise
1731+
// closure should have an explicity type e.g. { _ in return }
1732+
if (kind == ConstraintKind::ArgumentConversion &&
1733+
func1->getParams().empty() && func2->getParams().size() >= 1) {
1734+
auto *anchor = locator.trySimplifyToExpr();
1735+
auto closureExpr = dyn_cast_or_null<ClosureExpr>(anchor);
1736+
if (closureExpr && closureExpr->hasAnonymousClosureVars()) {
1737+
increaseScore(SK_DisfavoredOverload);
1738+
}
1739+
}
17251740

17261741
if (shouldAttemptFixes()) {
17271742
auto *anchor = locator.trySimplifyToExpr();

0 commit comments

Comments
 (0)