@@ -1225,21 +1225,28 @@ ASTNode InvalidCoercionFailure::getAnchor() const {
12251225 return anchor;
12261226}
12271227
1228+ SourceLoc InvalidCoercionFailure::getLoc () const {
1229+ if (getLocator ()->isForCoercion ()) {
1230+ auto *CE = castToExpr<CoerceExpr>(getRawAnchor ());
1231+ return CE->getAsLoc ();
1232+ }
1233+ return FailureDiagnostic::getLoc ();
1234+ }
1235+
12281236bool InvalidCoercionFailure::diagnoseAsError () {
12291237 auto fromType = getFromType ();
12301238 auto toType = getToType ();
1231- auto *CE = getAsExpr<CoerceExpr>(getRawAnchor ());
12321239
12331240 emitDiagnostic (diag::cannot_coerce_to_type, fromType, toType);
12341241
12351242 if (UseConditionalCast) {
12361243 emitDiagnostic (diag::missing_optional_downcast)
1237- .highlight (CE-> getSourceRange ())
1238- .fixItReplace (CE-> getAsLoc (), " as?" );
1244+ .highlight (getSourceRange ())
1245+ .fixItReplace (getLoc (), " as?" );
12391246 } else {
12401247 emitDiagnostic (diag::missing_forced_downcast)
1241- .highlight (CE-> getSourceRange ())
1242- .fixItReplace (CE-> getAsLoc (), " as!" );
1248+ .highlight (getSourceRange ())
1249+ .fixItReplace (getLoc (), " as!" );
12431250 }
12441251
12451252 return true ;
@@ -2662,7 +2669,7 @@ bool ContextualFailure::diagnoseAsError() {
26622669}
26632670
26642671bool ContextualFailure::diagnoseAsNote () {
2665- auto *locator = getAmbiguityLocator ();
2672+ auto *locator = getLocator ();
26662673
26672674 auto overload = getCalleeOverloadChoiceIfAvailable (locator);
26682675 if (!(overload && overload->choice .isDecl ()))
@@ -4931,7 +4938,7 @@ bool MissingArgumentsFailure::diagnoseAsError() {
49314938}
49324939
49334940bool MissingArgumentsFailure::diagnoseAsNote () {
4934- auto *locator = getAmbiguityLocator ();
4941+ auto *locator = getLocator ();
49354942 if (auto overload = getCalleeOverloadChoiceIfAvailable (locator)) {
49364943 auto *fn = resolveType (overload->adjustedOpenedType )->getAs <AnyFunctionType>();
49374944 auto loc = overload->choice .getDecl ()->getLoc ();
@@ -5733,16 +5740,16 @@ bool ExtraneousArgumentsFailure::diagnoseAsError() {
57335740}
57345741
57355742bool ExtraneousArgumentsFailure::diagnoseAsNote () {
5736- auto overload = getCalleeOverloadChoiceIfAvailable (getAmbiguityLocator ());
5743+ auto overload = getCalleeOverloadChoiceIfAvailable (getLocator ());
57375744 if (!(overload && overload->choice .isDecl ()))
57385745 return false ;
57395746
57405747 auto *decl = overload->choice .getDecl ();
57415748 auto numArgs = getTotalNumArguments ();
57425749 if (isExpr<ClosureExpr>(getAnchor ())) {
57435750 emitDiagnosticAt (decl, diag::candidate_with_extraneous_args_closure,
5744- ContextualType, ContextualType->getNumParams (), numArgs,
5745- (numArgs == 1 ));
5751+ ContextualType, ContextualType->getNumParams (), numArgs,
5752+ (numArgs == 1 ));
57465753 } else {
57475754 emitDiagnosticAt (decl, diag::candidate_with_extraneous_args,
57485755 overload->adjustedOpenedType , numArgs, ContextualType,
0 commit comments