Skip to content

Commit d58df38

Browse files
committed
[CodeComplete] Workaround a bug that parameterized protocols without 'any' cannot be mangled
`typealias` is currently allowed to refer to a protocol without the `any` keyword. This breaks mangling the typealias type into a USR will crash because parameterized protocols are expected to be `any` types. Implement a SourceKit-specific minimal workaround for that problem by not computing `USRBasedType`s for parameterized protocols. rdar://98623438
1 parent fd4e98a commit d58df38

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

lib/IDE/CodeCompletionResultType.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,16 @@ const USRBasedType *USRBasedType::fromType(Type Ty, USRBasedTypeArena &Arena) {
195195
return USRBasedType::null(Arena);
196196
}
197197

198+
// ParameterizedProtocolType should always be wrapped in ExistentialType and
199+
// cannot be mangled on its own.
200+
// But ParameterizedProtocolType can currently occur in 'typealias'
201+
// declarations. rdar://99176683
202+
// To avoid crashing in USR generation, simply return a null type until the
203+
// underlying issue has been fixed.
204+
if (Ty->is<ParameterizedProtocolType>()) {
205+
return USRBasedType::null(Arena);
206+
}
207+
198208
SmallString<32> USR;
199209
llvm::raw_svector_ostream OS(USR);
200210
printTypeUSR(Ty, OS);
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// RUN: %empty-directory(%t/split)
2+
// RUN: %empty-directory(%t/build)
3+
// RUN: %{python} %utils/split_file.py -o %t/split %s
4+
5+
// RUN: %target-swift-frontend -emit-module -o %t/build %t/split/pck.swift
6+
7+
// RUN: %target-swift-ide-test -code-completion -source-filename %t/split/test.swift -I %t/build -code-completion-token=COMPLETE | %FileCheck %s
8+
9+
// BEGIN pck.swift
10+
11+
public protocol Foo<Bar> {
12+
associatedtype Bar
13+
}
14+
15+
public typealias Problem = Foo<String>
16+
17+
// BEGIN test.swift
18+
19+
import pck
20+
21+
#^COMPLETE^#
22+
23+
// CHECK: Begin completions
24+
// CHECK-DAG: Decl[Protocol]/OtherModule[pck]/Flair[RareType]: Foo[#Foo#];
25+
// CHECK-DAG: Decl[TypeAlias]/OtherModule[pck]: Problem[#Foo<String>#];
26+
// CHECK: End completions

0 commit comments

Comments
 (0)