Skip to content

Commit b8481da

Browse files
authored
Include explicitly unnamed parameter names in function signature (#77222)
rdar://138630917
1 parent 0d16cbf commit b8481da

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

lib/SymbolGraphGen/Symbol.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,8 @@ void Symbol::serializeFunctionSignature(llvm::json::OStream &OS) const {
413413
OS.attributeArray("parameters", [&]() {
414414
for (const auto *Param : *ParamList) {
415415
auto ExternalName = Param->getArgumentName().str();
416-
auto InternalName = Param->getParameterName().str();
416+
// `getNameStr()` returns "_" if the parameter is unnamed.
417+
auto InternalName = Param->getNameStr();
417418

418419
OS.object([&]() {
419420
if (ExternalName.empty()) {

test/SymbolGraph/Symbols/Mixins/FunctionSignature.swift

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
// RUN: %FileCheck %s --input-file %t/FunctionSignature.symbols.json --check-prefix=FUNC
55
// RUN: %FileCheck %s --input-file %t/FunctionSignature.symbols.json --check-prefix=INIT
66
// RUN: %FileCheck %s --input-file %t/FunctionSignature.symbols.json --check-prefix=SUBSCRIPT
7+
// RUN: %FileCheck %s --input-file %t/FunctionSignature.symbols.json --check-prefix=FUNC2
78

89
public struct MyStruct {
910
public init(_ noext: Int, ext int: Int) {}
@@ -102,4 +103,36 @@ public struct MyStruct {
102103
// FUNC-NEXT: "spelling": "String"
103104
// FUNC-NEXT: "preciseIdentifier": "s:SS"
104105

106+
public func bar(_: Int, ext _: Int) -> Void {}
107+
108+
// FUNC2-LABEL: "precise": "s:17FunctionSignature8MyStructV3bar_3extySi_SitF",
109+
// FUNC2: "name": "_"
110+
// FUNC2-NOT: "internalName": "_"
111+
// FUNC2-NEXT: declarationFragments
112+
113+
// FUNC2: "kind": "identifier"
114+
// FUNC2-NEXT: "spelling": "_"
115+
// FUNC2: "kind": "text"
116+
// FUNC2-NEXT: "spelling": ": "
117+
// FUNC2: "kind": "typeIdentifier"
118+
// FUNC2-NEXT: "spelling": "Int"
119+
// FUNC2-NEXT: "preciseIdentifier": "s:Si"
120+
121+
// FUNC2: "name": "ext"
122+
// FUNC2-NEXT: "internalName": "_"
123+
// FUNC2-NEXT: declarationFragments
124+
125+
// FUNC2: "kind": "identifier"
126+
// FUNC2-NEXT: "spelling": "_"
127+
// FUNC2: "kind": "text"
128+
// FUNC2-NEXT: "spelling": ": "
129+
// FUNC2: "kind": "typeIdentifier"
130+
// FUNC2-NEXT: "spelling": "Int"
131+
// FUNC2-NEXT: "preciseIdentifier": "s:Si"
132+
133+
// FUNC2: returns
134+
// FUNC2: "kind": "typeIdentifier"
135+
// FUNC2-NEXT: "spelling": "Void"
136+
// FUNC2-NEXT: "preciseIdentifier": "s:s4Voida"
137+
105138
}

0 commit comments

Comments
 (0)