Skip to content

Commit 4600b1d

Browse files
committed
[CodeCompletion] Fix incorrect upper bound for assertion
This assertion was bogus if there were fewer results than N.
1 parent 9433c39 commit 4600b1d

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

test/SourceKit/CodeComplete/complete_sort_order.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,15 @@ func test3(x: Int) {
118118
// EXPR_TOP_1: z
119119
// EXPR_TOP_1: zzz
120120

121+
// Test where there are fewer results than 'top'.
122+
// RUN: %complete-test -top=1000 -tok=FEW_1 %s | FileCheck %s -check-prefix=FEW_1
123+
func test3b() -> Int {
124+
return #^FEW_1^#
125+
}
126+
// FEW_1: test3b()
127+
// FEW_1: Int
128+
// FEW_1: 0
129+
121130
// Top 3
122131
// RUN: %complete-test -top=3 -tok=EXPR_2 %s | FileCheck %s -check-prefix=EXPR_TOP_3
123132
func test4(x: Int) {

tools/SourceKit/lib/SwiftLang/CodeCompletionOrganizer.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -924,7 +924,7 @@ static void sortTopN(const Options &options, Group *group,
924924
if (!beginNewIndex)
925925
return;
926926

927-
assert(endNewIndex > beginNewIndex && endNewIndex < contents.size());
927+
assert(endNewIndex > beginNewIndex && endNewIndex <= contents.size());
928928

929929
// Temporarily copy the first result to temporary storage.
930930
SmallVector<Item *, 16> firstResults;
@@ -938,6 +938,7 @@ static void sortTopN(const Options &options, Group *group,
938938
contents[ci] = std::unique_ptr<Item>(firstResults[i]);
939939
}
940940
unsigned topN = endNewIndex - beginNewIndex;
941+
assert(topN <= options.showTopNonLiteralResults);
941942
for (unsigned ci = topN, i = 0; i < beginNewIndex; ++i, ++ci) {
942943
assert(ci < contents.size() && !contents[ci]);
943944
contents[ci] = std::unique_ptr<Item>(firstResults[i]);

0 commit comments

Comments
 (0)