Skip to content

Commit 9aead6b

Browse files
authored
Merge pull request #16507 from nkcsgexi/avoid-reinsert-function
2 parents 0a6ea97 + b302bd3 commit 9aead6b

File tree

3 files changed

+53
-1
lines changed

3 files changed

+53
-1
lines changed

lib/Migrator/APIDiffMigratorPass.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,15 @@ struct APIDiffMigratorPass : public ASTMigratorPass, public SourceEntityWalker {
312312
APIDiffMigratorPass(EditorAdapter &Editor, SourceFile *SF,
313313
const MigratorOptions &Opts):
314314
ASTMigratorPass(Editor, SF, Opts),
315-
FileEndLoc(SM.getRangeForBuffer(BufferID).getEnd()) {}
315+
FileEndLoc(SM.getRangeForBuffer(BufferID).getEnd()) {
316+
SmallVector<Decl*, 16> TopDecls;
317+
SF->getTopLevelDecls(TopDecls);
318+
for (auto *D: TopDecls) {
319+
if (auto *FD = dyn_cast<FuncDecl>(D)) {
320+
InsertedFunctions.insert(FD->getBaseName().getIdentifier().str());
321+
}
322+
}
323+
}
316324

317325
void run() {
318326
if (Opts.APIDigesterDataStorePaths.empty())
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// REQUIRES: objc_interop
2+
// RUN: %empty-directory(%t.mod)
3+
// RUN: %target-swift-frontend -emit-module -o %t.mod/Cities.swiftmodule %S/Inputs/Cities.swift -module-name Cities -parse-as-library
4+
// RUN: %empty-directory(%t) && %target-swift-frontend -c -update-code -primary-file %s -I %t.mod -api-diff-data-file %S/Inputs/string-representable.json -emit-migrated-file-path %t/avoid_insert_existing_functions.swift.result -disable-migrator-fixits -o /dev/null
5+
// RUN: diff -u %S/avoid_insert_existing_functions.swift.expected %t/avoid_insert_existing_functions.swift.result
6+
7+
import Cities
8+
9+
typealias NewAttribute = String
10+
11+
func foo(_ c: Container) -> String {
12+
c.Value = ""
13+
return c.Value
14+
}
15+
16+
fileprivate func convertToNewAttribute(_ input: String) -> NewAttribute {
17+
return ""
18+
}
19+
20+
fileprivate func convertFromNewAttribute(_ input: NewAttribute) -> String {
21+
return ""
22+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// REQUIRES: objc_interop
2+
// RUN: %empty-directory(%t.mod)
3+
// RUN: %target-swift-frontend -emit-module -o %t.mod/Cities.swiftmodule %S/Inputs/Cities.swift -module-name Cities -parse-as-library
4+
// RUN: %empty-directory(%t) && %target-swift-frontend -c -update-code -primary-file %s -I %t.mod -api-diff-data-file %S/Inputs/string-representable.json -emit-migrated-file-path %t/avoid_insert_existing_functions.swift.result -disable-migrator-fixits -o /dev/null
5+
// RUN: diff -u %S/avoid_insert_existing_functions.swift.expected %t/avoid_insert_existing_functions.swift.result
6+
7+
import Cities
8+
9+
typealias NewAttribute = String
10+
11+
func foo(_ c: Container) -> String {
12+
c.Value = convertToNewAttribute("")
13+
return convertFromNewAttribute(c.Value)
14+
}
15+
16+
fileprivate func convertToNewAttribute(_ input: String) -> NewAttribute {
17+
return ""
18+
}
19+
20+
fileprivate func convertFromNewAttribute(_ input: NewAttribute) -> String {
21+
return ""
22+
}

0 commit comments

Comments
 (0)