Skip to content

Commit 1286bbe

Browse files
authored
Merge pull request #38665 from ahoppen/pr/async-refactoring-parens-around-result
[Async Refactoring] Handle parenthesis around params that no longer need to be unwrapped after refactoring
2 parents c8ad4cd + 3bea2b7 commit 1286bbe

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
@@ -6802,7 +6802,8 @@ class AsyncConverter : private SourceEntityWalker {
68026802
// Synthesize the force unwrap so that we get the expected results.
68036803
if (TopHandler.getHandlerType() == HandlerType::PARAMS &&
68046804
TopHandler.HasError) {
6805-
if (auto DRE = dyn_cast<DeclRefExpr>(Elt)) {
6805+
if (auto DRE =
6806+
dyn_cast<DeclRefExpr>(Elt->getSemanticsProvidingExpr())) {
68066807
auto D = DRE->getDecl();
68076808
if (Unwraps.count(D)) {
68086809
Elt = new (getASTContext()) ForceValueExpr(Elt, SourceLoc());

test/refactoring/ConvertAsync/convert_function.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -587,6 +587,17 @@ func wrapCompletionCallInParenthesis(completion: @escaping (String?, Error?) ->
587587
// WRAP-COMPLETION-CALL-IN-PARENS-NEXT: return res
588588
// WRAP-COMPLETION-CALL-IN-PARENS-NEXT: }
589589

590+
// RUN: %refactor -convert-to-async -dump-text -source-filename %s -pos=%(line+1):1 | %FileCheck -check-prefix=WRAP-RESULT-IN-PARENS %s
591+
func wrapResultInParenthesis(completion: @escaping (String?, Error?) -> Void) {
592+
simpleErr(arg: "test") { (res, err) in
593+
completion((res).self, err)
594+
}
595+
}
596+
// WRAP-RESULT-IN-PARENS: func wrapResultInParenthesis() async throws -> String {
597+
// WRAP-RESULT-IN-PARENS-NEXT: let res = try await simpleErr(arg: "test")
598+
// WRAP-RESULT-IN-PARENS-NEXT: return res
599+
// WRAP-RESULT-IN-PARENS-NEXT: }
600+
590601
// RUN: %refactor -convert-to-async -dump-text -source-filename %s -pos=%(line+1):1 | %FileCheck -check-prefix=TWO-COMPLETION-HANDLER-CALLS %s
591602
func twoCompletionHandlerCalls(completion: @escaping (String?, Error?) -> Void) {
592603
simpleErr(arg: "test") { (res, err) in

0 commit comments

Comments
 (0)