I'm seeing a really weird issue where objects get corrupted when using generics on the iOS 9.2/9.3 simulators. I've attached an Xcode project showing the issue. Also I've reproduced the problematic part of the code below:
class MainObject: NSObject {
let a = BaseView<Double>()
let b = BaseView<Int>()
override init() {
super.init()
a.label.text = "HELLO" // Crash here on iOS 9 simulator
// Change type of b to BaseView<Int>() - doesn't crash
}
}
class BaseView<T>: UIView {
private let x = UIPickerView()
let label: UILabel = UILabel()
private var value : T?
}
It looks like the initialisation of 'b' in MainObject is causing 'a' to become corrupted. The crash is:
2017-04-25 13:31:41.687 Test[13321:33688179] -[UIPickerView setText:]: unrecognized selector sent to instance 0x7af38670
It appears that when trying to read the label property we actually end up reading the x property instead. I suspect this is something to do with the difference in the sizing of the specialisation (Int vs Double); if I change both a and b to be of type BaseView<Double>, then problem goes away.
Other observations:
This only seems to occur in the iOS 9.2/9.3 simulator
It doesn't crash on an iOS 9.2 device (although this may be chance)
iOS 10 simulator is fine
I'm not sure if this is a platform issue or a swift one
Problem was seen in both Xcode 8.2.1 and Xcode 8.3.2
Attachment: Download
Environment
Xcode 8.3.2, iOS 9.2/9.3 simulatorAdditional Detail from JIRA
| | | |------------------|-----------------| |Votes | 0 | |Component/s | Compiler | |Labels | Bug, Miscompile, RunTimeCrash | |Assignee | None | |Priority | Medium | md5: e174098a42cc35c0971bb5029f815063Issue Description:
I'm seeing a really weird issue where objects get corrupted when using generics on the iOS 9.2/9.3 simulators. I've attached an Xcode project showing the issue. Also I've reproduced the problematic part of the code below:
It looks like the initialisation of 'b' in MainObject is causing 'a' to become corrupted. The crash is:
It appears that when trying to read the label property we actually end up reading the x property instead. I suspect this is something to do with the difference in the sizing of the specialisation (Int vs Double); if I change both a and b to be of type
BaseView<Double>
, then problem goes away.Other observations:
This only seems to occur in the iOS 9.2/9.3 simulator
It doesn't crash on an iOS 9.2 device (although this may be chance)
iOS 10 simulator is fine
I'm not sure if this is a platform issue or a swift one
Problem was seen in both Xcode 8.2.1 and Xcode 8.3.2