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