@@ -121,10 +121,14 @@ Expr *FailureDiagnostic::getBaseExprFor(Expr *anchor) const {
121
121
return nullptr ;
122
122
}
123
123
124
- Optional<SelectedOverload> FailureDiagnostic::getChoiceFor (Expr *expr) const {
124
+ Optional<SelectedOverload> FailureDiagnostic::getAnchormostChoice () const {
125
+ return getAnchormostChoiceFor (getLocator ());
126
+ }
127
+
128
+ Optional<SelectedOverload>
129
+ FailureDiagnostic::getAnchormostChoiceFor (ConstraintLocator *locator) const {
125
130
auto &cs = getConstraintSystem ();
126
- auto *loc = cs.getConstraintLocator (expr);
127
- return getOverloadChoiceIfAvailable (cs.getAnchormostCalleeLocator (loc));
131
+ return getOverloadChoiceIfAvailable (cs.getAnchormostCalleeLocator (locator));
128
132
}
129
133
130
134
Type FailureDiagnostic::resolveInterfaceType (Type type,
@@ -159,7 +163,8 @@ Type FailureDiagnostic::resolveInterfaceType(Type type,
159
163
}
160
164
161
165
// / Given an apply expr, returns true if it is expected to have a direct callee
162
- // / overload, resolvable using `getChoiceFor`. Otherwise, returns false.
166
+ // / overload, resolvable using `getAnchormostChoiceFor`. Otherwise, returns
167
+ // / false.
163
168
static bool shouldHaveDirectCalleeOverload (const CallExpr *callExpr) {
164
169
auto *fnExpr = callExpr->getDirectCallee ();
165
170
@@ -221,7 +226,7 @@ FailureDiagnostic::getFunctionArgApplyInfo(ConstraintLocator *locator) const {
221
226
222
227
ValueDecl *callee = nullptr ;
223
228
Type rawFnType;
224
- if (auto overload = getChoiceFor (anchor )) {
229
+ if (auto overload = getAnchormostChoiceFor (argLocator )) {
225
230
// If we have resolved an overload for the callee, then use that to get the
226
231
// function type and callee.
227
232
callee = overload->choice .getDeclOrNull ();
@@ -375,7 +380,7 @@ ValueDecl *RequirementFailure::getDeclRef() const {
375
380
if (isFromContextualType ())
376
381
return getAffectedDeclFromType (cs.getContextualType ());
377
382
378
- if (auto overload = getChoiceFor ( getRawAnchor () )) {
383
+ if (auto overload = getAnchormostChoice ( )) {
379
384
// If there is a declaration associated with this
380
385
// failure e.g. an overload choice of the call
381
386
// expression, let's see whether failure is
@@ -747,7 +752,7 @@ bool LabelingFailure::diagnoseAsNote() {
747
752
return " (" + str + " )" ;
748
753
};
749
754
750
- auto selectedOverload = getChoiceFor (anchor );
755
+ auto selectedOverload = getAnchormostChoice ( );
751
756
if (!selectedOverload)
752
757
return false ;
753
758
@@ -3121,8 +3126,8 @@ bool AllowTypeOrInstanceMemberFailure::diagnoseAsError() {
3121
3126
return true ;
3122
3127
};
3123
3128
3124
- auto selection = getChoiceFor (ctorRef->getBase ());
3125
- if (selection) {
3129
+ auto *baseLoc = cs. getConstraintLocator (ctorRef->getBase ());
3130
+ if (auto selection = getAnchormostChoiceFor (baseLoc) ) {
3126
3131
OverloadChoice choice = selection->choice ;
3127
3132
if (choice.isDecl () && isMutable (choice.getDecl ()) &&
3128
3133
!isCallArgument (initCall) &&
@@ -4282,15 +4287,13 @@ bool MutatingMemberRefOnImmutableBase::diagnoseAsError() {
4282
4287
}
4283
4288
4284
4289
bool InvalidTupleSplatWithSingleParameterFailure::diagnoseAsError () {
4285
- auto *anchor = getRawAnchor ();
4286
-
4287
- auto selectedOverload = getChoiceFor (anchor);
4290
+ auto selectedOverload = getAnchormostChoice ();
4288
4291
if (!selectedOverload || !selectedOverload->choice .isDecl ())
4289
4292
return false ;
4290
4293
4291
4294
auto *choice = selectedOverload->choice .getDecl ();
4292
4295
4293
- auto *argExpr = getArgumentExprFor (anchor );
4296
+ auto *argExpr = getArgumentExprFor (getRawAnchor () );
4294
4297
if (!argExpr)
4295
4298
return false ;
4296
4299
0 commit comments