Skip to content

Commit 1e3484c

Browse files
committed
[Constraint solver] Dig out the root expression as the "contextual node".
1 parent 133439d commit 1e3484c

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

lib/Sema/CSDiagnostics.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3390,6 +3390,12 @@ bool AllowTypeOrInstanceMemberFailure::diagnoseAsError() {
33903390
return true;
33913391
}
33923392

3393+
auto getRootExpr = [&cs](Expr *expr) {
3394+
while (auto parent = cs.getParentExpr(expr))
3395+
expr = parent;
3396+
return expr;
3397+
};
3398+
33933399
Expr *expr = findParentExpr(getAnchor());
33943400
SourceRange baseRange = expr ? expr->getSourceRange() : SourceRange();
33953401

@@ -3440,12 +3446,6 @@ bool AllowTypeOrInstanceMemberFailure::diagnoseAsError() {
34403446
return true;
34413447
};
34423448

3443-
auto getRootExpr = [&cs](Expr *expr) {
3444-
while (auto parent = cs.getParentExpr(expr))
3445-
expr = parent;
3446-
return expr;
3447-
};
3448-
34493449
auto *baseLoc = cs.getConstraintLocator(ctorRef->getBase());
34503450
if (auto selection = getChoiceFor(baseLoc)) {
34513451
OverloadChoice choice = selection->choice;
@@ -3637,7 +3637,7 @@ bool AllowTypeOrInstanceMemberFailure::diagnoseAsError() {
36373637
Type contextualType;
36383638
for (auto iterateCS = &cs; contextualType.isNull() && iterateCS;
36393639
iterateCS = iterateCS->baseCS) {
3640-
contextualType = iterateCS->getContextualType(expr);
3640+
contextualType = iterateCS->getContextualType(getRawAnchor());
36413641
}
36423642

36433643
// Try to provide a fix-it that only contains a '.'
@@ -3648,7 +3648,7 @@ bool AllowTypeOrInstanceMemberFailure::diagnoseAsError() {
36483648

36493649
// Check if the expression is the matching operator ~=, most often used in
36503650
// case statements. If so, try to provide a single dot fix-it
3651-
const Expr *contextualTypeNode = getAnchor();
3651+
const Expr *contextualTypeNode = getRootExpr(getAnchor());
36523652
ConstraintSystem *lastCS = nullptr;
36533653
for (auto iterateCS = &cs; iterateCS; iterateCS = iterateCS->baseCS) {
36543654
lastCS = iterateCS;

0 commit comments

Comments
 (0)