[SR-11043] Crash on swift_getObjectType on usage of [weak self] or [unowned self] in closures after required initialziation in @objc convenience init #53432
Labels
bug
A deviation from expected or documented behavior. Also: expected but undesirable behavior.
compiler
The Swift compiler in itself
crash
Bug: A crash, i.e., an abnormal termination of software
regression
run-time crash
Bug → crash: Swift code crashed during execution
swift 5.0
Attachment: Download
Environment
$ swift --version
Apple Swift version 5.0.1 (swiftlang-1001.0.82.4 clang-1001.0.46.5)
Target: x86_64-apple-darwin18.6.0
Reproducible with Xcode 10.2.1. Not reproducible with Swift 4.2.
Additional Detail from JIRA
md5: a5490d8dbd341cfc4cbf7da1454a5fc3
Issue Description:
After switching to Swift 5, we faced a crash in our code base that could be minimized down to the sample below.
The sample is tailored for execution in playground or for invocation with "swift xxx.swift". There's also an macOS project demonstrating the same crash (attached) (also available on GitHub). You can make iOS project and crash it with similar code as well.
This does crash:
Removal of
@objc
from the convenience initializer makes it not crash/behave as expected.Removal of
[weak self]
from the closure makes it not crash/behave as expected.Removal of property
.foo
seems to solve the problem as well.It doesn't crash if you replace
weak
withunowned
in the above example, but I believe that in our real case, it still crashes even withunowned
.Switching to Swift 4.2 or Swift 5.1 (swiftlang-1100.0.43.3 clang-1100.0.26.3) resolves the problem.
Moving the closure creation to a separate method like below makes it behave as expected:
The text was updated successfully, but these errors were encountered: