Skip to content

Commit f9e99ed

Browse files
committed
[Diagnostics] NFC: Align diagnoseAsNote with diagnoseAsError for AbstractRawRepresentableFailure
1 parent 4d9566c commit f9e99ed

File tree

1 file changed

+29
-29
lines changed

1 file changed

+29
-29
lines changed

lib/Sema/CSDiagnostics.cpp

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -6279,6 +6279,35 @@ bool AbstractRawRepresentableFailure::diagnoseAsError() {
62796279
return true;
62806280
}
62816281

6282+
bool AbstractRawRepresentableFailure::diagnoseAsNote() {
6283+
auto *locator = getLocator();
6284+
6285+
Optional<InFlightDiagnostic> diagnostic;
6286+
if (locator->isForContextualType()) {
6287+
auto overload = getCalleeOverloadChoiceIfAvailable(locator);
6288+
if (!overload)
6289+
return false;
6290+
6291+
if (auto *decl = overload->choice.getDeclOrNull()) {
6292+
diagnostic.emplace(emitDiagnosticAt(
6293+
decl, diag::cannot_convert_candidate_result_to_contextual_type,
6294+
decl->getName(), ExpectedType, RawReprType));
6295+
}
6296+
} else if (auto argConv =
6297+
locator->getLastElementAs<LocatorPathElt::ApplyArgToParam>()) {
6298+
diagnostic.emplace(
6299+
emitDiagnostic(diag::candidate_has_invalid_argument_at_position,
6300+
RawReprType, argConv->getParamIdx(), /*inOut=*/false));
6301+
}
6302+
6303+
if (diagnostic) {
6304+
fixIt(*diagnostic);
6305+
return true;
6306+
}
6307+
6308+
return false;
6309+
}
6310+
62826311
void MissingRawRepresentativeInitFailure::fixIt(
62836312
InFlightDiagnostic &diagnostic) const {
62846313
if (auto *E = getAsExpr(getAnchor())) {
@@ -6330,35 +6359,6 @@ void MissingRawRepresentativeInitFailure::fixIt(
63306359
}
63316360
}
63326361

6333-
bool AbstractRawRepresentableFailure::diagnoseAsNote() {
6334-
auto *locator = getLocator();
6335-
6336-
Optional<InFlightDiagnostic> diagnostic;
6337-
if (locator->isForContextualType()) {
6338-
auto overload = getCalleeOverloadChoiceIfAvailable(locator);
6339-
if (!overload)
6340-
return false;
6341-
6342-
if (auto *decl = overload->choice.getDeclOrNull()) {
6343-
diagnostic.emplace(emitDiagnosticAt(
6344-
decl, diag::cannot_convert_candidate_result_to_contextual_type,
6345-
decl->getName(), ExpectedType, RawReprType));
6346-
}
6347-
} else if (auto argConv =
6348-
locator->getLastElementAs<LocatorPathElt::ApplyArgToParam>()) {
6349-
diagnostic.emplace(
6350-
emitDiagnostic(diag::candidate_has_invalid_argument_at_position,
6351-
RawReprType, argConv->getParamIdx(), /*inOut=*/false));
6352-
}
6353-
6354-
if (diagnostic) {
6355-
fixIt(*diagnostic);
6356-
return true;
6357-
}
6358-
6359-
return false;
6360-
}
6361-
63626362
void UseOfRawRepresentableInsteadOfItsRawValueFailure::fixIt(
63636363
InFlightDiagnostic &diagnostic) const {
63646364
auto *E = getAsExpr(getAnchor());

0 commit comments

Comments
 (0)