Skip to content

Commit a673691

Browse files
committed
[CodeComplete] Fix mangling of protocols with primary associated types for cached type relations
#59763 changed `appendType` to no longer be able to mangle `ParameterizedProtocolType`. Instead, we need to call into `appendConstrainedExistential` directly. This manifested as a SourceKit crash every time you invoke code completion when you import a module that exports a type alias that resolves to a protocol with a primary associated type. rdar://98623438
1 parent fd4e98a commit a673691

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

lib/AST/ASTMangler.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -752,6 +752,9 @@ std::string ASTMangler::mangleTypeAsUSR(Type Ty) {
752752

753753
if (auto *fnType = Ty->getAs<AnyFunctionType>()) {
754754
appendFunction(fnType, nullptr);
755+
} else if (Ty->is<ParameterizedProtocolType>()) {
756+
// ParameterizedProtocolType cannot be mangled using 'appendType'.
757+
appendConstrainedExistential(Ty, nullptr, nullptr);
755758
} else {
756759
appendType(Ty, nullptr);
757760
}
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)