Skip to content

[Async Refactoring] Handle parenthesis around params that no longer need to be unwrapped after refactoring #38665

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 @@ -6802,7 +6802,8 @@ class AsyncConverter : private SourceEntityWalker {
// Synthesize the force unwrap so that we get the expected results.
if (TopHandler.getHandlerType() == HandlerType::PARAMS &&
TopHandler.HasError) {
if (auto DRE = dyn_cast<DeclRefExpr>(Elt)) {
if (auto DRE =
dyn_cast<DeclRefExpr>(Elt->getSemanticsProvidingExpr())) {
auto D = DRE->getDecl();
if (Unwraps.count(D)) {
Elt = new (getASTContext()) ForceValueExpr(Elt, SourceLoc());
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 @@ -587,6 +587,17 @@ func wrapCompletionCallInParenthesis(completion: @escaping (String?, Error?) ->
// WRAP-COMPLETION-CALL-IN-PARENS-NEXT: return res
// WRAP-COMPLETION-CALL-IN-PARENS-NEXT: }

// RUN: %refactor -convert-to-async -dump-text -source-filename %s -pos=%(line+1):1 | %FileCheck -check-prefix=WRAP-RESULT-IN-PARENS %s
func wrapResultInParenthesis(completion: @escaping (String?, Error?) -> Void) {
simpleErr(arg: "test") { (res, err) in
completion((res).self, err)
}
}
// WRAP-RESULT-IN-PARENS: func wrapResultInParenthesis() async throws -> String {
// WRAP-RESULT-IN-PARENS-NEXT: let res = try await simpleErr(arg: "test")
// WRAP-RESULT-IN-PARENS-NEXT: return res
// WRAP-RESULT-IN-PARENS-NEXT: }

// RUN: %refactor -convert-to-async -dump-text -source-filename %s -pos=%(line+1):1 | %FileCheck -check-prefix=TWO-COMPLETION-HANDLER-CALLS %s
func twoCompletionHandlerCalls(completion: @escaping (String?, Error?) -> Void) {
simpleErr(arg: "test") { (res, err) in
Expand Down