Skip to content

Commit c6ef23b

Browse files
authored
Merge pull request #38982 from apple/cherry-rdar82156720
[5.5][Refactoring] Do not add "async" if function is already async
2 parents a85e729 + 1d570fc commit c6ef23b

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

lib/IDE/Refactoring.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6671,7 +6671,8 @@ class AsyncConverter : private SourceEntityWalker {
66716671
addRange(MidStartLoc, MidEndLoc);
66726672

66736673
// Third chunk: add in async and throws if necessary
6674-
OS << " async";
6674+
if (!FD->hasAsync())
6675+
OS << " async";
66756676
if (FD->hasThrows() || TopHandler.HasError)
66766677
// TODO: Add throws if converting a function and it has a converted call
66776678
// without a do/catch

test/refactoring/ConvertAsync/convert_function.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,17 @@ func simpleErr(arg: String) async throws -> String { }
2121
func simpleRes(arg: String, _ completion: @escaping (Result<String, Error>) -> Void) { }
2222
func simpleRes(arg: String) async throws -> String { }
2323

24+
// RUN: %refactor-check-compiles -convert-to-async -dump-text -source-filename %s -pos=%(line+1):1 | %FileCheck -check-prefix=ALREADY-ASYNC %s
25+
func alreadyAsync() async {
26+
simple {
27+
print($0)
28+
}
29+
}
30+
// ALREADY-ASYNC: func alreadyAsync() async {
31+
// ALREADY-ASYNC-NEXT: let val0 = await simple()
32+
// ALREADY-ASYNC-NEXT: print(val0)
33+
// ALREADY-ASYNC-NEXT: }
34+
2435
// RUN: %refactor-check-compiles -convert-to-async -dump-text -source-filename %s -pos=%(line+1):1 | %FileCheck -check-prefix=NESTED %s
2536
func nested() {
2637
simple {

0 commit comments

Comments
 (0)