Skip to content

Commit 2dfc8b6

Browse files
committed
[Diagnostics] Refactor argument source range retrieval
1 parent f0078d6 commit 2dfc8b6

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
@@ -4752,28 +4752,22 @@ static bool diagnoseSingleCandidateFailures(CalleeCandidateInfo &CCI,
47524752
argBindings[argIdx] = paramIdx;
47534753
}
47544754

4755-
auto firstRange = tuple->getElement(argIdx)->getSourceRange();
4756-
if (!first.empty()) {
4757-
firstRange.Start = tuple->getElementNameLoc(argIdx);
4758-
}
4759-
unsigned OOOParamIdx = argBindings[argIdx];
4760-
if (Bindings[OOOParamIdx].size() > 1) {
4761-
firstRange.End =
4762-
tuple->getElement(Bindings[OOOParamIdx].back())->getEndLoc();
4763-
}
4755+
auto argRange = [&](unsigned argIdx, Identifier label) -> SourceRange {
4756+
auto range = tuple->getElement(argIdx)->getSourceRange();
4757+
if (!label.empty())
4758+
range.Start = tuple->getElementNameLoc(argIdx);
47644759

4765-
auto secondRange = tuple->getElement(prevArgIdx)->getSourceRange();
4766-
if (!second.empty()) {
4767-
secondRange.Start = tuple->getElementNameLoc(prevArgIdx);
4768-
}
4769-
unsigned OOOPrevParamIdx = argBindings[prevArgIdx];
4770-
if (Bindings[OOOPrevParamIdx].size() > 1) {
4771-
secondRange.End =
4772-
tuple->getElement(Bindings[OOOPrevParamIdx].back())->getEndLoc();
4773-
}
4760+
unsigned paramIdx = argBindings[argIdx];
4761+
if (Bindings[paramIdx].size() > 1)
4762+
range.End = tuple->getElement(Bindings[paramIdx].back())->getEndLoc();
47744763

4775-
SourceLoc diagLoc = firstRange.Start;
4764+
return range;
4765+
};
47764766

4767+
auto firstRange = argRange(argIdx, first);
4768+
auto secondRange = argRange(prevArgIdx, second);
4769+
4770+
SourceLoc diagLoc = firstRange.Start;
47774771
if (first.empty() && second.empty()) {
47784772
TC.diagnose(diagLoc, diag::argument_out_of_order_unnamed_unnamed,
47794773
argIdx + 1, prevArgIdx + 1)

0 commit comments

Comments
 (0)