From f4a72fefa5bdad0f283aeeae068938b187893ace Mon Sep 17 00:00:00 2001 From: Ben Langmuir Date: Tue, 21 Jun 2016 16:53:25 -0700 Subject: [PATCH] [CodeCompletion] Fix a crash when completing typealiases for protocol conformance 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 --- test/SourceKit/CodeComplete/complete_structure.swift | 9 +++++++++ tools/SourceKit/lib/SwiftLang/SwiftCompletion.cpp | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/test/SourceKit/CodeComplete/complete_structure.swift b/test/SourceKit/CodeComplete/complete_structure.swift index e31b8d5e449bf..abaef93274f30 100644 --- a/test/SourceKit/CodeComplete/complete_structure.swift +++ b/test/SourceKit/CodeComplete/complete_structure.swift @@ -7,6 +7,7 @@ // RUN: %complete-test %s -group=none -fuzz -structure -tok=OVERRIDE_0 | FileCheck %s -check-prefix=OVERRIDE_0 // RUN: %complete-test %s -group=none -fuzz -structure -tok=S1_INNER_0 | FileCheck %s -check-prefix=S1_INNER_0 // RUN: %complete-test %s -group=none -fuzz -structure -tok=INT_INNER_0 | FileCheck %s -check-prefix=INT_INNER_0 +// RUN: %complete-test %s -group=none -fuzz -structure -tok=ASSOCIATED_TYPE_1 | FileCheck %s -check-prefix=ASSOCIATED_TYPE_1 struct S1 { func method1() {} @@ -119,3 +120,11 @@ func test9(_ x: inout Int) { // INT_INNER_0: {name:x++} // INT_INNER_0: {name:x>>} // INT_INNER_0: {name:x..<} + +protocol P1 { + associatedtype T +} +struct S2: P1 { + #^ASSOCIATED_TYPE_1^# +} +// ASSOCIATED_TYPE_1: {name:T = }{params:{l:Type}} diff --git a/tools/SourceKit/lib/SwiftLang/SwiftCompletion.cpp b/tools/SourceKit/lib/SwiftLang/SwiftCompletion.cpp index 9e16473e80e60..40e73c97262dd 100644 --- a/tools/SourceKit/lib/SwiftLang/SwiftCompletion.cpp +++ b/tools/SourceKit/lib/SwiftLang/SwiftCompletion.cpp @@ -372,7 +372,7 @@ static void getResultStructure( if (!param.range().empty()) parameters.push_back(std::move(param)); - if (chunks[i].hasText()) + if (i < chunks.size() && chunks[i].hasText()) textSize += chunks[i].getText().size(); }