Skip to content

Commit 1190505

Browse files
[CSSimplify] Attempt unwrap optional base fix before root base mismatch on keypath application
1 parent 9924719 commit 1190505

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

lib/Sema/CSSimplify.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3774,6 +3774,14 @@ bool ConstraintSystem::repairFailures(
37743774
}
37753775

37763776
case ConstraintLocator::KeyPathRoot: {
3777+
// The root mismatch is from base U? to U or a subtype of U in keypath
3778+
// application so let's suggest an unwrap the optional fix.
3779+
if (auto unwrapFix = UnwrapOptionalBaseKeyPathApplication::attempt(
3780+
*this, lhs, rhs, getConstraintLocator(locator))) {
3781+
conversionsOrFixes.push_back(unwrapFix);
3782+
break;
3783+
}
3784+
37773785
conversionsOrFixes.push_back(AllowKeyPathRootTypeMismatch::create(
37783786
*this, lhs, rhs, getConstraintLocator(locator)));
37793787

@@ -9742,6 +9750,7 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyFixConstraint(
97429750
case FixKind::CoerceToCheckedCast:
97439751
case FixKind::SpecifyObjectLiteralTypeImport:
97449752
case FixKind::AllowKeyPathRootTypeMismatch:
9753+
case FixKind::UnwrapOptionalBaseKeyPathApplication:
97459754
case FixKind::AllowCoercionToForceCast:
97469755
case FixKind::SpecifyKeyPathRootType: {
97479756
return recordFix(fix) ? SolutionKind::Error : SolutionKind::Solved;

0 commit comments

Comments
 (0)