Skip to content

Commit 7305275

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.
1 parent 27c28d4 commit 7305275

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)
@@ -15687,7 +15694,8 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyFixConstraint(
1568715694
case FixKind::AllowFunctionSpecialization:
1568815695
case FixKind::IgnoreGenericSpecializationArityMismatch:
1568915696
case FixKind::IgnoreKeyPathSubscriptIndexMismatch:
15690-
case FixKind::AllowMemberRefOnExistential: {
15697+
case FixKind::AllowMemberRefOnExistential:
15698+
case FixKind::AllowNonClassTypeToConvertToAnyObject: {
1569115699
return recordFix(fix) ? SolutionKind::Error : SolutionKind::Solved;
1569215700
}
1569315701

@@ -15938,7 +15946,6 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyFixConstraint(
1593815946
case FixKind::DefaultGenericArgument:
1593915947
case FixKind::AllowMutatingMemberOnRValueBase:
1594015948
case FixKind::AllowTupleSplatForSingleParameter:
15941-
case FixKind::AllowNonClassTypeToConvertToAnyObject:
1594215949
case FixKind::SpecifyClosureParameterType:
1594315950
case FixKind::SpecifyClosureReturnType:
1594415951
case FixKind::AddQualifierToAccessTopLevelName:

0 commit comments

Comments
 (0)