@@ -12195,7 +12195,6 @@ ConstraintSystem::simplifyKeyPathConstraint(
12195
12195
// The constraint ought to have been anchored on a KeyPathExpr.
12196
12196
auto keyPath = castToExpr<KeyPathExpr>(locator.getAnchor());
12197
12197
keyPathTy = getFixedTypeRecursive(keyPathTy, /*want rvalue*/ true);
12198
- bool resolveAsMultiArgFuncFix = false;
12199
12198
12200
12199
auto formUnsolved = [&]() -> SolutionKind {
12201
12200
if (flags.contains(TMF_GenerateConstraints)) {
@@ -12226,17 +12225,7 @@ ConstraintSystem::simplifyKeyPathConstraint(
12226
12225
}
12227
12226
12228
12227
if (auto fnTy = type->getAs<FunctionType>()) {
12229
- if (fnTy->getParams().size() != 1) {
12230
- if (!shouldAttemptFixes())
12231
- return false;
12232
-
12233
- resolveAsMultiArgFuncFix = true;
12234
- auto *fix = AllowMultiArgFuncKeyPathMismatch::create(
12235
- *this, fnTy, getConstraintLocator(locator));
12236
- // Pretend the keypath type got resolved and move on.
12237
- return !recordFix(fix);
12238
- }
12239
-
12228
+ assert(fnTy->getParams().size() == 1);
12240
12229
// Match up the root and value types to the function's param and return
12241
12230
// types. Note that we're using the type of the parameter as referenced
12242
12231
// from inside the function body as we'll be transforming the code into:
@@ -12260,6 +12249,23 @@ ConstraintSystem::simplifyKeyPathConstraint(
12260
12249
return true;
12261
12250
};
12262
12251
12252
+ // If key path has to be converted to a function, let's check that
12253
+ // the contextual type has precisely one parameter.
12254
+ if (auto *fnTy = keyPathTy->getAs<FunctionType>()) {
12255
+ if (fnTy->getParams().size() != 1) {
12256
+ if (!shouldAttemptFixes())
12257
+ return SolutionKind::Error;
12258
+
12259
+ recordAnyTypeVarAsPotentialHole(rootTy);
12260
+ recordAnyTypeVarAsPotentialHole(valueTy);
12261
+
12262
+ auto *fix = AllowMultiArgFuncKeyPathMismatch::create(
12263
+ *this, fnTy, getConstraintLocator(locator));
12264
+ // Pretend the keypath type got resolved and move on.
12265
+ return recordFix(fix) ? SolutionKind::Error : SolutionKind::Solved;
12266
+ }
12267
+ }
12268
+
12263
12269
// If we have a hole somewhere in the key path, the solver won't be able to
12264
12270
// infer the key path type. So let's just assume this is solved.
12265
12271
if (shouldAttemptFixes()) {
@@ -12281,10 +12287,6 @@ ConstraintSystem::simplifyKeyPathConstraint(
12281
12287
if (!tryMatchRootAndValueFromType(keyPathTy))
12282
12288
return SolutionKind::Error;
12283
12289
12284
- // If we fix this keypath as `AllowMultiArgFuncKeyPathMismatch`, just proceed
12285
- if (resolveAsMultiArgFuncFix)
12286
- return SolutionKind::Solved;
12287
-
12288
12290
bool isValid;
12289
12291
llvm::Optional<KeyPathCapability> capability;
12290
12292
0 commit comments