[Sema] Do not skip key path last component/value equal constraint failure fix

This commit is contained in:
Luciano Almeida
2021-03-21 18:29:47 -03:00
parent 891e053b65
commit 0bca6ce73c
3 changed files with 41 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();