Skip to content

Commit 7a68a1d

Browse files
authored
Merge pull request #38191 from ahoppen/pr/implict-return-async-refactoring
[Async Refactoring] Add `return` keyword if wrapping `ReturnStmt` is implicit
2 parents 7f08508 + f7c7599 commit 7a68a1d

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
@@ -6461,7 +6461,8 @@ class AsyncConverter : private SourceEntityWalker {
64616461
// for the completion handler call, e.g 'return completion(args...)'. In
64626462
// that case, be sure not to add another return.
64636463
auto *parent = getWalker().Parent.getAsStmt();
6464-
AddedReturnOrThrow = !(parent && isa<ReturnStmt>(parent));
6464+
AddedReturnOrThrow = !(parent && isa<ReturnStmt>(parent) &&
6465+
!cast<ReturnStmt>(parent)->isImplicit());
64656466
if (AddedReturnOrThrow)
64666467
OS << tok::kw_return;
64676468
} 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)