@@ -84,7 +84,16 @@ struct ParametersAndReturnValidator {
84
84
// If all source languages have empty parameter sections, return `nil` instead of individually empty sections.
85
85
parameterVariants = DocumentationDataVariants ( defaultVariantValue: nil )
86
86
}
87
- var returnVariants = makeReturnsSectionVariants ( returns? . first, signatures, symbol. documentedSymbol? . kind, hasDocumentedParameters: parameters != nil )
87
+
88
+ var returnVariants = makeReturnsSectionVariants (
89
+ returns? . first,
90
+ signatures,
91
+ documentedSymbolKind: symbol. documentedSymbol? . kind,
92
+ swiftSymbolKind: symbol. kind. mapFirst { selector, kind in
93
+ SourceLanguage ( knownLanguageIdentifier: selector. interfaceLanguage) == . swift ? kind. identifier : nil
94
+ } ,
95
+ hasDocumentedParameters: parameters != nil
96
+ )
88
97
if returnVariants. allValues. allSatisfy ( { _, section in section. content. isEmpty } ) {
89
98
// If all source languages have empty return value sections, return `nil` instead of individually empty sections.
90
99
returnVariants = DocumentationDataVariants ( defaultVariantValue: nil )
@@ -209,25 +218,34 @@ struct ParametersAndReturnValidator {
209
218
/// - Parameters:
210
219
/// - returns: The symbol's documented return values.
211
220
/// - signatures: The symbol's containing only the values that exist in that language representation's function signature.
212
- /// - symbolKind: The documented symbol's kind, for use in diagnostics.
221
+ /// - documentedSymbolKind: The documented symbol's kind, for use in diagnostics.
222
+ /// - swiftSymbolKind: The symbol's Swift representation's kind, or `nil` if the symbol doesn't have a Swift representation.
213
223
/// - hasDocumentedParameters: `true` if the symbol has documented any of its parameters; otherwise `false`.
214
224
/// - Returns: A returns section variant containing only the return values that exist in each language representation's function signature.
215
225
private func makeReturnsSectionVariants(
216
226
_ returns: Return ? ,
217
227
_ signatures: Signatures ,
218
- _ symbolKind: SymbolGraph . Symbol . Kind ? ,
228
+ documentedSymbolKind: SymbolGraph . Symbol . Kind ? ,
229
+ swiftSymbolKind: SymbolGraph . Symbol . KindIdentifier ? ,
219
230
hasDocumentedParameters: Bool
220
231
) -> DocumentationDataVariants < ReturnsSection > {
221
232
let returnsSection = returns. map { ReturnsSection ( content: $0. contents) }
222
233
var variants = DocumentationDataVariants < ReturnsSection > ( )
223
234
224
235
var traitsWithNonVoidReturnValues = Set ( signatures. keys)
225
236
for (trait, signature) in signatures {
237
+ let language = trait. interfaceLanguage. flatMap ( SourceLanguage . init ( knownLanguageIdentifier: ) )
238
+
239
+ // The function signature for Swift initializers indicate a Void return type.
240
+ // However, initializers have a _conceptual_ return value that's sometimes worth documenting (rdar://131913065).
241
+ if language == . swift, swiftSymbolKind == . `init` {
242
+ variants [ trait] = returnsSection
243
+ continue
244
+ }
245
+
226
246
/// A Boolean value that indicates whether the current signature returns a known "void" value.
227
247
var returnsKnownVoidValue : Bool {
228
- guard let language = trait. interfaceLanguage. flatMap ( SourceLanguage . init ( knownLanguageIdentifier: ) ) ,
229
- let voidReturnValues = Self . knownVoidReturnValuesByLanguage [ language]
230
- else {
248
+ guard let language, let voidReturnValues = Self . knownVoidReturnValuesByLanguage [ language] else {
231
249
return false
232
250
}
233
251
return signature. returns. allSatisfy { voidReturnValues. contains ( $0) }
@@ -251,7 +269,7 @@ struct ParametersAndReturnValidator {
251
269
252
270
// Diagnose if the symbol had documented its return values but all language representations only return void.
253
271
if let returns, traitsWithNonVoidReturnValues. isEmpty {
254
- diagnosticEngine. emit ( makeReturnsDocumentedForVoidProblem ( returns, symbolKind: symbolKind ) )
272
+ diagnosticEngine. emit ( makeReturnsDocumentedForVoidProblem ( returns, symbolKind: documentedSymbolKind ) )
255
273
}
256
274
return variants
257
275
}
0 commit comments