Skip to content

Commit a3edf17

Browse files
committed
[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.
1 parent a63ab6d commit a3edf17

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// Make sure we don't crash
2+
struct S {
3+
init?() {
4+
return nil
5+
// RUN: %sourcekitd-test -req=complete.open -pos=%(line-1):12 %s -- %s
6+
}
7+
}

tools/SourceKit/lib/SwiftLang/CodeCompletionOrganizer.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -847,10 +847,7 @@ static void sortTopN(const Options &options, Group *group,
847847
unsigned endNewIndex = 0;
848848
for (unsigned i = 1; i < contents.size(); ++i) {
849849
auto bucket = getResultBucket(*contents[i], hasRequiredTypes);
850-
if (bucket < best) {
851-
// This algorithm assumes we don't have both literal and
852-
// literal-type-match at the start of the list.
853-
assert(bucket != ResultBucket::Literal);
850+
if (bucket < best && bucket != ResultBucket::Literal) {
854851
if (isTopNonLiteralResult(*contents[i], best)) {
855852
beginNewIndex = i;
856853
endNewIndex = beginNewIndex + 1;

0 commit comments

Comments
 (0)