Skip to content

Commit ca0cc2f

Browse files
xedinrudkx
authored andcommitted
[Diagnostics] Refactor argument source range retrieval
(cherry picked from commit 2dfc8b6)
1 parent c57f635 commit ca0cc2f

File tree

1 file changed

+13
-19
lines changed

1 file changed

+13
-19
lines changed

lib/Sema/CSDiag.cpp

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4738,28 +4738,22 @@ static bool diagnoseSingleCandidateFailures(CalleeCandidateInfo &CCI,
47384738
argBindings[argIdx] = paramIdx;
47394739
}
47404740

4741-
auto firstRange = tuple->getElement(argIdx)->getSourceRange();
4742-
if (!first.empty()) {
4743-
firstRange.Start = tuple->getElementNameLoc(argIdx);
4744-
}
4745-
unsigned OOOParamIdx = argBindings[argIdx];
4746-
if (Bindings[OOOParamIdx].size() > 1) {
4747-
firstRange.End =
4748-
tuple->getElement(Bindings[OOOParamIdx].back())->getEndLoc();
4749-
}
4741+
auto argRange = [&](unsigned argIdx, Identifier label) -> SourceRange {
4742+
auto range = tuple->getElement(argIdx)->getSourceRange();
4743+
if (!label.empty())
4744+
range.Start = tuple->getElementNameLoc(argIdx);
47504745

4751-
auto secondRange = tuple->getElement(prevArgIdx)->getSourceRange();
4752-
if (!second.empty()) {
4753-
secondRange.Start = tuple->getElementNameLoc(prevArgIdx);
4754-
}
4755-
unsigned OOOPrevParamIdx = argBindings[prevArgIdx];
4756-
if (Bindings[OOOPrevParamIdx].size() > 1) {
4757-
secondRange.End =
4758-
tuple->getElement(Bindings[OOOPrevParamIdx].back())->getEndLoc();
4759-
}
4746+
unsigned paramIdx = argBindings[argIdx];
4747+
if (Bindings[paramIdx].size() > 1)
4748+
range.End = tuple->getElement(Bindings[paramIdx].back())->getEndLoc();
47604749

4761-
SourceLoc diagLoc = firstRange.Start;
4750+
return range;
4751+
};
47624752

4753+
auto firstRange = argRange(argIdx, first);
4754+
auto secondRange = argRange(prevArgIdx, second);
4755+
4756+
SourceLoc diagLoc = firstRange.Start;
47634757
if (first.empty() && second.empty()) {
47644758
TC.diagnose(diagLoc, diag::argument_out_of_order_unnamed_unnamed,
47654759
argIdx + 1, prevArgIdx + 1)

0 commit comments

Comments
 (0)