mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
Merge pull request #27769 from hborla/anyobject-conformance-failure
[ConstraintSystem] Diagnose missing AnyObject conformance using the MissingConformance constraint fix.
This commit is contained in:
@@ -2015,6 +2015,12 @@ ConstraintSystem::matchExistentialTypes(Type type1, Type type2,
|
||||
if (req &&
|
||||
req->getRequirementKind() == RequirementKind::Superclass)
|
||||
return getTypeMatchSuccess();
|
||||
|
||||
auto *fix = fixRequirementFailure(*this, type1, type2, locator);
|
||||
if (fix && !recordFix(fix)) {
|
||||
recordFixedRequirement(type1, RequirementKind::Layout, type2);
|
||||
return getTypeMatchSuccess();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3437,8 +3443,10 @@ ConstraintSystem::matchTypes(Type type1, Type type2, ConstraintKind kind,
|
||||
if (shouldAttemptFixes()) {
|
||||
auto last = locator.last();
|
||||
// If this happens as part of the argument-to-parameter
|
||||
// conversion, there is a tailored fix/diagnostic.
|
||||
if (last && last->is<LocatorPathElt::ApplyArgToParam>())
|
||||
// conversion or type requirement, there is a tailored
|
||||
// fix/diagnostic.
|
||||
if (last && (last->is<LocatorPathElt::ApplyArgToParam>() ||
|
||||
last->is<LocatorPathElt::AnyRequirement>()))
|
||||
break;
|
||||
}
|
||||
// If two module types or archetypes were not already equal, there's
|
||||
@@ -4339,24 +4347,6 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyConformsToConstraint(
|
||||
if (!shouldAttemptFixes())
|
||||
return SolutionKind::Error;
|
||||
|
||||
// See if there's anything we can do to fix the conformance:
|
||||
if (auto optionalObjectType = type->getOptionalObjectType()) {
|
||||
TypeMatchOptions subflags = getDefaultDecompositionOptions(flags);
|
||||
// The underlying type of an optional may conform to the protocol if the
|
||||
// optional doesn't; suggest forcing if that's the case.
|
||||
auto result = simplifyConformsToConstraint(
|
||||
optionalObjectType, protocol, kind,
|
||||
locator.withPathElement(LocatorPathElt::GenericArgument(0)), subflags);
|
||||
if (result == SolutionKind::Solved) {
|
||||
auto *fix = ForceOptional::create(*this, type, optionalObjectType,
|
||||
getConstraintLocator(locator));
|
||||
if (recordFix(fix)) {
|
||||
return SolutionKind::Error;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
auto protocolTy = protocol->getDeclaredType();
|
||||
// If this conformance has been fixed already, let's just consider this done.
|
||||
if (hasFixedRequirement(type, RequirementKind::Conformance, protocolTy))
|
||||
|
||||
Reference in New Issue
Block a user