Skip to content

Commit 8faaee8

Browse files
synthesized symbols should always inherit docs
1 parent 977f134 commit 8faaee8

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

lib/SymbolGraphGen/Symbol.cpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,10 @@ const ValueDecl *Symbol::getDeclInheritingDocs() const {
178178
getDocCommentProvidingDecl(VD, /*AllowSerialized=*/true));
179179

180180
// if the decl is the same as the one for this symbol, we're not
181-
// inheriting docs, so return null.
182-
if (DocCommentProvidingDecl == VD) {
181+
// inheriting docs, so return null. however, if this symbol is
182+
// a synthesized symbol, `VD` is actually the source symbol, and
183+
// we should point to that one regardless.
184+
if (DocCommentProvidingDecl == VD && !SynthesizedBaseTypeDecl) {
183185
return nullptr;
184186
} else {
185187
// otherwise, return whatever `getDocCommentProvidingDecl` returned.

test/SymbolGraph/Relationships/Synthesized/InheritedDocs.swift

+21
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,48 @@
44
// RUN: %target-swift-symbolgraph-extract -module-name InheritedDocs -I %t -pretty-print -output-dir %t
55
// RUN: %FileCheck %s --input-file %t/InheritedDocs.symbols.json --check-prefixes CHECK,DOCS
66
// RUN: %FileCheck %s --input-file %t/InheritedDocs.symbols.json --check-prefixes IMPL
7+
// RUN: %FileCheck %s --input-file %t/InheritedDocs.symbols.json --check-prefixes BONUS
8+
// RUN: %FileCheck %s --input-file %t/InheritedDocs.symbols.json --check-prefixes BONUS-DOCS
79

810
// RUN: %target-swift-symbolgraph-extract -module-name InheritedDocs -I %t -pretty-print -output-dir %t -skip-inherited-docs
911
// RUN: %FileCheck %s --input-file %t/InheritedDocs.symbols.json --check-prefixes CHECK,SKIP
1012
// RUN: %FileCheck %s --input-file %t/InheritedDocs.symbols.json --check-prefixes IMPL
13+
// RUN: %FileCheck %s --input-file %t/InheritedDocs.symbols.json --check-prefixes BONUS
14+
// RUN: %FileCheck %s --input-file %t/InheritedDocs.symbols.json --check-prefixes BONUS-SKIP
1115

1216
// RUN: %empty-directory(%t)
1317
// RUN: %target-build-swift %s -module-name InheritedDocs -emit-module -emit-module-path %t/InheritedDocs.swiftmodule -emit-symbol-graph -emit-symbol-graph-dir %t/ -skip-inherited-docs
1418
// RUN: %FileCheck %s --input-file %t/InheritedDocs.symbols.json --check-prefixes SKIP
1519

1620
// DOCS-COUNT-3: Some Function
21+
// BONUS-DOCS-COUNT-2: Bonus docs!
1722
// SKIP-COUNT-1: Some Function
23+
// BONUS-SKIP-COUNT-1: Bonus docs!
24+
25+
// synthesized symbols should have a sourceOrigin field that points to where its docs come from
1826

1927
// CHECK: "source": "s:13InheritedDocs1PPAAE8someFuncyyF::SYNTHESIZED::s:13InheritedDocs1SV"
2028
// CHECK-NEXT: "target": "s:13InheritedDocs1SV"
2129
// CHECK-NEXT: "sourceOrigin"
2230
// CHECK-NEXT: "identifier": "s:13InheritedDocs1PP8someFuncyyF"
2331
// CHECK-NEXT: "displayName": "P.someFunc()"
2432

33+
// non-synthesized symbols that nonetheless inherit docs (like this extension) should have the same
34+
2535
// IMPL: "source": "s:13InheritedDocs1PPAAE8someFuncyyF"
2636
// IMPL-NEXT: "target": "s:13InheritedDocs1PP8someFuncyyF"
2737
// IMPL-NEXT: "sourceOrigin"
2838
// IMPL-NEXT: "identifier": "s:13InheritedDocs1PP8someFuncyyF"
2939
// IMPL-NEXT: "displayName": "P.someFunc()"
3040

41+
// synthesized symbols that point directly to their docs should also have a sourceOrigin field
42+
43+
// BONUS: "source": "s:13InheritedDocs1PPAAE9bonusFuncyyF::SYNTHESIZED::s:13InheritedDocs1SV"
44+
// BONUS-NEXT: "target": "s:13InheritedDocs1SV"
45+
// BONUS-NEXT: "sourceOrigin"
46+
// BONUS-NEXT: "identifier": "s:13InheritedDocs1PPAAE9bonusFuncyyF"
47+
// BONUS-NEXT: "displayName": "P.bonusFunc()"
48+
3149
/// Protocol P
3250
public protocol P {
3351
/// Some Function
@@ -36,6 +54,9 @@ public protocol P {
3654

3755
public extension P {
3856
func someFunc() {}
57+
58+
/// Bonus docs!
59+
func bonusFunc() {}
3960
}
4061

4162
public struct S: P {

0 commit comments

Comments
 (0)