Skip to content

Commit 8a460aa

Browse files
committed
[CSSimplify] NFC: Extract invalid function type detection from tryMatchRootAndValueFromType
1 parent a8fede4 commit 8a460aa

File tree

1 file changed

+18
-16
lines changed

1 file changed

+18
-16
lines changed

lib/Sema/CSSimplify.cpp

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12195,7 +12195,6 @@ ConstraintSystem::simplifyKeyPathConstraint(
1219512195
// The constraint ought to have been anchored on a KeyPathExpr.
1219612196
auto keyPath = castToExpr<KeyPathExpr>(locator.getAnchor());
1219712197
keyPathTy = getFixedTypeRecursive(keyPathTy, /*want rvalue*/ true);
12198-
bool resolveAsMultiArgFuncFix = false;
1219912198

1220012199
auto formUnsolved = [&]() -> SolutionKind {
1220112200
if (flags.contains(TMF_GenerateConstraints)) {
@@ -12226,17 +12225,7 @@ ConstraintSystem::simplifyKeyPathConstraint(
1222612225
}
1222712226

1222812227
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);
1224012229
// Match up the root and value types to the function's param and return
1224112230
// types. Note that we're using the type of the parameter as referenced
1224212231
// from inside the function body as we'll be transforming the code into:
@@ -12260,6 +12249,23 @@ ConstraintSystem::simplifyKeyPathConstraint(
1226012249
return true;
1226112250
};
1226212251

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+
1226312269
// If we have a hole somewhere in the key path, the solver won't be able to
1226412270
// infer the key path type. So let's just assume this is solved.
1226512271
if (shouldAttemptFixes()) {
@@ -12281,10 +12287,6 @@ ConstraintSystem::simplifyKeyPathConstraint(
1228112287
if (!tryMatchRootAndValueFromType(keyPathTy))
1228212288
return SolutionKind::Error;
1228312289

12284-
// If we fix this keypath as `AllowMultiArgFuncKeyPathMismatch`, just proceed
12285-
if (resolveAsMultiArgFuncFix)
12286-
return SolutionKind::Solved;
12287-
1228812290
bool isValid;
1228912291
llvm::Optional<KeyPathCapability> capability;
1229012292

0 commit comments

Comments
 (0)