[CS] If locator points to a function call, then compare the fn and semanticFn, otherwise fall back to paren check

This is because otherwise we would have false positives, like 'Foo(Bar())' where Foo's init accepts a non-optional Bar and Bar's init returns an IUO
This commit is contained in:
Suyash Srijan
2019-08-29 01:12:32 +01:00
parent 532498bae5
commit b32386bcac
2 changed files with 19 additions and 3 deletions

View File

@@ -2199,9 +2199,14 @@ void ConstraintSystem::resolveOverload(ConstraintLocator *locator,
if (!type || !type->is<AnyFunctionType>())
return false;
auto paren = getParentExpr(locator->getAnchor());
auto result = paren ? isa<ParenExpr>(paren) : false;
return result;
if (auto call = dyn_cast<CallExpr>(locator->getAnchor()))
return call->getSemanticFn() != call->getFn();
if (auto paren = getParentExpr(locator->getAnchor())) {
return isa<ParenExpr>(paren);
}
return false;
};
// In some cases we already created the appropriate bind constraints.