[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.
This commit is contained in:
Pavel Yaskevich
2025-06-03 00:36:22 -07:00
parent 27c28d4d64
commit 7305275dbd

View File

@@ -6942,12 +6942,19 @@ bool ConstraintSystem::repairFailures(
path.pop_back();
ConstraintFix *fix = nullptr;
if (!path.empty() && path.back().is<LocatorPathElt::AnyRequirement>()) {
auto *fixLoc = getConstraintLocator(anchor, path);
if (fixLoc->isLastElement<LocatorPathElt::AnyRequirement>()) {
fix = fixRequirementFailure(*this, fromType, toType, anchor, path);
} else if (fixLoc->isLastElement<LocatorPathElt::TupleElement>()) {
return repairFailures(lhs, rhs, matchKind, flags, conversionsOrFixes,
fixLoc);
} else if (!lhs->mayHaveSuperclass() && rhs->isAnyObject()) {
fix = AllowNonClassTypeToConvertToAnyObject::create(*this, fromType,
fixLoc);
} else {
fix = GenericArgumentsMismatch::create(
*this, fromType, toType, {genericArgElt.getIndex()},
getConstraintLocator(anchor, path));
*this, fromType, toType, {genericArgElt.getIndex()}, fixLoc);
}
if (!fix)
@@ -15687,7 +15694,8 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyFixConstraint(
case FixKind::AllowFunctionSpecialization:
case FixKind::IgnoreGenericSpecializationArityMismatch:
case FixKind::IgnoreKeyPathSubscriptIndexMismatch:
case FixKind::AllowMemberRefOnExistential: {
case FixKind::AllowMemberRefOnExistential:
case FixKind::AllowNonClassTypeToConvertToAnyObject: {
return recordFix(fix) ? SolutionKind::Error : SolutionKind::Solved;
}
@@ -15938,7 +15946,6 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyFixConstraint(
case FixKind::DefaultGenericArgument:
case FixKind::AllowMutatingMemberOnRValueBase:
case FixKind::AllowTupleSplatForSingleParameter:
case FixKind::AllowNonClassTypeToConvertToAnyObject:
case FixKind::SpecifyClosureParameterType:
case FixKind::SpecifyClosureReturnType:
case FixKind::AddQualifierToAccessTopLevelName: