Skip to content

Commit 1e34f31

Browse files
committed
[Async Refactoring] Drop bool flag parameter binding
If we have a known bool flag parameter, drop it from the success parameters being bound in a refactored await call, as the async variant drops it. rdar://81896460
1 parent fa3efee commit 1e34f31

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

lib/IDE/Refactoring.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4982,6 +4982,10 @@ class ClosureCallbackParams final {
49824982
bool hasBinding(const ParamDecl *Param) const {
49834983
if (!hasParam(Param))
49844984
return false;
4985+
if (auto BoolFlag = getKnownBoolFlagParam()) {
4986+
if (Param == BoolFlag->Param)
4987+
return false;
4988+
}
49854989
return true;
49864990
}
49874991

test/refactoring/ConvertAsync/convert_bool.swift

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -384,8 +384,7 @@ func testConvertBool() async throws {
384384
// OPT-BOOL-WITH-ERR-NEXT: print("g \(err)")
385385
// OPT-BOOL-WITH-ERR-NEXT: }
386386

387-
// We cannot use refactor-check-compiles, as a placeholder cannot be force unwrapped.
388-
// RUN: %refactor -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):3 -I %S/Inputs -I %t -target %target-triple %clang-importer-sdk-nosource | %FileCheck -check-prefix=OBJC-BOOL-WITH-ERR %s
387+
// RUN: %refactor-check-compiles -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):3 -I %S/Inputs -I %t -target %target-triple %clang-importer-sdk-nosource | %FileCheck -check-prefix=OBJC-BOOL-WITH-ERR %s
389388
ClassWithHandlerMethods.firstBoolFlagSuccess("") { str, success, unrelated, err in
390389
if !unrelated {
391390
print(err!)
@@ -405,7 +404,7 @@ func testConvertBool() async throws {
405404
}
406405

407406
// OBJC-BOOL-WITH-ERR: do {
408-
// OBJC-BOOL-WITH-ERR-NEXT: let (str, success, unrelated) = try await ClassWithHandlerMethods.firstBoolFlagSuccess("")
407+
// OBJC-BOOL-WITH-ERR-NEXT: let (str, unrelated) = try await ClassWithHandlerMethods.firstBoolFlagSuccess("")
409408
// OBJC-BOOL-WITH-ERR-NEXT: if !unrelated {
410409
// OBJC-BOOL-WITH-ERR-NEXT: print(<#err#>!)
411410
// OBJC-BOOL-WITH-ERR-NEXT: }
@@ -416,8 +415,7 @@ func testConvertBool() async throws {
416415
// OBJC-BOOL-WITH-ERR-NEXT: print(err)
417416
// OBJC-BOOL-WITH-ERR-NEXT: }
418417

419-
// We cannot use refactor-check-compiles, as a placeholder cannot be force unwrapped.
420-
// RUN: %refactor -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):3 -I %S/Inputs -I %t -target %target-triple %clang-importer-sdk-nosource | %FileCheck -check-prefix=OBJC-BOOL-WITH-ERR2 %s
418+
// RUN: %refactor-check-compiles -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):3 -I %S/Inputs -I %t -target %target-triple %clang-importer-sdk-nosource | %FileCheck -check-prefix=OBJC-BOOL-WITH-ERR2 %s
421419
ClassWithHandlerMethods.secondBoolFlagFailure("") { str, unrelated, failure, err in
422420
if unrelated {
423421
print(err!)
@@ -446,13 +444,13 @@ func testConvertBool() async throws {
446444
}
447445

448446
// OBJC-BOOL-WITH-ERR2: do {
449-
// OBJC-BOOL-WITH-ERR2-NEXT: let (str, unrelated, failure) = try await ClassWithHandlerMethods.secondBoolFlagFailure("")
447+
// OBJC-BOOL-WITH-ERR2-NEXT: let (str, unrelated) = try await ClassWithHandlerMethods.secondBoolFlagFailure("")
450448
// OBJC-BOOL-WITH-ERR2-NEXT: if unrelated {
451449
// OBJC-BOOL-WITH-ERR2-NEXT: print(<#err#>!)
452450
// OBJC-BOOL-WITH-ERR2-NEXT: }
453451
// OBJC-BOOL-WITH-ERR2-NEXT: print("woo")
454452
// OBJC-BOOL-WITH-ERR2-NEXT: print("also woo")
455-
// OBJC-BOOL-WITH-ERR2-NEXT: if failure && <#err#> == nil {
453+
// OBJC-BOOL-WITH-ERR2-NEXT: if <#failure#> && <#err#> == nil {
456454
// OBJC-BOOL-WITH-ERR2-NEXT: print("wat")
457455
// OBJC-BOOL-WITH-ERR2-NEXT: }
458456
// OBJC-BOOL-WITH-ERR2-NEXT: } catch let err {

0 commit comments

Comments
 (0)