Skip to content

Commit 2d0d2e9

Browse files
authored
[SourceKitd] Avoid printing parent type directly on extended type. rdar://37965902 (#14915)
When printing parent type directly, we may print generic arguments and sugared dictionary type.
1 parent 7c48bea commit 2d0d2e9

File tree

4 files changed

+464
-352
lines changed

4 files changed

+464
-352
lines changed

lib/AST/ASTPrinter.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1751,15 +1751,15 @@ static void printExtendedTypeName(Type ExtendedType, ASTPrinter &Printer,
17511751
PrintOptions Options) {
17521752
auto Nominal = ExtendedType->getAnyNominal();
17531753
assert(Nominal && "extension of non-nominal type");
1754-
if (auto ct = ExtendedType->getAs<ClassType>()) {
1755-
if (auto ParentType = ct->getParent()) {
1756-
ParentType.print(Printer, Options);
1757-
Printer << ".";
1758-
}
1759-
}
1760-
if (auto st = ExtendedType->getAs<StructType>()) {
1761-
if (auto ParentType = st->getParent()) {
1762-
ParentType.print(Printer, Options);
1754+
if (auto nt = ExtendedType->getAs<NominalType>()) {
1755+
if (auto ParentType = nt->getParent()) {
1756+
if (auto *PD = ParentType->getNominalOrBoundGenericNominal()) {
1757+
// Avoid using the parent type directly because it can be bound
1758+
// generic type and sugared.
1759+
PD->getDeclaredType().print(Printer, Options);
1760+
} else {
1761+
ParentType.print(Printer, Options);
1762+
}
17631763
Printer << ".";
17641764
}
17651765
}

test/SourceKit/DocSupport/Inputs/cake1.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,7 @@ public protocol P3 {
2525
public extension P2 where Self : P3 {
2626
func fooConstraint() {}
2727
}
28+
29+
public extension Dictionary.Keys {
30+
public func foo() {}
31+
}

0 commit comments

Comments
 (0)