Skip to content

[4.0][migrator] When renaming a function decl, we should use underscore to represent empty external argument label. rdar://34569243 #12225

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
Oct 3, 2017
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
7 changes: 6 additions & 1 deletion lib/Migrator/APIDiffMigratorPass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -684,14 +684,19 @@ struct APIDiffMigratorPass : public ASTMigratorPass, public SourceEntityWalker {
StringRef NewArg = View.args()[Index++];
auto ArgLoc = PD->getArgumentNameLoc();

// Represent empty label with underscore.
if (NewArg.empty())
NewArg = "_";

// If the argument name is not specified, add the argument name before
// the parameter name.
if (ArgLoc.isInvalid())
Editor.insertBefore(PD->getNameLoc(),
(llvm::Twine(NewArg) + " ").str());
else
else {
// Otherwise, replace the argument name directly.
Editor.replaceToken(ArgLoc, NewArg);
}
}
}
}
Expand Down
11 changes: 11 additions & 0 deletions test/Migrator/Inputs/API.json
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,17 @@
"RightComment": "setZooLocationNew(newX:newY:newZ:)",
"ModuleName": "Cities"
},
{
"DiffItemKind": "CommonDiffItem",
"NodeKind": "Function",
"NodeAnnotation": "Rename",
"ChildIndex": "0",
"LeftUsr": "s:6Cities04MoreA0P8addZooAtySi_Si1ySi1ztF",
"LeftComment": "",
"RightUsr": "",
"RightComment": "addNewZooAt(_:newY:newZ:)",
"ModuleName": "Cities"
},
{
"DiffItemKind": "CommonDiffItem",
"NodeKind": "Function",
Expand Down
1 change: 1 addition & 0 deletions test/Migrator/Inputs/Cities.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public protocol ExtraCities {

public protocol MoreCities {
func setZooLocation(x: Int, y: Int, z: Int)
func addZooAt(_ x: Int, y: Int, z: Int)
}

public func setCityProperty1(_ c : Cities, _ p : Int) {}
Expand Down
1 change: 1 addition & 0 deletions test/Migrator/rename-func-decl.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ import Cities

class MyCities : MoreCities {
func setZooLocation(x ix: Int, y iy: Int, z iz: Int) {}
func addZooAt(_ x: Int, y: Int, z: Int) {}
}
1 change: 1 addition & 0 deletions test/Migrator/rename-func-decl.swift.expected
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ import Cities

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