Skip to content

Commit c00de60

Browse files
benlangmuirtkremenek
authored andcommitted
[CodeCompletion] Fix a crash when completing typealiases for protocol conformance (#3120)
The index may be at the end of the ArrayRef of chunks if the completion ends with a simple parameter with no type annotation. Check that the index is in-bounds before adding text. rdar://problem/26273906
1 parent d08ebf6 commit c00de60

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

test/SourceKit/CodeComplete/complete_structure.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
// RUN: %complete-test %s -group=none -fuzz -structure -tok=OVERRIDE_0 | FileCheck %s -check-prefix=OVERRIDE_0
88
// RUN: %complete-test %s -group=none -fuzz -structure -tok=S1_INNER_0 | FileCheck %s -check-prefix=S1_INNER_0
99
// RUN: %complete-test %s -group=none -fuzz -structure -tok=INT_INNER_0 | FileCheck %s -check-prefix=INT_INNER_0
10+
// RUN: %complete-test %s -group=none -fuzz -structure -tok=ASSOCIATED_TYPE_1 | FileCheck %s -check-prefix=ASSOCIATED_TYPE_1
1011

1112
struct S1 {
1213
func method1() {}
@@ -119,3 +120,11 @@ func test9(_ x: inout Int) {
119120
// INT_INNER_0: {name:x++}
120121
// INT_INNER_0: {name:x>>}
121122
// INT_INNER_0: {name:x..<}
123+
124+
protocol P1 {
125+
associatedtype T
126+
}
127+
struct S2: P1 {
128+
#^ASSOCIATED_TYPE_1^#
129+
}
130+
// ASSOCIATED_TYPE_1: {name:T = }{params:{l:Type}}

tools/SourceKit/lib/SwiftLang/SwiftCompletion.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ static void getResultStructure(
372372
if (!param.range().empty())
373373
parameters.push_back(std::move(param));
374374

375-
if (chunks[i].hasText())
375+
if (i < chunks.size() && chunks[i].hasText())
376376
textSize += chunks[i].getText().size();
377377
}
378378

0 commit comments

Comments
 (0)