Skip to content

Commit 2171ab9

Browse files
authored
Merge pull request #16333 from nkcsgexi/doc-support-4-30
[4.2-04-30] DocSupport: don't assume we've printed the first extension when merging several together. rdar://39887195
2 parents 615a666 + e1b898e commit 2171ab9

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

lib/IDE/ModuleInterfacePrinting.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -622,10 +622,11 @@ void swift::ide::printSubmoduleInterface(
622622
// For sub-decls, all extensions should be printed.
623623
SynthesizedExtensionAnalyzer::MergeGroupKind::All,
624624
[&](ArrayRef<ExtensionInfo> Decls) {
625+
// Whether we've started the extension merge group in printing.
626+
bool Opened = false;
625627
for (auto ET : Decls) {
626-
AdjustedOptions.BracketOptions = {
627-
ET.Ext, Decls.front().Ext == ET.Ext,
628-
Decls.back().Ext == ET.Ext, true};
628+
AdjustedOptions.BracketOptions = { ET.Ext, !Opened,
629+
Decls.back().Ext == ET.Ext, true};
629630
if (AdjustedOptions.BracketOptions.shouldOpenExtension(
630631
ET.Ext))
631632
Printer << "\n";
@@ -636,7 +637,8 @@ void swift::ide::printSubmoduleInterface(
636637
else
637638
AdjustedOptions.initForSynthesizedExtension(NTD);
638639
}
639-
ET.Ext->print(Printer, AdjustedOptions);
640+
// Set opened if we actually printed this extension.
641+
Opened |= ET.Ext->print(Printer, AdjustedOptions);
640642
if (ET.IsSynthesized)
641643
AdjustedOptions.clearSynthesizedExtension();
642644
if (AdjustedOptions.BracketOptions.shouldCloseExtension(
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// Make sure we're not crashing.
2+
// RUN: %sourcekitd-test -req=doc-info -module Swift

tools/SourceKit/lib/SwiftLang/SwiftDocSupport.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@ class AnnotatingPrinter : public StreamPrinter {
209209
initDefaultMapToUse(D);
210210
// If D is declared in the extension, then the synthesized target is valid.
211211
TypeOrExtensionDecl SynthesizedTarget;
212+
assert(D->getDeclContext()->isModuleScopeContext() == EntitiesStack.empty());
212213
if (D->getDeclContext() == SynthesizedExtensionInfo.first)
213214
SynthesizedTarget = SynthesizedExtensionInfo.second;
214215
EntitiesStack.emplace_back(D, SynthesizedTarget,

0 commit comments

Comments
 (0)