@@ -12201,7 +12201,6 @@ ConstraintSystem::simplifyKeyPathConstraint(
12201
12201
// The constraint ought to have been anchored on a KeyPathExpr.
12202
12202
auto keyPath = castToExpr<KeyPathExpr>(locator.getAnchor());
12203
12203
keyPathTy = getFixedTypeRecursive(keyPathTy, /*want rvalue*/ true);
12204
- bool resolveAsMultiArgFuncFix = false;
12205
12204
12206
12205
auto formUnsolved = [&]() -> SolutionKind {
12207
12206
if (flags.contains(TMF_GenerateConstraints)) {
@@ -12232,17 +12231,7 @@ ConstraintSystem::simplifyKeyPathConstraint(
12232
12231
}
12233
12232
12234
12233
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);
12246
12235
// Match up the root and value types to the function's param and return
12247
12236
// types. Note that we're using the type of the parameter as referenced
12248
12237
// from inside the function body as we'll be transforming the code into:
@@ -12276,6 +12265,23 @@ ConstraintSystem::simplifyKeyPathConstraint(
12276
12265
return true;
12277
12266
};
12278
12267
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
+
12279
12285
// If we have a hole somewhere in the key path, the solver won't be able to
12280
12286
// infer the key path type. So let's just assume this is solved.
12281
12287
if (shouldAttemptFixes()) {
@@ -12297,10 +12303,6 @@ ConstraintSystem::simplifyKeyPathConstraint(
12297
12303
if (!tryMatchRootAndValueFromType(keyPathTy))
12298
12304
return SolutionKind::Error;
12299
12305
12300
- // If we fix this keypath as `AllowMultiArgFuncKeyPathMismatch`, just proceed
12301
- if (resolveAsMultiArgFuncFix)
12302
- return SolutionKind::Solved;
12303
-
12304
12306
bool isValid;
12305
12307
llvm::Optional<KeyPathCapability> capability;
12306
12308
0 commit comments