Skip to content

Commit 254fc5e

Browse files
authored
[migrator] When renaming a function decl, we should use underscore to represent empty external argument label. rdar://34569243 (#12221) (#12225)
1 parent 8ed5ab3 commit 254fc5e

File tree

5 files changed

+20
-1
lines changed

5 files changed

+20
-1
lines changed

lib/Migrator/APIDiffMigratorPass.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -684,14 +684,19 @@ struct APIDiffMigratorPass : public ASTMigratorPass, public SourceEntityWalker {
684684
StringRef NewArg = View.args()[Index++];
685685
auto ArgLoc = PD->getArgumentNameLoc();
686686

687+
// Represent empty label with underscore.
688+
if (NewArg.empty())
689+
NewArg = "_";
690+
687691
// If the argument name is not specified, add the argument name before
688692
// the parameter name.
689693
if (ArgLoc.isInvalid())
690694
Editor.insertBefore(PD->getNameLoc(),
691695
(llvm::Twine(NewArg) + " ").str());
692-
else
696+
else {
693697
// Otherwise, replace the argument name directly.
694698
Editor.replaceToken(ArgLoc, NewArg);
699+
}
695700
}
696701
}
697702
}

test/Migrator/Inputs/API.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,17 @@
446446
"RightComment": "setZooLocationNew(newX:newY:newZ:)",
447447
"ModuleName": "Cities"
448448
},
449+
{
450+
"DiffItemKind": "CommonDiffItem",
451+
"NodeKind": "Function",
452+
"NodeAnnotation": "Rename",
453+
"ChildIndex": "0",
454+
"LeftUsr": "s:6Cities04MoreA0P8addZooAtySi_Si1ySi1ztF",
455+
"LeftComment": "",
456+
"RightUsr": "",
457+
"RightComment": "addNewZooAt(_:newY:newZ:)",
458+
"ModuleName": "Cities"
459+
},
449460
{
450461
"DiffItemKind": "CommonDiffItem",
451462
"NodeKind": "Function",

test/Migrator/Inputs/Cities.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ public protocol ExtraCities {
2222

2323
public protocol MoreCities {
2424
func setZooLocation(x: Int, y: Int, z: Int)
25+
func addZooAt(_ x: Int, y: Int, z: Int)
2526
}
2627

2728
public func setCityProperty1(_ c : Cities, _ p : Int) {}

test/Migrator/rename-func-decl.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ import Cities
88

99
class MyCities : MoreCities {
1010
func setZooLocation(x ix: Int, y iy: Int, z iz: Int) {}
11+
func addZooAt(_ x: Int, y: Int, z: Int) {}
1112
}

test/Migrator/rename-func-decl.swift.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ import Cities
88

99
class MyCities : MoreCities {
1010
func setZooLocationNew(newX ix: Int, newY iy: Int, newZ iz: Int) {}
11+
func addNewZooAt(_ x: Int, newY y: Int, newZ z: Int) {}
1112
}

0 commit comments

Comments
 (0)