[ConstraintSystem] Adjust impact of a missing member fix

Currently its impact is set to be less than that of a conversion fix,
which is incorrect. Let's adjust that and increase it even farther for
cases where base is `Any` or `AnyObject`. We couldn't do it for `Any`
before because it was used to represent type holes, but it's no longer
the case.

Resolves: rdar://problem/68155466
This commit is contained in:
Pavel Yaskevich
2020-09-09 10:33:26 -07:00
parent 2e03264ce3
commit 7b0e46bdfa
2 changed files with 36 additions and 7 deletions

View File

@@ -7168,18 +7168,19 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyMemberConstraint(
MemberLookupResult::ErrorAlreadyDiagnosed);
auto *fix = DefineMemberBasedOnUse::create(*this, baseTy, member,
alreadyDiagnosed, locator);
// Impact is higher if the base is expected to be inferred from context,
// because a failure to find a member ultimately means that base type is
// not a match in this case.
auto impact =
locator->findLast<LocatorPathElt::UnresolvedMember>() ? 2 : 1;
auto instanceTy = baseObjTy->getMetatypeInstanceType();
auto impact = 2;
// Impact is higher if the the base type is any function type
// because function types can't have any members other than self
if (baseObjTy->is<AnyFunctionType>()) {
impact += 10;
if (instanceTy->is<AnyFunctionType>()) {
impact += 10;
}
if (instanceTy->isAny() || instanceTy->isAnyObject())
impact += 5;
if (recordFix(fix, impact))
return SolutionKind::Error;