[CSSimplify] Increase the score when matching functions with different representations for contextual type

This commit is contained in:
Luciano Almeida
2021-02-28 15:59:17 -03:00
parent 836a81e639
commit f5f7204974
2 changed files with 19 additions and 0 deletions

View File

@@ -2013,6 +2013,16 @@ ConstraintSystem::matchFunctionTypes(FunctionType *func1, FunctionType *func2,
return getTypeMatchFailure(locator);
}
// To contextual type increase the score to avoid ambiguity when solver can
// find more than one viable binding different only in representation e.g.
// let _: (@convention(block) () -> Void)? = Bool.random() ? nil : {}
// so same representation should be always favored.
auto loc = getConstraintLocator(locator);
if (loc->findLast<LocatorPathElt::ContextualType>() &&
func1->getRepresentation() != func2->getRepresentation()) {
increaseScore(SK_FunctionConversion);
}
if (!matchFunctionRepresentations(func1->getExtInfo(), func2->getExtInfo(),
kind, Options)) {
return getTypeMatchFailure(locator);