[CSSimplify] Detect when generic argument mismatch applies to argument and produce a tailed fix

The problem detection logic currently expects `generic argument #<N>`
location to always be associated with two generic types, but that
is not always the case, this locator element is sometimes used for
i.e. optional object types and pointer `Pointee` type when types
appear in argument positions. This needs to be handled specifically.

Resolves: rdar://82971941
This commit is contained in:
Pavel Yaskevich
2025-05-26 14:31:07 -07:00
parent 10186d664b
commit ded6158cc3
7 changed files with 43 additions and 16 deletions

View File

@@ -6884,9 +6884,28 @@ bool ConstraintSystem::repairFailures(
if (!path.empty() && path.back().is<LocatorPathElt::PackElement>())
path.pop_back();
if (!path.empty() && path.back().is<LocatorPathElt::AnyRequirement>()) {
return repairFailures(lhs, rhs, matchKind, flags, conversionsOrFixes,
getConstraintLocator(anchor, path));
if (!path.empty()) {
if (path.back().is<LocatorPathElt::AnyRequirement>()) {
return repairFailures(lhs, rhs, matchKind, flags, conversionsOrFixes,
getConstraintLocator(anchor, path));
}
if (auto argConv = path.back().getAs<LocatorPathElt::ApplyArgToParam>()) {
auto argIdx = argConv->getArgIdx();
auto paramIdx = argConv->getParamIdx();
auto *argLoc = getConstraintLocator(anchor, path);
if (auto overload = findSelectedOverloadFor(getCalleeLocator(argLoc))) {
auto *overloadTy =
simplifyType(overload->boundType)->castTo<FunctionType>();
auto *argList = getArgumentList(argLoc);
ASSERT(argList);
conversionsOrFixes.push_back(AllowArgumentMismatch::create(
*this, getType(argList->getExpr(argIdx)),
overloadTy->getParams()[paramIdx].getPlainType(), argLoc));
return true;
}
}
}
// When the solver sets `TMF_MatchingGenericArguments` it means