Skip to content

Commit 4fef4b6

Browse files
ahoppenbnbarham
authored andcommitted
[Async Refactoring] Handle parenthesis around params that no longer need to be unwrapped after refactoring
Throw another `getSemanticsProvidingExpr` in the async refactoring code for better results.
1 parent 793b492 commit 4fef4b6

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
@@ -6906,7 +6906,8 @@ class AsyncConverter : private SourceEntityWalker {
69066906
// Synthesize the force unwrap so that we get the expected results.
69076907
if (TopHandler.getHandlerType() == HandlerType::PARAMS &&
69086908
TopHandler.HasError) {
6909-
if (auto DRE = dyn_cast<DeclRefExpr>(Elt)) {
6909+
if (auto DRE =
6910+
dyn_cast<DeclRefExpr>(Elt->getSemanticsProvidingExpr())) {
69106911
auto D = DRE->getDecl();
69116912
if (Unwraps.count(D)) {
69126913
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)