mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
[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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user