mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[Diagnostics] Correctly diagnose situations when immutable value is passed to inout parameter
Currently the note is going to point to the "callee" but that is incorrect when the failure is related to an argument of a call. Detect this situation in `RValueTreatedAsLValueFailure::diagnoseAsNote` and produce a correct note. Resolves: rdar://150689994
This commit is contained in:
@@ -2049,11 +2049,24 @@ bool RValueTreatedAsLValueFailure::diagnoseAsError() {
|
||||
}
|
||||
|
||||
bool RValueTreatedAsLValueFailure::diagnoseAsNote() {
|
||||
auto overload = getCalleeOverloadChoiceIfAvailable(getLocator());
|
||||
auto *locator = getLocator();
|
||||
|
||||
auto overload = getCalleeOverloadChoiceIfAvailable(locator);
|
||||
if (!(overload && overload->choice.isDecl()))
|
||||
return false;
|
||||
|
||||
auto *decl = overload->choice.getDecl();
|
||||
|
||||
if (locator->isLastElement<LocatorPathElt::ArgumentAttribute>()) {
|
||||
auto argConv = locator->findLast<LocatorPathElt::ApplyArgToParam>();
|
||||
if (!argConv)
|
||||
return false;
|
||||
|
||||
emitDiagnosticAt(decl, diag::candidate_expects_inout_argument,
|
||||
argConv->getParamIdx() + 1);
|
||||
return true;
|
||||
}
|
||||
|
||||
emitDiagnosticAt(decl, diag::candidate_is_not_assignable, decl);
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user