[CodeCompletion] Fix incorrect upper bound for assertion

This assertion was bogus if there were fewer results than N.
This commit is contained in:
Ben Langmuir
2016-06-02 09:01:48 -07:00
parent 9433c390e8
commit 4600b1dd12
2 changed files with 11 additions and 1 deletions

View File

@@ -118,6 +118,15 @@ func test3(x: Int) {
// EXPR_TOP_1: z // EXPR_TOP_1: z
// EXPR_TOP_1: zzz // EXPR_TOP_1: zzz
// Test where there are fewer results than 'top'.
// RUN: %complete-test -top=1000 -tok=FEW_1 %s | FileCheck %s -check-prefix=FEW_1
func test3b() -> Int {
return #^FEW_1^#
}
// FEW_1: test3b()
// FEW_1: Int
// FEW_1: 0
// Top 3 // Top 3
// RUN: %complete-test -top=3 -tok=EXPR_2 %s | FileCheck %s -check-prefix=EXPR_TOP_3 // RUN: %complete-test -top=3 -tok=EXPR_2 %s | FileCheck %s -check-prefix=EXPR_TOP_3
func test4(x: Int) { func test4(x: Int) {

View File

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