Skip to content

Commit b5dbb69

Browse files
[Sema][SR-14408] Increase the impact of missing member fix when member is on argument position
1 parent 259cf54 commit b5dbb69

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

lib/Sema/CSSimplify.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8251,6 +8251,13 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyMemberConstraint(
82518251
if (instanceTy->isAny() || instanceTy->isAnyObject())
82528252
impact += 5;
82538253

8254+
// Increasing the impact for missing member in any argument position so it
8255+
// doesn't affect situations where there are another fixes involved.
8256+
auto *anchorExpr = getAsExpr(locator->getAnchor());
8257+
if (anchorExpr && isArgumentExpr(anchorExpr)) {
8258+
impact += 5;
8259+
}
8260+
82548261
if (recordFix(fix, impact))
82558262
return SolutionKind::Error;
82568263

@@ -8301,7 +8308,7 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyMemberConstraint(
83018308
functionRefKind, locator,
83028309
/*includeInaccessibleMembers*/ true);
83038310

8304-
// If uwrapped type still couldn't find anything for a given name,
8311+
// If unwrapped type still couldn't find anything for a given name,
83058312
// let's fallback to a "not such member" fix.
83068313
if (result.ViableCandidates.empty() && result.UnviableCandidates.empty())
83078314
return fixMissingMember(origBaseTy, memberTy, locator);

lib/Sema/ConstraintSystem.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4934,6 +4934,15 @@ ConstraintSystem::isArgumentExpr(Expr *expr) {
49344934
return None;
49354935
}
49364936

4937+
// Specifically for unresolved member expr getParentExpr returns a chain
4938+
// result expr as its immediate parent, so let's look one level up on AST.
4939+
if (auto *URMCR = getAsExpr<UnresolvedMemberChainResultExpr>(argList)) {
4940+
argList = getParentExpr(URMCR);
4941+
if (!argList) {
4942+
return None;
4943+
}
4944+
}
4945+
49374946
if (isa<ParenExpr>(argList)) {
49384947
for (;;) {
49394948
auto *parent = getParentExpr(argList);

0 commit comments

Comments
 (0)