Skip to content

[5.5][Refactoring] Fix invalid legacy body for Result<Void, ...> handler #38865

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 3 commits into from
Aug 16, 2021
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
12 changes: 9 additions & 3 deletions lib/IDE/Refactoring.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6906,7 +6906,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 Expand Up @@ -7863,8 +7864,13 @@ class AsyncConverter : private SourceEntityWalker {
}
case HandlerType::RESULT: {
if (!ResultName.empty()) {
OS << tok::period_prefix << "success" << tok::l_paren << ResultName
<< tok::r_paren;
OS << tok::period_prefix << "success" << tok::l_paren;
if (!HandlerDesc.willAsyncReturnVoid()) {
OS << ResultName;
} else {
OS << tok::l_paren << tok::r_paren;
}
OS << tok::r_paren;
} else {
OS << tok::period_prefix << "failure" << tok::l_paren;
addForwardedErrorArgument("error", HandlerDesc);
Expand Down
15 changes: 15 additions & 0 deletions test/refactoring/ConvertAsync/basic.swift
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,21 @@ func voidAndErrorCompletion(completion: @escaping (Void, Error?) -> Void) {}
// VOID-AND-ERROR-HANDLER-NEXT: }
// VOID-AND-ERROR-HANDLER: func voidAndErrorCompletion() async throws {}

// RUN: %refactor-check-compiles -add-async-alternative -dump-text -source-filename %s -pos=%(line+1):1 | %FileCheck -check-prefix VOID-RESULT-HANDLER %s
func voidResultCompletion(completion: @escaping (Result<Void, Error>) -> Void) {}
// VOID-RESULT-HANDLER: {
// VOID-RESULT-HANDLER-NEXT: Task {
// VOID-RESULT-HANDLER-NEXT: do {
// VOID-RESULT-HANDLER-NEXT: try await voidResultCompletion()
// VOID-RESULT-HANDLER-NEXT: completion(.success(()))
// VOID-RESULT-HANDLER-NEXT: } catch {
// VOID-RESULT-HANDLER-NEXT: completion(.failure(error))
// VOID-RESULT-HANDLER-NEXT: }
// VOID-RESULT-HANDLER-NEXT: }
// VOID-RESULT-HANDLER-NEXT: }
// VOID-RESULT-HANDLER: func voidResultCompletion() async throws {


// 2. Check that the various ways to call a function (and the positions the
// refactoring is called from) are handled correctly

Expand Down
Loading