[SR-9176] Object Over-Released when enum case with associated value T is passed as closure to function operating over a generic specializing T #51667
Labels
access control
Feature → modifiers: Access control and access levels
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 4.2
Attachment: Download
Environment
Xcode 10.1 (10B61)
Swift 4.0, 4.2
macOS 10.13.6, 10.14
Additional Detail from JIRA
md5: e3edd86a852ba61276c0ea3eb81b3582
Issue Description:
Sorry if my description is not the most accurate, but it's not an easy one to describe 😛
When passing an
enum
's case with associated valueT
as a closure to another function (i.e. to "wrap" aT
and create a newenum
instance), if the typeT
is anassociatedtype
on a protocol (specialized in the generic of the function's parent type), an over-release is made, causing aEXC_BAD_ACCESS
runtime crash.I've only observed this issue since Xcode 10 (also present in 10.1), in both Swift 4 and Swift 4.2 modes. On Xcode 9 the same code worked without any issues, and since the code is valid Swift I am led to believe that this is most likely a compiler regression.
When this issue started occurring I analyzed the app with the Zombies Instrument and discovered that an additional release was being generated when the
enum
's case is used as a parameter.I've managed to create a reduced example which demonstrates the issue:
I've atached a demo app demonstrating the issue, but it's also manifested on a playground (even though it may require a small change so that the
result
lives a bit longer).The text was updated successfully, but these errors were encountered: