[ConstraintLocator] Identify whether locator is a result of keypath dynamic member lookup or belongs to keypath subscript component

This commit is contained in:
Pavel Yaskevich
2019-04-07 17:51:23 -07:00
parent c3460f825d
commit 93f9cb1d2a
4 changed files with 39 additions and 50 deletions

View File

@@ -983,21 +983,6 @@ ConstraintSystem::TypeMatchResult constraints::matchCallArguments(
const auto &param = params[paramIdx];
auto paramTy = param.getOldType();
// Each of the index parameters has to conform to Hashable
// to be viable for use as a keypath subscript component.
if (keyPathSubscriptComponent) {
auto *hashable =
cs.getASTContext().getProtocol(KnownProtocolKind::Hashable);
// Standard library might be broken.
if (!hashable)
return cs.getTypeMatchFailure(locator);
cs.addConstraint(
ConstraintKind::ConformsTo, paramTy, hashable->getDeclaredType(),
cs.getConstraintLocator(keyPathSubscriptComponent,
LocatorPathElt::getTupleElement(paramIdx)));
}
if (param.isAutoClosure())
paramTy = paramTy->castTo<FunctionType>()->getResult();
@@ -3159,11 +3144,13 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyConformsToConstraint(
// If this is an implicit Hashable conformance check generated for each
// index argument of the keypath subscript component, we could just treat
// it as though it conforms.
if (auto *component = getAsKeyPathSubscriptComponent(*this, anchor, path)) {
auto *loc = getConstraintLocator(locator);
if (loc->isResultOfKeyPathDynamicMemberLookup() ||
loc->isKeyPathSubscriptComponent()) {
if (protocol ==
getASTContext().getProtocol(KnownProtocolKind::Hashable)) {
auto *fix = TreatKeyPathSubscriptIndexAsHashable::create(*this, type,
component);
auto *fix =
TreatKeyPathSubscriptIndexAsHashable::create(*this, type, loc);
if (!recordFix(fix))
return SolutionKind::Solved;
}