[ConstraintSystem] Add a fix to allow conversion between non-class type and AnyObject

This commit is contained in:
Pavel Yaskevich
2020-01-29 00:06:57 -08:00
parent 1fff12f663
commit b2083db45d
3 changed files with 68 additions and 4 deletions

View File

@@ -1180,3 +1180,40 @@ SpecifyObjectLiteralTypeImport::create(ConstraintSystem &cs,
ConstraintLocator *locator) {
return new (cs.getAllocator()) SpecifyObjectLiteralTypeImport(cs, locator);
}
AllowNonClassTypeToConvertToAnyObject::AllowNonClassTypeToConvertToAnyObject(
ConstraintSystem &cs, Type type, ConstraintLocator *locator)
: ContextualMismatch(cs, FixKind::AllowNonClassTypeToConvertToAnyObject,
type, cs.getASTContext().getAnyObjectType(), locator) {
}
bool AllowNonClassTypeToConvertToAnyObject::diagnose(bool asNote) const {
auto &cs = getConstraintSystem();
auto *locator = getLocator();
if (locator->getPath().empty())
return false;
const auto &last = locator->getPath().back();
switch (last.getKind()) {
case ConstraintLocator::ContextualType: {
ContextualFailure failure(cs, getFromType(), getToType(), locator);
return failure.diagnose(asNote);
}
case ConstraintLocator::ApplyArgToParam: {
ArgumentMismatchFailure failure(cs, getFromType(), getToType(), locator);
return failure.diagnose(asNote);
}
default:
return false;
}
}
AllowNonClassTypeToConvertToAnyObject *
AllowNonClassTypeToConvertToAnyObject::create(ConstraintSystem &cs, Type type,
ConstraintLocator *locator) {
return new (cs.getAllocator())
AllowNonClassTypeToConvertToAnyObject(cs, type, locator);
}