[SourceKit] Fix assertion failure in sortTopN

With the unqualified fallback we start to hit this assertion for
`return nil` in failable intializers. We ought to be able to just
skip over literal buckets though.
This commit is contained in:
Hamish Knight
2025-08-25 11:13:40 +01:00
parent a63ab6d161
commit a3edf17b24
2 changed files with 8 additions and 4 deletions

View File

@@ -847,10 +847,7 @@ static void sortTopN(const Options &options, Group *group,
unsigned endNewIndex = 0;
for (unsigned i = 1; i < contents.size(); ++i) {
auto bucket = getResultBucket(*contents[i], hasRequiredTypes);
if (bucket < best) {
// This algorithm assumes we don't have both literal and
// literal-type-match at the start of the list.
assert(bucket != ResultBucket::Literal);
if (bucket < best && bucket != ResultBucket::Literal) {
if (isTopNonLiteralResult(*contents[i], best)) {
beginNewIndex = i;
endNewIndex = beginNewIndex + 1;