mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
Merge pull request #18484 from xedin/diag-req-failures-via-fixes
[ConstraintSystem] Diagnose missing conformance requirements via "fixes"
This commit is contained in:
@@ -2766,6 +2766,28 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyConformsToConstraint(
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
// If this is a generic requirement let's try to record that
|
||||
// conformance is missing and consider this a success, which
|
||||
// makes it much easier to diagnose problems like that.
|
||||
{
|
||||
SmallVector<LocatorPathElt, 4> path;
|
||||
auto *anchor = locator.getLocatorParts(path);
|
||||
|
||||
if (!path.empty() && path.back().getKind() ==
|
||||
ConstraintLocator::PathElementKind::TypeParameterRequirement) {
|
||||
auto typeRequirement = path.back();
|
||||
std::pair<Expr *, unsigned> reqLoc = {anchor, typeRequirement.getValue()};
|
||||
MissingConformances[reqLoc] = {type.getPointer(), protocol};
|
||||
// Let's strip all of the unnecessary information from locator,
|
||||
// diagnostics only care about anchor - to lookup type,
|
||||
// and what was the requirement# which is not satisfied.
|
||||
ConstraintLocatorBuilder requirement(getConstraintLocator(anchor));
|
||||
if (!recordFix({FixKind::AddConformance},
|
||||
requirement.withPathElement(typeRequirement)))
|
||||
return SolutionKind::Solved;
|
||||
}
|
||||
}
|
||||
|
||||
// There's nothing more we can do; fail.
|
||||
return SolutionKind::Error;
|
||||
@@ -5004,6 +5026,7 @@ ConstraintSystem::simplifyFixConstraint(Fix fix, Type type1, Type type2,
|
||||
case FixKind::ExplicitlyEscapingToAny:
|
||||
case FixKind::CoerceToCheckedCast:
|
||||
case FixKind::RelabelArguments:
|
||||
case FixKind::AddConformance:
|
||||
llvm_unreachable("handled elsewhere");
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user