Skip to content

Commit bbc6ed8

Browse files
committed
[CSSimplify] Produce tailored fixes for a few generic argument mismatches
- Mismatch in tuple element position should reference whole tuple with a note for mismatch position; - Situations where optional object type is not a class but matched against `AnyObject` have a tailored fix. (cherry picked from commit 7305275)
1 parent f67687b commit bbc6ed8

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

lib/Sema/CSSimplify.cpp

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6942,12 +6942,19 @@ bool ConstraintSystem::repairFailures(
69426942
path.pop_back();
69436943

69446944
ConstraintFix *fix = nullptr;
6945-
if (!path.empty() && path.back().is<LocatorPathElt::AnyRequirement>()) {
6945+
auto *fixLoc = getConstraintLocator(anchor, path);
6946+
6947+
if (fixLoc->isLastElement<LocatorPathElt::AnyRequirement>()) {
69466948
fix = fixRequirementFailure(*this, fromType, toType, anchor, path);
6949+
} else if (fixLoc->isLastElement<LocatorPathElt::TupleElement>()) {
6950+
return repairFailures(lhs, rhs, matchKind, flags, conversionsOrFixes,
6951+
fixLoc);
6952+
} else if (!lhs->mayHaveSuperclass() && rhs->isAnyObject()) {
6953+
fix = AllowNonClassTypeToConvertToAnyObject::create(*this, fromType,
6954+
fixLoc);
69476955
} else {
69486956
fix = GenericArgumentsMismatch::create(
6949-
*this, fromType, toType, {genericArgElt.getIndex()},
6950-
getConstraintLocator(anchor, path));
6957+
*this, fromType, toType, {genericArgElt.getIndex()}, fixLoc);
69516958
}
69526959

69536960
if (!fix)
@@ -15684,7 +15691,8 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyFixConstraint(
1568415691
case FixKind::AllowFunctionSpecialization:
1568515692
case FixKind::IgnoreGenericSpecializationArityMismatch:
1568615693
case FixKind::IgnoreKeyPathSubscriptIndexMismatch:
15687-
case FixKind::AllowMemberRefOnExistential: {
15694+
case FixKind::AllowMemberRefOnExistential:
15695+
case FixKind::AllowNonClassTypeToConvertToAnyObject: {
1568815696
return recordFix(fix) ? SolutionKind::Error : SolutionKind::Solved;
1568915697
}
1569015698

@@ -15935,7 +15943,6 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyFixConstraint(
1593515943
case FixKind::DefaultGenericArgument:
1593615944
case FixKind::AllowMutatingMemberOnRValueBase:
1593715945
case FixKind::AllowTupleSplatForSingleParameter:
15938-
case FixKind::AllowNonClassTypeToConvertToAnyObject:
1593915946
case FixKind::SpecifyClosureParameterType:
1594015947
case FixKind::SpecifyClosureReturnType:
1594115948
case FixKind::AddQualifierToAccessTopLevelName:

0 commit comments

Comments
 (0)