Skip to content

Commit 8d3a728

Browse files
committed
[migrator] Revert "migrator: avoid inserting base name while renaming if users' member access doesn't specify the base name. rdar://40373279"
We've seen cases where using dot member names cause build errors. Thus, we revert this QOL fix. rdar://40458118
1 parent c99009f commit 8d3a728

File tree

3 files changed

+8
-28
lines changed

3 files changed

+8
-28
lines changed

lib/Migrator/APIDiffMigratorPass.cpp

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -260,21 +260,6 @@ struct APIDiffMigratorPass : public ASTMigratorPass, public SourceEntityWalker {
260260
SF->getASTContext().SourceMgr, Range).str() == "nil";
261261
}
262262

263-
bool isDotMember(CharSourceRange Range) {
264-
auto S = Range.str();
265-
return S.startswith(".") && S.substr(1).find(".") == StringRef::npos;
266-
}
267-
268-
bool isDotMember(SourceRange Range) {
269-
return isDotMember(Lexer::getCharSourceRangeFromSourceRange(
270-
SF->getASTContext().SourceMgr, Range));
271-
}
272-
273-
bool isDotMember(Expr *E) {
274-
auto Range = E->getSourceRange();
275-
return Range.isValid() && isDotMember(Range);
276-
}
277-
278263
std::vector<APIDiffItem*> getRelatedDiffItems(ValueDecl *VD) {
279264
std::vector<APIDiffItem*> results;
280265
auto addDiffItems = [&](ValueDecl *VD) {
@@ -323,11 +308,11 @@ struct APIDiffMigratorPass : public ASTMigratorPass, public SourceEntityWalker {
323308
}
324309

325310

326-
bool isSimpleReplacement(APIDiffItem *Item, bool isDotMember, std::string &Text) {
311+
bool isSimpleReplacement(APIDiffItem *Item, std::string &Text) {
327312
if (auto *MD = dyn_cast<TypeMemberDiffItem>(Item)) {
328313
if (MD->Subkind == TypeMemberDiffItemSubKind::SimpleReplacement) {
329-
Text = (llvm::Twine(isDotMember ? "" : MD->newTypeName) + "." +
330-
MD->getNewName().base()).str();
314+
Text = (llvm::Twine(MD->newTypeName) + "." + MD->getNewName().base()).
315+
str();
331316
return true;
332317
}
333318
}
@@ -390,7 +375,7 @@ struct APIDiffMigratorPass : public ASTMigratorPass, public SourceEntityWalker {
390375
Type T, ReferenceMetaData Data) override {
391376
for (auto *Item: getRelatedDiffItems(CtorTyRef ? CtorTyRef: D)) {
392377
std::string RepText;
393-
if (isSimpleReplacement(Item, isDotMember(Range), RepText)) {
378+
if (isSimpleReplacement(Item, RepText)) {
394379
Editor.replace(Range, RepText);
395380
return true;
396381
}
@@ -465,9 +450,8 @@ struct APIDiffMigratorPass : public ASTMigratorPass, public SourceEntityWalker {
465450
for (auto *I: getRelatedDiffItems(VD)) {
466451
if (auto *Item = dyn_cast<TypeMemberDiffItem>(I)) {
467452
if (Item->Subkind == TypeMemberDiffItemSubKind::QualifiedReplacement) {
468-
Editor.replace(ToReplace,
469-
(llvm::Twine(isDotMember(ToReplace) ? "" : Item->newTypeName) + "." +
470-
Item->getNewName().base()).str());
453+
Editor.replace(ToReplace, (llvm::Twine(Item->newTypeName) + "." +
454+
Item->getNewName().base()).str());
471455
return true;
472456
}
473457
}
@@ -741,7 +725,7 @@ struct APIDiffMigratorPass : public ASTMigratorPass, public SourceEntityWalker {
741725
StringRef LeftComment;
742726
StringRef RightComment;
743727
for (auto *Item: getRelatedDiffItems(RD)) {
744-
if (isSimpleReplacement(Item, isDotMember(Reference), Rename)) {
728+
if (isSimpleReplacement(Item, Rename)) {
745729
} else if (auto *CI = dyn_cast<CommonDiffItem>(Item)) {
746730
if (CI->isStringRepresentableChange() &&
747731
CI->NodeKind == SDKNodeKind::DeclVar) {

test/Migrator/qualified-replacement.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ func foo() {
1414
_ = Cities.CityKind.Town
1515
_ = ToplevelType()
1616
_ = ToplevelType(recordName: "")
17-
bar(.orderedSame)
1817
}
1918

2019
func foo(_: ToplevelType) {}
21-
func bar(_ : FooComparisonResult) {}

test/Migrator/qualified-replacement.swift.expected

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,10 @@ func foo() {
1010
_ = NewPropertyUserInterface.newFieldPlus
1111
NewPropertyUserInterface.newMethodPlus(1)
1212
_ = NewFooComparisonResult.NewFooOrderedSame
13-
let _ : FooComparisonResult = .NewFooOrderedSame
13+
let _ : FooComparisonResult = NewFooComparisonResult.NewFooOrderedSame
1414
_ = NewCityKind.NewTown
1515
_ = ToplevelWrapper.internalType()
1616
_ = ToplevelWrapper.internalType(recordName: "")
17-
bar(.NewFooOrderedSame)
1817
}
1918

2019
func foo(_: ToplevelWrapper.internalType) {}
21-
func bar(_ : FooComparisonResult) {}

0 commit comments

Comments
 (0)