Hi,
We are getting crashes in code that has worked fine for the last 1.5 years and which by all means looks legal to us.
Since Upgrading to Xcode 13.3 the following two code examples crash on iPhone & Simulator and MacOS.
They work fine when compiling with Xcode 13.2.1:
fileprivate typealias Closure = () -> Void
func crash1() {
let closure1: Closure? = nil
let closure2: Closure? = nil
let closure3: Closure? = nil
print("Closures: \(String(describing: closure1)), \(String(describing: closure2)), \(String(describing: closure3))")
let closure = closure1 ?? closure2 ?? closure3
print("\(#line): \(String(describing: closure))")
closure?() // <- EXC_BAD_ACCESS
assert(closure == nil)
}
func crash2() {
let closure1: Closure? = nil
let closure2: Closure? = nil
let closure3: Closure? = { }
print("Closures: \(String(describing: closure1)), \(String(describing: closure2)), \(String(describing: closure3))")
let closure = closure1 ?? closure2 ?? closure3
print("\(#line): \(String(describing: closure))")
closure?() // <- EXC_BAD_ACCESS
assert(closure != nil)
}
The resulting closure
has a value of Optional((Function))
in both cases, but it is corrupted, i.e. crashes on use. Please not the it should be nil
in the first example, after all.
Note: The Code apparently works in a playground (albeit sometimes the playground simply hangs), but not in an iOS (UIKit/SwiftUI) or MacOS (SwiftUI or command line tool) project.
No crashes when:
a) using only two optionals in a row:
let closure = closure1 ?? closure2
or b) when using parentheses:
let closure = (closure1 ?? closure2) ?? closure3
Known issue?
Radar?
Any ideas?
Thanks,
Lars