Skip to content

Commit 636b4ce

Browse files
committed
[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`.
1 parent 44536fe commit 636b4ce

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

lib/Sema/CSSimplify.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4751,6 +4751,19 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyMemberConstraint(
47514751
// Since member with given base and name doesn't exist, let's try to
47524752
// fake its presence based on use, that makes it possible to diagnose
47534753
// problems related to member lookup more precisely.
4754+
4755+
origBaseTy.transform([&](Type type) -> Type {
4756+
if (auto *typeVar = type->getAs<TypeVariableType>()) {
4757+
if (typeVar->getImpl().hasRepresentativeOrFixed())
4758+
return type;
4759+
// Default all of the generic parameters found in base to `Any`.
4760+
addConstraint(ConstraintKind::Defaultable, typeVar,
4761+
getASTContext().TheAnyType,
4762+
typeVar->getImpl().getLocator());
4763+
}
4764+
return type;
4765+
});
4766+
47544767
auto *fix =
47554768
DefineMemberBasedOnUse::create(*this, origBaseTy, member, locator);
47564769
if (recordFix(fix))

0 commit comments

Comments
 (0)