mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
[CodeCompletion] Fix incorrect upper bound for assertion
This assertion was bogus if there were fewer results than N.
This commit is contained in:
@@ -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) {
|
||||||
|
|||||||
@@ -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]);
|
||||||
|
|||||||
Reference in New Issue
Block a user