❯ xcodebuild -version
Build version 11B52
❯ swift --version
Apple Swift version 5.1.2 (swiftlang-1100.0.278 clang-1188.8.131.52)
Issue occurs on iOS 13.2 simulators and devices. Issue does not occur on macOS 10.15. Have not tested other situations.
I've hit an issue where a custom subscript I defined on a type in one of my Swift packages is causing a crash when running on iOS, but not on macOS (either with Catalyst or not).
I've attached a minimal reproduction package, which only shows the issue when running the tests in Xcode on an iOS simulator or device. In my real use case, this issue reproduces in both test cases and when using the package from an app.
I've reduced it down to a class shaped something like this:
The crash is triggered by creating a new instance and setting the subscript with any key/value.
The following details I've found to be important (removing any of them makes the crash go away):
- The class must be generic
- The class must have a private variable
- The class must be non-final
- The class must live in a module of a Swift package (the same use case with a class in an iOS framework linked by an app does not reproduce the issue)
I've seen the crash on a stack frame like this:
#0 0x00000001060a1099 in method descriptor for UserActions.Context.subscript.modify
In the attached test case, it's much weirder, as it's referencing a different type than the one the subscript is being called on:
#0 0x0000000102a3aba8 in direct field offset for NotCrashy.data ()