[Refactoring] Do not add "async" if function is already async

Convert Function to Async is available on an async function. It could be
useful to run this refactoring still, as it would attempt to convert any
completion-handler functions to their async alternatives. Keep allowing
this, but make sure not to re-add "async" to the function declaration.

Resolves rdar://82156720
This commit is contained in:
Ben Barham
2021-08-20 15:19:34 +10:00
parent 0daa9cc097
commit 86c47e45f0
2 changed files with 13 additions and 1 deletions

View File

@@ -21,6 +21,17 @@ func simpleErr(arg: String) async throws -> String { }
func simpleRes(arg: String, _ completion: @escaping (Result<String, Error>) -> Void) { }
func simpleRes(arg: String) async throws -> String { }
// RUN: %refactor-check-compiles -convert-to-async -dump-text -source-filename %s -pos=%(line+1):1 | %FileCheck -check-prefix=ALREADY-ASYNC %s
func alreadyAsync() async {
simple {
print($0)
}
}
// ALREADY-ASYNC: func alreadyAsync() async {
// ALREADY-ASYNC-NEXT: let val0 = await simple()
// ALREADY-ASYNC-NEXT: print(val0)
// ALREADY-ASYNC-NEXT: }
// RUN: %refactor-check-compiles -convert-to-async -dump-text -source-filename %s -pos=%(line+1):1 | %FileCheck -check-prefix=NESTED %s
func nested() {
simple {