[SR-9947] EXC_BAD_ACCESS stemming from protocol definition not including class, but including class-based restraint #52350
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
run-time crash
Bug → crash: Swift code crashed during execution
runtime
The Swift Runtime
Attachment: Download
Environment
Xcode 10.1 (10B61)
Swift 4.2.1
macOS 10.13.6 (17G5019)
Additional Detail from JIRA
md5: 6e55766998aa375ab1d917246fb28b04
Issue Description:
A crash named EXC_BAD_ACCESS occurs with the following setup:
Swift 4.2.1 (as bundled with Xcode 10.1)
A protocol which is not class-bound, but which has a
where
clause requiring it to inherit from any other classA class which conforms to the aforementioned protocol
A variable or constant whose type is explicitly the aforementioned protocol, and whose instance is of the aforementioned class
A call to the protocol-required function or variable of the aforementioned variable
Expected outcome
Calling the function or variable requirement on the implementation instance will actually call said function or variable
Actual outcome
Attempting to perform such a call results in EXC_BAD_ACCESS
Known workarounds
On the protocol, add
: class
to make it class-bound. This is not always possible as it results in a Swift compiler warning, and some projects/businesses require "Treat Warnings As Errors" be set to "Yes", which will cause this to fail a compile attemptOn the variable declaration, explicitly type it to the implementation class' type. This is not always possible as that type is not always knowable at that time of writing (e.g. implementation class might be
internal
to some other framework)SSCCE
The text was updated successfully, but these errors were encountered: