Merge pull request #36531 from LucianoPAlmeida/SR-14096-kp-as-fn

[Sema][SR-14096] Change conditions in which key path component mismatch fix are diagnosed
This commit is contained in:
Pavel Yaskevich
2021-03-22 10:42:08 -07:00
committed by GitHub
4 changed files with 58 additions and 4 deletions

View File

@@ -3795,10 +3795,13 @@ bool ConstraintSystem::repairFailures(
// there is going to be a constraint to match result of the
// member lookup to the generic parameter `V` of *KeyPath<R, V>
// type associated with key path expression, which we need to
// fix-up here.
if (isExpr<KeyPathExpr>(anchor)) {
auto *fnType = lhs->getAs<FunctionType>();
if (fnType && fnType->getResult()->isEqual(rhs))
// fix-up here unless last component has already a invalid type or
// instance fix recorded.
if (auto *kpExpr = getAsExpr<KeyPathExpr>(anchor)) {
auto i = kpExpr->getComponents().size() - 1;
auto lastCompLoc = getConstraintLocator(
locator.withPathElement(LocatorPathElt::KeyPathComponent(i)));
if (hasFixFor(lastCompLoc, FixKind::AllowTypeOrInstanceMember))
return true;
auto lastComponentType = lhs->lookThroughAllOptionalTypes();