File tree Expand file tree Collapse file tree 3 files changed +24
-11
lines changed
test/refactoring/ConvertAsync Expand file tree Collapse file tree 3 files changed +24
-11
lines changed Original file line number Diff line number Diff line change @@ -4258,10 +4258,12 @@ struct AsyncHandlerDesc {
4258
4258
if (!isValid ())
4259
4259
return nullptr ;
4260
4260
4261
- if (Node.isExpr (swift::ExprKind::Call)) {
4262
- CallExpr *CE = cast<CallExpr>(Node.dyn_cast <Expr *>());
4263
- if (CE->getFn ()->getReferencedDecl ().getDecl () == getHandler ())
4264
- return CE;
4261
+ if (auto E = Node.dyn_cast <Expr *>()) {
4262
+ if (auto *CE = dyn_cast<CallExpr>(E->getSemanticsProvidingExpr ())) {
4263
+ if (CE->getFn ()->getReferencedDecl ().getDecl () == getHandler ()) {
4264
+ return CE;
4265
+ }
4266
+ }
4265
4267
}
4266
4268
return nullptr ;
4267
4269
}
@@ -6343,10 +6345,10 @@ class AsyncConverter : private SourceEntityWalker {
6343
6345
}
6344
6346
} else if (CallExpr *CE = TopHandler.getAsHandlerCall (E)) {
6345
6347
if (Scopes.back ().isWrappedInContination ()) {
6346
- return addCustom (CE ->getSourceRange (),
6348
+ return addCustom (E ->getSourceRange (),
6347
6349
[&]() { addHandlerCallToContinuation (CE); });
6348
6350
} else if (NestedExprCount == 0 ) {
6349
- return addCustom (CE ->getSourceRange (), [&]() { addHandlerCall (CE); });
6351
+ return addCustom (E ->getSourceRange (), [&]() { addHandlerCall (CE); });
6350
6352
}
6351
6353
} else if (auto *CE = dyn_cast<CallExpr>(E)) {
6352
6354
// Try and hoist a call's completion handler. Don't do so if
Original file line number Diff line number Diff line change @@ -287,15 +287,12 @@ func testReturnHandling2(completion: @escaping (String) -> ()) {
287
287
// RETURN-HANDLING2-NEXT: }
288
288
// RETURN-HANDLING2-NEXT: }
289
289
290
- // FIXME: We should arguably be able to handle transforming this completion handler call (rdar://78011350).
291
- // RUN: %refactor -add-async-alternative -dump-text -source-filename %s -pos=%(line+1):1 | %FileCheck -check-prefix=RETURN-HANDLING3 %s
290
+ // RUN: %refactor-check-compiles -add-async-alternative -dump-text -source-filename %s -pos=%(line+1):1 | %FileCheck -check-prefix=RETURN-HANDLING3 %s
292
291
func testReturnHandling3( _ completion: ( String ? , Error ? ) -> Void ) {
293
292
return ( completion ( " " , nil ) )
294
293
}
295
294
// RETURN-HANDLING3: func testReturnHandling3() async throws -> String {
296
- // RETURN-HANDLING3-NEXT: return try await withCheckedThrowingContinuation { continuation in
297
- // RETURN-HANDLING3-NEXT: (continuation.resume(returning: ""))
298
- // RETURN-HANDLING3-NEXT: }
295
+ // RETURN-HANDLING3-NEXT: {{^}} return ""{{$}}
299
296
// RETURN-HANDLING3-NEXT: }
300
297
301
298
// RUN: %refactor -convert-to-async -dump-text -source-filename %s -pos=%(line+1):1 | %FileCheck -check-prefix=RDAR78693050 %s
Original file line number Diff line number Diff line change @@ -26,6 +26,20 @@ func testCreateContinuation(completionHandler: (Int) -> Void) {
26
26
// CREATE-CONTINUATION-NEXT: }
27
27
// CREATE-CONTINUATION-NEXT: }
28
28
29
+ // RUN: %refactor-check-compiles -convert-to-async -dump-text -source-filename %s -pos=%(line+1):1 | %FileCheck -check-prefix=CREATE-CONTINUATION-HANDLER-CALL-IN-PARENS %s
30
+ func testCreateContinuationWithCompletionHandlerCallInParens( completionHandler: ( Int ) -> Void ) {
31
+ withoutAsyncAlternativeBecauseOfMismatchedCompletionHandlerName {
32
+ ( completionHandler ( $0) )
33
+ }
34
+ }
35
+ // CREATE-CONTINUATION-HANDLER-CALL-IN-PARENS: func testCreateContinuationWithCompletionHandlerCallInParens() async -> Int {
36
+ // CREATE-CONTINUATION-HANDLER-CALL-IN-PARENS-NEXT: return await withCheckedContinuation { continuation in
37
+ // CREATE-CONTINUATION-HANDLER-CALL-IN-PARENS-NEXT: withoutAsyncAlternativeBecauseOfMismatchedCompletionHandlerName {
38
+ // CREATE-CONTINUATION-HANDLER-CALL-IN-PARENS-NEXT: continuation.resume(returning: $0)
39
+ // CREATE-CONTINUATION-HANDLER-CALL-IN-PARENS-NEXT: }
40
+ // CREATE-CONTINUATION-HANDLER-CALL-IN-PARENS-NEXT: }
41
+ // CREATE-CONTINUATION-HANDLER-CALL-IN-PARENS-NEXT: }
42
+
29
43
// RUN: %refactor-check-compiles -convert-to-async -dump-text -source-filename %s -pos=%(line+1):1 | %FileCheck -check-prefix=CREATE-CONTINUATION-BECAUSE-RETURN-VALUE %s
30
44
func testCreateContinuationBecauseOfReturnValue( completionHandler: ( Int ) -> Void ) {
31
45
_ = withoutAsyncAlternativeBecauseOfReturnValue {
You can’t perform that action at this time.
0 commit comments