Skip to content

Commit 7123d26

Browse files
authored
Merge pull request #36880 from ahoppen/pr/cursor-info-protocol-var
[ASTPrinter] Don't transform type if current type can't have members
2 parents 8c9d402 + d93ae06 commit 7123d26

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

lib/AST/ASTPrinter.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -924,6 +924,18 @@ class PrintAST : public ASTVisitor<PrintAST> {
924924
if (Options.TransformContext) {
925925
Type CurrentType = Options.TransformContext->getBaseType();
926926
if (CurrentType && CurrentType->hasArchetype()) {
927+
// OpenedArchetypeTypes get replaced by a GenericTypeParamType without a
928+
// name in mapTypeOutOfContext. The GenericTypeParamType has no children
929+
// so we can't use it for TypeTransformContext.
930+
// To work around this, replace the OpenedArchetypeType with the type of
931+
// the protocol itself.
932+
CurrentType = CurrentType.transform([](Type T) -> Type {
933+
if (auto *Opened = T->getAs<OpenedArchetypeType>()) {
934+
return Opened->getOpenedExistentialType();
935+
} else {
936+
return T;
937+
}
938+
});
927939
CurrentType = CurrentType->mapTypeOutOfContext();
928940
}
929941
setCurrentType(CurrentType);
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
protocol MyError {
2+
var myVar: String { get }
3+
}
4+
5+
func foo(error: MyError) {
6+
_ = error.myVar
7+
}
8+
9+
// RUN: %sourcekitd-test -req=cursor -pos=6:15 %s -- %s | %FileCheck %s
10+
// CHECK: myVar
11+
// CHECK-NEXT: s:27cursor_info_existential_var7MyErrorP5myVarSSvp
12+
// CHECK-NEXT: source.lang.swift
13+
// CHECK-NEXT: String

0 commit comments

Comments
 (0)