Skip to content

Commit 8c18dec

Browse files
committed
[CSSimplify] Adjust impact assessment of l-value mismatch based on member settability
Increases the default score of the `treat r-value as l-value` and decrease the impact if the immediate member is settable because that means that the problem is somewhere in the "base".
1 parent 3497287 commit 8c18dec

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

lib/Sema/CSSimplify.cpp

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14190,8 +14190,26 @@ ConstraintSystem::simplifyLValueObjectConstraint(
1419014190
if (!shouldAttemptFixes())
1419114191
return SolutionKind::Error;
1419214192

14193+
auto assessImpact = [&]() -> unsigned {
14194+
// If this is a projection of a member reference
14195+
// let's check whether the member is unconditionally
14196+
// settable, if so than it's a problem with its base.
14197+
if (locator.directlyAt<UnresolvedDotExpr>()) {
14198+
auto *memberLoc = getConstraintLocator(locator.getAnchor(),
14199+
ConstraintLocator::Member);
14200+
if (auto selected = findSelectedOverloadFor(memberLoc)) {
14201+
if (auto *storage = dyn_cast_or_null<AbstractStorageDecl>(
14202+
selected->choice.getDeclOrNull())) {
14203+
return storage->isSettable(nullptr) ? 1 : 2;
14204+
}
14205+
}
14206+
}
14207+
return 2;
14208+
};
14209+
1419314210
if (recordFix(
14194-
TreatRValueAsLValue::create(*this, getConstraintLocator(locator))))
14211+
TreatRValueAsLValue::create(*this, getConstraintLocator(locator)),
14212+
assessImpact()))
1419514213
return SolutionKind::Error;
1419614214

1419714215
lvalueTy = LValueType::get(lvalueTy);

0 commit comments

Comments
 (0)