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-1097] Failable convenience initializer in extension of objc class crashes #4362

Closed
swift-ci opened this issue Mar 29, 2016 · 1 comment
Closed

Comments

@swift-ci
Copy link
Contributor

Previous ID SR-1097
Radar None
Original Reporter dunkelstern (JIRA User)
Type Bug
Status Resolved
Resolution Duplicate
Environment

Xcode 7.3 with default Toolchain. Compiling for OSX or iPhone.

Additional Detail from JIRA
Votes 0
Component/s Foundation
Labels Bug, 2.2Regression, RunTimeCrash
Assignee None
Priority Medium

md5: 77c9b902eace624d2a5a36f9f5e7c34d

duplicates:

  • SR-704 EXC_BAD_ACCESS on returning nil from a failable initializer of NSObject subclass

Issue Description:

Let me just give a speedy example (you can do it in a playground):

import Cocoa

public extension NSDate {
    public convenience init?(fail: Bool) {
        return nil
    }
}

let date = NSDate(fail: true)

Expectation: date is nil
Result: Program crashes with EXC_BAD_ACCESS

When you do this on a pure Swift class like the following, everything works:

public class X {
}

extension X {
    public convenience init?(fail: Bool) {
        return nil
    }
}

let x = X(fail: true)
@swift-ci
Copy link
Contributor Author

Comment by Johannes Schriewer (JIRA)

When throwing from a convenience initializer it crashes too:

enum DateError: ErrorType {
    case Error
}

public extension NSDate {
    public convenience init(fail: Bool) throws {
        throw DateError.Error
    }
}

let date = try NSDate(fail: true)

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@shahmishal shahmishal transferred this issue from apple/swift May 5, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant