Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SR-4687] Object corruption when generics are used with UIView on iOS 9 simulators #47264

Closed
swift-ci opened this issue Apr 25, 2017 · 2 comments
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

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-4687
Radar rdar://problem/31813495
Original Reporter mjholgate (JIRA User)
Type Bug
Status Resolved
Resolution Done

Attachment: Download

Environment

Xcode 8.3.2, iOS 9.2/9.3 simulator

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, Miscompile, RunTimeCrash
Assignee None
Priority Medium

md5: e174098a42cc35c0971bb5029f815063

Issue 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:

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

@belkadan
Copy link
Contributor

@swift-ci create

@aschwaighofer
Copy link
Member

#9945

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@AnthonyLatsis AnthonyLatsis added the crash Bug: A crash, i.e., an abnormal termination of software label Dec 12, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
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
Projects
None yet
Development

No branches or pull requests

4 participants