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