Skip to content

Commit 7877c07

Browse files
committed
[CSGen] Fix one last incorrect key path locator use
Optional chaining is related to the key path value and not the key path type itself.
1 parent 7812f5e commit 7877c07

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

lib/Sema/CSGen.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3853,7 +3853,10 @@ namespace {
38533853
// constraint system so we can find it later.
38543854
CS.setType(E, i, base);
38553855
}
3856-
3856+
3857+
auto valueLocator =
3858+
CS.getConstraintLocator(E, ConstraintLocator::KeyPathValue);
3859+
38573860
// If there was an optional chaining component, the end result must be
38583861
// optional.
38593862
if (didOptionalChain) {
@@ -3862,8 +3865,7 @@ namespace {
38623865
componentTypeVars.push_back(objTy);
38633866

38643867
auto optTy = OptionalType::get(objTy);
3865-
CS.addConstraint(ConstraintKind::Conversion, base, optTy,
3866-
locator);
3868+
CS.addConstraint(ConstraintKind::Conversion, base, optTy, valueLocator);
38673869
base = optTy;
38683870
}
38693871

@@ -3873,8 +3875,7 @@ namespace {
38733875
(void)CS.recordFix(AllowKeyPathWithoutComponents::create(CS, locator));
38743876
}
38753877

3876-
auto valueLocator =
3877-
CS.getConstraintLocator(E, ConstraintLocator::KeyPathValue);
3878+
38783879
auto *value = CS.createTypeVariable(valueLocator, TVO_CanBindToNoEscape |
38793880
TVO_CanBindToHole);
38803881
CS.addConstraint(ConstraintKind::Equal, base, value, valueLocator);

lib/Sema/CSSimplify.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6675,6 +6675,10 @@ bool ConstraintSystem::repairFailures(
66756675
if (lhs->isTypeVariableOrMember() || rhs->isTypeVariableOrMember())
66766676
break;
66776677

6678+
if (hasConversionOrRestriction(ConversionRestrictionKind::DeepEquality) ||
6679+
hasConversionOrRestriction(ConversionRestrictionKind::ValueToOptional))
6680+
return false;
6681+
66786682
auto kpExpr = castToExpr<KeyPathExpr>(anchor);
66796683
auto i = kpExpr->getComponents().size() - 1;
66806684
auto lastCompLoc =

0 commit comments

Comments
 (0)