Skip to content

[Async Refactoring] Add return keyword if wrapping ReturnStmt is implicit #38191

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/IDE/Refactoring.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6460,7 +6460,8 @@ class AsyncConverter : private SourceEntityWalker {
// for the completion handler call, e.g 'return completion(args...)'. In
// that case, be sure not to add another return.
auto *parent = getWalker().Parent.getAsStmt();
AddedReturnOrThrow = !(parent && isa<ReturnStmt>(parent));
AddedReturnOrThrow = !(parent && isa<ReturnStmt>(parent) &&
!cast<ReturnStmt>(parent)->isImplicit());
if (AddedReturnOrThrow)
OS << tok::kw_return;
} else {
Expand Down
11 changes: 11 additions & 0 deletions test/refactoring/ConvertAsync/convert_function.swift
Original file line number Diff line number Diff line change
Expand Up @@ -329,3 +329,14 @@ func withDefaultArg(x: String = "") {
// DEFAULT-ARG: convert_function.swift [[# @LINE-3]]:1 -> [[# @LINE-2]]:2
// DEFAULT-ARG-NOT: @discardableResult
// DEFAULT-ARG-NEXT: {{^}}func withDefaultArg(x: String = "") async

// RUN: %refactor -convert-to-async -dump-text -source-filename %s -pos=%(line+1):1 | %FileCheck -check-prefix=IMPLICIT-RETURN %s
func withImplicitReturn(completionHandler: (String) -> Void) {
simple {
completionHandler($0)
}
}
// IMPLICIT-RETURN: func withImplicitReturn() async -> String {
// IMPLICIT-RETURN-NEXT: let val0 = await simple()
// IMPLICIT-RETURN-NEXT: return val0
// IMPLICIT-RETURN-NEXT: }