@@ -3390,6 +3390,12 @@ bool AllowTypeOrInstanceMemberFailure::diagnoseAsError() {
3390
3390
return true ;
3391
3391
}
3392
3392
3393
+ auto getRootExpr = [&cs](Expr *expr) {
3394
+ while (auto parent = cs.getParentExpr (expr))
3395
+ expr = parent;
3396
+ return expr;
3397
+ };
3398
+
3393
3399
Expr *expr = findParentExpr (getAnchor ());
3394
3400
SourceRange baseRange = expr ? expr->getSourceRange () : SourceRange ();
3395
3401
@@ -3440,12 +3446,6 @@ bool AllowTypeOrInstanceMemberFailure::diagnoseAsError() {
3440
3446
return true ;
3441
3447
};
3442
3448
3443
- auto getRootExpr = [&cs](Expr *expr) {
3444
- while (auto parent = cs.getParentExpr (expr))
3445
- expr = parent;
3446
- return expr;
3447
- };
3448
-
3449
3449
auto *baseLoc = cs.getConstraintLocator (ctorRef->getBase ());
3450
3450
if (auto selection = getChoiceFor (baseLoc)) {
3451
3451
OverloadChoice choice = selection->choice ;
@@ -3637,7 +3637,7 @@ bool AllowTypeOrInstanceMemberFailure::diagnoseAsError() {
3637
3637
Type contextualType;
3638
3638
for (auto iterateCS = &cs; contextualType.isNull () && iterateCS;
3639
3639
iterateCS = iterateCS->baseCS ) {
3640
- contextualType = iterateCS->getContextualType (expr );
3640
+ contextualType = iterateCS->getContextualType (getRawAnchor () );
3641
3641
}
3642
3642
3643
3643
// Try to provide a fix-it that only contains a '.'
@@ -3648,7 +3648,7 @@ bool AllowTypeOrInstanceMemberFailure::diagnoseAsError() {
3648
3648
3649
3649
// Check if the expression is the matching operator ~=, most often used in
3650
3650
// case statements. If so, try to provide a single dot fix-it
3651
- const Expr *contextualTypeNode = getAnchor ();
3651
+ const Expr *contextualTypeNode = getRootExpr ( getAnchor () );
3652
3652
ConstraintSystem *lastCS = nullptr ;
3653
3653
for (auto iterateCS = &cs; iterateCS; iterateCS = iterateCS->baseCS ) {
3654
3654
lastCS = iterateCS;
0 commit comments