Skip to content

Commit 9330eb0

Browse files
authored
Merge pull request swiftlang#38194 from ahoppen/pr-5.5/implict-return-async-refactoring
[5.5][Async Refactoring] Add `return` keyword if wrapping `ReturnStmt` is implicit
2 parents e432296 + 3134a9a commit 9330eb0

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
@@ -6477,7 +6477,8 @@ class AsyncConverter : private SourceEntityWalker {
64776477
// for the completion handler call, e.g 'return completion(args...)'. In
64786478
// that case, be sure not to add another return.
64796479
auto *parent = getWalker().Parent.getAsStmt();
6480-
AddedReturnOrThrow = !(parent && isa<ReturnStmt>(parent));
6480+
AddedReturnOrThrow = !(parent && isa<ReturnStmt>(parent) &&
6481+
!cast<ReturnStmt>(parent)->isImplicit());
64816482
if (AddedReturnOrThrow)
64826483
OS << tok::kw_return;
64836484
} else {

test/refactoring/ConvertAsync/convert_function.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,3 +329,14 @@ func withDefaultArg(x: String = "") {
329329
// DEFAULT-ARG: convert_function.swift [[# @LINE-3]]:1 -> [[# @LINE-2]]:2
330330
// DEFAULT-ARG-NOT: @discardableResult
331331
// DEFAULT-ARG-NEXT: {{^}}func withDefaultArg(x: String = "") async
332+
333+
// RUN: %refactor -convert-to-async -dump-text -source-filename %s -pos=%(line+1):1 | %FileCheck -check-prefix=IMPLICIT-RETURN %s
334+
func withImplicitReturn(completionHandler: (String) -> Void) {
335+
simple {
336+
completionHandler($0)
337+
}
338+
}
339+
// IMPLICIT-RETURN: func withImplicitReturn() async -> String {
340+
// IMPLICIT-RETURN-NEXT: let val0 = await simple()
341+
// IMPLICIT-RETURN-NEXT: return val0
342+
// IMPLICIT-RETURN-NEXT: }

0 commit comments

Comments
 (0)