[ConstraintSystem] Default generic parameters associated with missing member to Any

As part of the `DefineBasedOnUse` fix introduced in places where
there is a reference to non-existent member, let's also add
constraints which allow to default any generic parameters found
in base type to `Any`.
This commit is contained in:
Pavel Yaskevich
2019-05-29 14:58:45 -07:00
parent 44536fe2e0
commit 636b4ceeb2

View File

@@ -4751,6 +4751,19 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyMemberConstraint(
// Since member with given base and name doesn't exist, let's try to
// fake its presence based on use, that makes it possible to diagnose
// problems related to member lookup more precisely.
origBaseTy.transform([&](Type type) -> Type {
if (auto *typeVar = type->getAs<TypeVariableType>()) {
if (typeVar->getImpl().hasRepresentativeOrFixed())
return type;
// Default all of the generic parameters found in base to `Any`.
addConstraint(ConstraintKind::Defaultable, typeVar,
getASTContext().TheAnyType,
typeVar->getImpl().getLocator());
}
return type;
});
auto *fix =
DefineMemberBasedOnUse::create(*this, origBaseTy, member, locator);
if (recordFix(fix))