1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502
|
// REQUIRES: objc_interop
// REQUIRES: concurrency
// RUN: %empty-directory(%t)
// RUN: %build-clang-importer-objc-overlays
import Foundation
import ConvertBoolObjC
func boolWithErr() async throws -> Bool { true }
func boolWithErr(completion: @escaping (Bool, Error?) -> Void) {}
func multipleBoolWithErr() async throws -> (String, Bool, Bool) { ("", true, true) }
func multipleBoolWithErr(completion: @escaping (String?, Bool, Bool, Error?) -> Void) {}
func optionalBoolWithErr() async throws -> (String, Bool, Bool) { ("", true, true) }
func optionalBoolWithErr(completion: @escaping (String?, Bool?, Bool, Error?) -> Void) {}
func testConvertBool() async throws {
// All 7 of the below should generate the same refactoring.
// 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=BOOL-WITH-ERR %s
boolWithErr { b, err in
if !b {
fatalError("oh no \(err!)")
}
print("not err")
}
// 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=BOOL-WITH-ERR %s
boolWithErr { b, err in
if b {
fatalError("oh no \(err!)")
}
print("not err")
}
// 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=BOOL-WITH-ERR %s
boolWithErr { b, err in
if !b && err != nil {
fatalError("oh no \(err!)")
}
print("not err")
}
// 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=BOOL-WITH-ERR %s
boolWithErr { b, err in
if b && err != nil {
fatalError("oh no \(err!)")
}
print("not err")
}
// 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=BOOL-WITH-ERR %s
boolWithErr { b, err in
if err != nil && b == false {
fatalError("oh no \(err!)")
}
print("not err")
}
// 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=BOOL-WITH-ERR %s
boolWithErr { b, err in
if b == true && err == nil {
} else {
fatalError("oh no \(err!)")
}
print("not err")
}
// 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=BOOL-WITH-ERR %s
boolWithErr { b, err in
if !b && err == nil {
} else {
fatalError("oh no \(err!)")
}
print("not err")
}
// BOOL-WITH-ERR: do {
// BOOL-WITH-ERR-NEXT: let b = try await boolWithErr()
// BOOL-WITH-ERR-NEXT: print("not err")
// BOOL-WITH-ERR-NEXT: } catch let err {
// BOOL-WITH-ERR-NEXT: fatalError("oh no \(err)")
// BOOL-WITH-ERR-NEXT: }
// These 3 should both generate the same refactoring.
// 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=BOOL-WITH-ERR2 %s
boolWithErr { success, err in
if success == true && err == nil {
print("hi")
} else {
fatalError("oh no \(err!)")
}
print("not err")
}
// 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=BOOL-WITH-ERR2 %s
boolWithErr { success, err in
if success && err == nil {
print("hi")
} else {
fatalError("oh no \(err!)")
}
print("not err")
}
// 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=BOOL-WITH-ERR2 %s
boolWithErr { success, err in
if err == nil {
print("hi")
} else if !success {
fatalError("oh no \(err!)")
}
print("not err")
}
// BOOL-WITH-ERR2: do {
// BOOL-WITH-ERR2-NEXT: let success = try await boolWithErr()
// BOOL-WITH-ERR2-NEXT: print("hi")
// BOOL-WITH-ERR2-NEXT: print("not err")
// BOOL-WITH-ERR2-NEXT: } catch let err {
// BOOL-WITH-ERR2-NEXT: fatalError("oh no \(err)")
// BOOL-WITH-ERR2-NEXT: }
// 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=BOOL-WITH-ERR3 %s
boolWithErr { failure, err in
if failure {
print("a \(err!)")
} else if .random() {
print("b")
} else {
print("c")
}
}
// BOOL-WITH-ERR3: do {
// BOOL-WITH-ERR3-NEXT: let failure = try await boolWithErr()
// BOOL-WITH-ERR3-NEXT: if .random() {
// BOOL-WITH-ERR3-NEXT: print("b")
// BOOL-WITH-ERR3-NEXT: } else {
// BOOL-WITH-ERR3-NEXT: print("c")
// BOOL-WITH-ERR3-NEXT: }
// BOOL-WITH-ERR3-NEXT: } catch let err {
// BOOL-WITH-ERR3-NEXT: print("a \(err)")
// BOOL-WITH-ERR3-NEXT: }
// Don't handle the below example as the force unwrap of err takes place under a different condition.
// We cannot use refactor-check-compiles, as a placeholder cannot be force unwrapped.
// 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=BOOL-DONT-HANDLE %s
boolWithErr { success, err in
if !success {
if err != nil {
fatalError("oh no \(err!)")
}
}
if !success {
_ = err != nil ? fatalError("oh no \(err!)") : fatalError("some worries")
}
print("not err")
}
// BOOL-DONT-HANDLE: let success = try await boolWithErr()
// BOOL-DONT-HANDLE-NEXT: if !success {
// BOOL-DONT-HANDLE-NEXT: if <#err#> != nil {
// BOOL-DONT-HANDLE-NEXT: fatalError("oh no \(<#err#>!)")
// BOOL-DONT-HANDLE-NEXT: }
// BOOL-DONT-HANDLE-NEXT: }
// BOOL-DONT-HANDLE-NEXT: if !success {
// BOOL-DONT-HANDLE-NEXT: _ = <#err#> != nil ? fatalError("oh no \(<#err#>!)") : fatalError("some worries")
// BOOL-DONT-HANDLE-NEXT: }
// BOOL-DONT-HANDLE-NEXT: print("not err")
// We cannot use refactor-check-compiles, as a placeholder cannot be force unwrapped.
// 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=BOOL-DONT-HANDLE2 %s
boolWithErr { success, err in
if !success {
func doThings() {
fatalError("oh no \(err!)")
}
doThings()
}
if !success {
let doThings = {
fatalError("oh no \(err!)")
}
doThings()
}
if !success {
while err != nil {
fatalError("oh no \(err!)")
}
}
if !success {
for _: Int in [] {
fatalError("oh no \(err!)")
}
}
print("not err")
}
// FIXME: The 'err' in doThings() should become a placeholder (rdar://78509286).
// BOOL-DONT-HANDLE2: let success = try await boolWithErr()
// BOOL-DONT-HANDLE2-NEXT: if !success {
// BOOL-DONT-HANDLE2-NEXT: func doThings() {
// BOOL-DONT-HANDLE2-NEXT: fatalError("oh no \(err!)")
// BOOL-DONT-HANDLE2-NEXT: }
// BOOL-DONT-HANDLE2-NEXT: doThings()
// BOOL-DONT-HANDLE2-NEXT: }
// BOOL-DONT-HANDLE2-NEXT: if !success {
// BOOL-DONT-HANDLE2-NEXT: let doThings = {
// BOOL-DONT-HANDLE2-NEXT: fatalError("oh no \(<#err#>!)")
// BOOL-DONT-HANDLE2-NEXT: }
// BOOL-DONT-HANDLE2-NEXT: doThings()
// BOOL-DONT-HANDLE2-NEXT: }
// BOOL-DONT-HANDLE2-NEXT: if !success {
// BOOL-DONT-HANDLE2-NEXT: while <#err#> != nil {
// BOOL-DONT-HANDLE2-NEXT: fatalError("oh no \(<#err#>!)")
// BOOL-DONT-HANDLE2-NEXT: }
// BOOL-DONT-HANDLE2-NEXT: }
// BOOL-DONT-HANDLE2-NEXT: if !success {
// BOOL-DONT-HANDLE2-NEXT: for _: Int in [] {
// BOOL-DONT-HANDLE2-NEXT: fatalError("oh no \(<#err#>!)")
// BOOL-DONT-HANDLE2-NEXT: }
// BOOL-DONT-HANDLE2-NEXT: }
// BOOL-DONT-HANDLE2-NEXT: print("not err")
// 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=BOOL-DONT-HANDLE3 %s
boolWithErr { success, err in
if !success {
fatalError("oh no maybe \(String(describing: err))")
}
print("not err")
}
// err is not force unwrapped, so don't handle.
// BOOL-DONT-HANDLE3: let success = try await boolWithErr()
// BOOL-DONT-HANDLE3-NEXT: if !success {
// BOOL-DONT-HANDLE3-NEXT: fatalError("oh no maybe \(String(describing: <#err#>))")
// BOOL-DONT-HANDLE3-NEXT: }
// BOOL-DONT-HANDLE3-NEXT: print("not err")
// We cannot use refactor-check-compiles, as a placeholder cannot be force unwrapped.
// 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=BOOL-DONT-HANDLE4 %s
boolWithErr { failure, err in
if failure {
print("a")
} else if .random() {
print("b \(err!)")
} else {
print("c")
}
}
// Don't handle the case where the err unwrap occurs in an unrelated else if
// clause.
// BOOL-DONT-HANDLE4: let failure = try await boolWithErr()
// BOOL-DONT-HANDLE4-NEXT: if failure {
// BOOL-DONT-HANDLE4-NEXT: print("a")
// BOOL-DONT-HANDLE4-NEXT: } else if .random() {
// BOOL-DONT-HANDLE4-NEXT: print("b \(<#err#>!)")
// BOOL-DONT-HANDLE4-NEXT: } else {
// BOOL-DONT-HANDLE4-NEXT: print("c")
// BOOL-DONT-HANDLE4-NEXT: }
// We cannot use refactor-check-compiles, as a placeholder cannot be force unwrapped.
// 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=BOOL-WITH-ERR-SILLY %s
boolWithErr { success, err in
if success == false && err == nil {
print("ummm wat \(err!)")
return
}
print("not err")
}
// BOOL-WITH-ERR-SILLY: let success = try await boolWithErr()
// BOOL-WITH-ERR-SILLY-NEXT: if success == false && <#err#> == nil {
// BOOL-WITH-ERR-SILLY-NEXT: print("ummm wat \(<#err#>!)")
// BOOL-WITH-ERR-SILLY-NEXT: <#return#>
// BOOL-WITH-ERR-SILLY-NEXT: }
// BOOL-WITH-ERR-SILLY-NEXT: print("not err")
// We cannot use refactor-check-compiles, as a placeholder cannot be force unwrapped.
// 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=BOOL-WITH-ERR-SILLY2 %s
boolWithErr { success, err in
if success {
print("ummm wat \(err!)")
} else {
print("ummm wat \(err!)")
}
}
// The err unwrap is in both blocks, so it's not clear what to classify as.
// BOOL-WITH-ERR-SILLY2: let success = try await boolWithErr()
// BOOL-WITH-ERR-SILLY2-NEXT: if success {
// BOOL-WITH-ERR-SILLY2-NEXT: print("ummm wat \(<#err#>!)")
// BOOL-WITH-ERR-SILLY2-NEXT: } else {
// BOOL-WITH-ERR-SILLY2-NEXT: print("ummm wat \(<#err#>!)")
// BOOL-WITH-ERR-SILLY2-NEXT: }
// 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=MULTI-BOOL-WITH-ERR %s
multipleBoolWithErr { str, b1, b2, err in
if !b1 && !b2 {
print("a \(err!)")
}
if b1, b2 {
print("b \(err!)")
}
if !b1 {
print("c \(err!)")
}
if !b2 {
print("d \(err!)")
}
}
// Don't handle the case where multiple flag checks are done in a single
// condition, because it's not exactly clear what the user is doing. It's a
// little unfortunate that we'll allow multiple flag checks in separate
// conditions, but both of these cases seem somewhat uncommon, and there's no
// real way to completely enforce a single flag param across e.g multiple calls
// to the same function, so this is probably okay for now.
// MULTI-BOOL-WITH-ERR: do {
// MULTI-BOOL-WITH-ERR-NEXT: let (str, b1, b2) = try await multipleBoolWithErr()
// MULTI-BOOL-WITH-ERR-NEXT: } catch let err {
// MULTI-BOOL-WITH-ERR-NEXT: if !<#b1#> && !<#b2#> {
// MULTI-BOOL-WITH-ERR-NEXT: print("a \(err)")
// MULTI-BOOL-WITH-ERR-NEXT: }
// MULTI-BOOL-WITH-ERR-NEXT: if <#b1#>, <#b2#> {
// MULTI-BOOL-WITH-ERR-NEXT: print("b \(err)")
// MULTI-BOOL-WITH-ERR-NEXT: }
// MULTI-BOOL-WITH-ERR-NEXT: print("c \(err)")
// MULTI-BOOL-WITH-ERR-NEXT: print("d \(err)")
// MULTI-BOOL-WITH-ERR-NEXT: }
// We cannot use refactor-check-compiles, as a placeholder cannot be force unwrapped.
// 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=OPT-BOOL-WITH-ERR %s
optionalBoolWithErr { str, optBool, b, err in
if optBool != nil {
print("a \(err!)")
}
if optBool == nil {
print("b \(err!)")
}
if optBool == true {
print("c \(err!)")
}
if ((optBool) == (false)) {
print("d \(err!)")
}
if optBool == false {
print("e \(String(describing: err))")
}
if optBool != true {
print("f \(err!)")
}
if b {
print("g \(err!)")
}
}
// It's a little unfortunate that print("a \(<#err#>!)") gets classified in the success
// block below, but it doesn't seem like a case that's likely to come up, as optBool
// would then be inaccessible in the error block.
// OPT-BOOL-WITH-ERR: do {
// OPT-BOOL-WITH-ERR-NEXT: let (str, optBool, b) = try await optionalBoolWithErr()
// OPT-BOOL-WITH-ERR-NEXT: print("a \(<#err#>!)")
// OPT-BOOL-WITH-ERR-NEXT: if <#optBool#> == false {
// OPT-BOOL-WITH-ERR-NEXT: print("e \(String(describing: <#err#>))")
// OPT-BOOL-WITH-ERR-NEXT: }
// OPT-BOOL-WITH-ERR-NEXT: if <#optBool#> != true {
// OPT-BOOL-WITH-ERR-NEXT: print("f \(<#err#>!)")
// OPT-BOOL-WITH-ERR-NEXT: }
// OPT-BOOL-WITH-ERR-NEXT: } catch let err {
// OPT-BOOL-WITH-ERR-NEXT: print("b \(err)")
// OPT-BOOL-WITH-ERR-NEXT: print("c \(err)")
// OPT-BOOL-WITH-ERR-NEXT: print("d \(err)")
// OPT-BOOL-WITH-ERR-NEXT: print("g \(err)")
// OPT-BOOL-WITH-ERR-NEXT: }
// 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
ClassWithHandlerMethods.firstBoolFlagSuccess("") { str, success, unrelated, err in
if !unrelated {
print(err!)
}
if !success {
print("oh no")
}
if !success {
print(err!)
}
if success {
print("woo")
}
if str != nil {
print("also woo")
}
}
// OBJC-BOOL-WITH-ERR: do {
// OBJC-BOOL-WITH-ERR-NEXT: let (str, unrelated) = try await ClassWithHandlerMethods.firstBoolFlagSuccess("")
// OBJC-BOOL-WITH-ERR-NEXT: if !unrelated {
// OBJC-BOOL-WITH-ERR-NEXT: print(<#err#>!)
// OBJC-BOOL-WITH-ERR-NEXT: }
// OBJC-BOOL-WITH-ERR-NEXT: print("woo")
// OBJC-BOOL-WITH-ERR-NEXT: print("also woo")
// OBJC-BOOL-WITH-ERR-NEXT: } catch let err {
// OBJC-BOOL-WITH-ERR-NEXT: print("oh no")
// OBJC-BOOL-WITH-ERR-NEXT: print(err)
// OBJC-BOOL-WITH-ERR-NEXT: }
// 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
ClassWithHandlerMethods.secondBoolFlagFailure("") { str, unrelated, failure, err in
if unrelated {
print(err!)
}
if failure {
print("oh no")
}
if failure {
print(err!)
}
if !failure {
print("woo")
}
if str != nil {
print("also woo")
}
if failure && err == nil {
print("wat")
}
if failure && err != nil {
print("neat")
}
if failure, let _ = err {
print("neato")
}
}
// OBJC-BOOL-WITH-ERR2: do {
// OBJC-BOOL-WITH-ERR2-NEXT: let (str, unrelated) = try await ClassWithHandlerMethods.secondBoolFlagFailure("")
// OBJC-BOOL-WITH-ERR2-NEXT: if unrelated {
// OBJC-BOOL-WITH-ERR2-NEXT: print(<#err#>!)
// OBJC-BOOL-WITH-ERR2-NEXT: }
// OBJC-BOOL-WITH-ERR2-NEXT: print("woo")
// OBJC-BOOL-WITH-ERR2-NEXT: print("also woo")
// OBJC-BOOL-WITH-ERR2-NEXT: if <#failure#> && <#err#> == nil {
// OBJC-BOOL-WITH-ERR2-NEXT: print("wat")
// OBJC-BOOL-WITH-ERR2-NEXT: }
// OBJC-BOOL-WITH-ERR2-NEXT: } catch let err {
// OBJC-BOOL-WITH-ERR2-NEXT: print("oh no")
// OBJC-BOOL-WITH-ERR2-NEXT: print(err)
// OBJC-BOOL-WITH-ERR2-NEXT: print("neat")
// OBJC-BOOL-WITH-ERR2-NEXT: print("neato")
// OBJC-BOOL-WITH-ERR2-NEXT: }
// 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-FALLBACK %s
ClassWithHandlerMethods.firstBoolFlagSuccess("") { str, success, unrelated, err in
guard success && success == .random() else { fatalError() }
print("much success", unrelated, str)
}
// OBJC-BOOL-WITH-ERR-FALLBACK: var str: String? = nil
// OBJC-BOOL-WITH-ERR-FALLBACK-NEXT: let success: Bool
// OBJC-BOOL-WITH-ERR-FALLBACK-NEXT: var unrelated: Bool? = nil
// OBJC-BOOL-WITH-ERR-FALLBACK-NEXT: var err: (any Error)? = nil
// OBJC-BOOL-WITH-ERR-FALLBACK-NEXT: do {
// OBJC-BOOL-WITH-ERR-FALLBACK-NEXT: (str, unrelated) = try await ClassWithHandlerMethods.firstBoolFlagSuccess("")
// OBJC-BOOL-WITH-ERR-FALLBACK-NEXT: success = true
// OBJC-BOOL-WITH-ERR-FALLBACK-NEXT: } catch {
// OBJC-BOOL-WITH-ERR-FALLBACK-NEXT: err = error
// OBJC-BOOL-WITH-ERR-FALLBACK-NEXT: success = false
// OBJC-BOOL-WITH-ERR-FALLBACK-NEXT: }
// OBJC-BOOL-WITH-ERR-FALLBACK-EMPTY:
// OBJC-BOOL-WITH-ERR-FALLBACK-NEXT: guard success && success == .random() else { fatalError() }
// OBJC-BOOL-WITH-ERR-FALLBACK-NEXT: print("much success", unrelated, str)
// 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-FALLBACK2 %s
ClassWithHandlerMethods.secondBoolFlagFailure("") { str, unrelated, failure, err in
guard !failure && failure == .random() else { fatalError() }
print("much fails", unrelated, str)
}
// OBJC-BOOL-WITH-ERR-FALLBACK2: var str: String? = nil
// OBJC-BOOL-WITH-ERR-FALLBACK2-NEXT: var unrelated: Bool? = nil
// OBJC-BOOL-WITH-ERR-FALLBACK2-NEXT: let failure: Bool
// OBJC-BOOL-WITH-ERR-FALLBACK2-NEXT: var err: (any Error)? = nil
// OBJC-BOOL-WITH-ERR-FALLBACK2-NEXT: do {
// OBJC-BOOL-WITH-ERR-FALLBACK2-NEXT: (str, unrelated) = try await ClassWithHandlerMethods.secondBoolFlagFailure("")
// OBJC-BOOL-WITH-ERR-FALLBACK2-NEXT: failure = false
// OBJC-BOOL-WITH-ERR-FALLBACK2-NEXT: } catch {
// OBJC-BOOL-WITH-ERR-FALLBACK2-NEXT: err = error
// OBJC-BOOL-WITH-ERR-FALLBACK2-NEXT: failure = true
// OBJC-BOOL-WITH-ERR-FALLBACK2-NEXT: }
// OBJC-BOOL-WITH-ERR-FALLBACK2-EMPTY:
// OBJC-BOOL-WITH-ERR-FALLBACK2-NEXT: guard !failure && failure == .random() else { fatalError() }
// OBJC-BOOL-WITH-ERR-FALLBACK2-NEXT: print("much fails", unrelated, str)
}
|