@@ -12201,7 +12201,6 @@ ConstraintSystem::simplifyKeyPathConstraint(
1220112201 // The constraint ought to have been anchored on a KeyPathExpr.
1220212202 auto keyPath = castToExpr<KeyPathExpr>(locator.getAnchor());
1220312203 keyPathTy = getFixedTypeRecursive(keyPathTy, /*want rvalue*/ true);
12204- bool resolveAsMultiArgFuncFix = false;
1220512204
1220612205 auto formUnsolved = [&]() -> SolutionKind {
1220712206 if (flags.contains(TMF_GenerateConstraints)) {
@@ -12232,17 +12231,7 @@ ConstraintSystem::simplifyKeyPathConstraint(
1223212231 }
1223312232
1223412233 if (auto fnTy = type->getAs<FunctionType>()) {
12235- if (fnTy->getParams().size() != 1) {
12236- if (!shouldAttemptFixes())
12237- return false;
12238-
12239- resolveAsMultiArgFuncFix = true;
12240- auto *fix = AllowMultiArgFuncKeyPathMismatch::create(
12241- *this, fnTy, getConstraintLocator(locator));
12242- // Pretend the keypath type got resolved and move on.
12243- return !recordFix(fix);
12244- }
12245-
12234+ assert(fnTy->getParams().size() == 1);
1224612235 // Match up the root and value types to the function's param and return
1224712236 // types. Note that we're using the type of the parameter as referenced
1224812237 // from inside the function body as we'll be transforming the code into:
@@ -12276,6 +12265,23 @@ ConstraintSystem::simplifyKeyPathConstraint(
1227612265 return true;
1227712266 };
1227812267
12268+ // If key path has to be converted to a function, let's check that
12269+ // the contextual type has precisely one parameter.
12270+ if (auto *fnTy = keyPathTy->getAs<FunctionType>()) {
12271+ if (fnTy->getParams().size() != 1) {
12272+ if (!shouldAttemptFixes())
12273+ return SolutionKind::Error;
12274+
12275+ recordAnyTypeVarAsPotentialHole(rootTy);
12276+ recordAnyTypeVarAsPotentialHole(valueTy);
12277+
12278+ auto *fix = AllowMultiArgFuncKeyPathMismatch::create(
12279+ *this, fnTy, getConstraintLocator(locator));
12280+ // Pretend the keypath type got resolved and move on.
12281+ return recordFix(fix) ? SolutionKind::Error : SolutionKind::Solved;
12282+ }
12283+ }
12284+
1227912285 // If we have a hole somewhere in the key path, the solver won't be able to
1228012286 // infer the key path type. So let's just assume this is solved.
1228112287 if (shouldAttemptFixes()) {
@@ -12297,10 +12303,6 @@ ConstraintSystem::simplifyKeyPathConstraint(
1229712303 if (!tryMatchRootAndValueFromType(keyPathTy))
1229812304 return SolutionKind::Error;
1229912305
12300- // If we fix this keypath as `AllowMultiArgFuncKeyPathMismatch`, just proceed
12301- if (resolveAsMultiArgFuncFix)
12302- return SolutionKind::Solved;
12303-
1230412306 bool isValid;
1230512307 llvm::Optional<KeyPathCapability> capability;
1230612308
0 commit comments