Skip to content

[4.2-04-30] DocSupport: don't assume we've printed the first extension when merging several together. rdar://39887195 #16333

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 3, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions lib/IDE/ModuleInterfacePrinting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -622,10 +622,11 @@ void swift::ide::printSubmoduleInterface(
// For sub-decls, all extensions should be printed.
SynthesizedExtensionAnalyzer::MergeGroupKind::All,
[&](ArrayRef<ExtensionInfo> Decls) {
// Whether we've started the extension merge group in printing.
bool Opened = false;
for (auto ET : Decls) {
AdjustedOptions.BracketOptions = {
ET.Ext, Decls.front().Ext == ET.Ext,
Decls.back().Ext == ET.Ext, true};
AdjustedOptions.BracketOptions = { ET.Ext, !Opened,
Decls.back().Ext == ET.Ext, true};
if (AdjustedOptions.BracketOptions.shouldOpenExtension(
ET.Ext))
Printer << "\n";
Expand All @@ -636,7 +637,8 @@ void swift::ide::printSubmoduleInterface(
else
AdjustedOptions.initForSynthesizedExtension(NTD);
}
ET.Ext->print(Printer, AdjustedOptions);
// Set opened if we actually printed this extension.
Opened |= ET.Ext->print(Printer, AdjustedOptions);
if (ET.IsSynthesized)
AdjustedOptions.clearSynthesizedExtension();
if (AdjustedOptions.BracketOptions.shouldCloseExtension(
Expand Down
2 changes: 2 additions & 0 deletions test/SourceKit/DocSupport/doc_stdlib.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// Make sure we're not crashing.
// RUN: %sourcekitd-test -req=doc-info -module Swift
1 change: 1 addition & 0 deletions tools/SourceKit/lib/SwiftLang/SwiftDocSupport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ class AnnotatingPrinter : public StreamPrinter {
initDefaultMapToUse(D);
// If D is declared in the extension, then the synthesized target is valid.
TypeOrExtensionDecl SynthesizedTarget;
assert(D->getDeclContext()->isModuleScopeContext() == EntitiesStack.empty());
if (D->getDeclContext() == SynthesizedExtensionInfo.first)
SynthesizedTarget = SynthesizedExtensionInfo.second;
EntitiesStack.emplace_back(D, SynthesizedTarget,
Expand Down