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-10958] Swift 5 regression with init delegation #53346

Closed
Agarunov opened this issue Jun 17, 2019 · 1 comment
Closed

[SR-10958] Swift 5 regression with init delegation #53346

Agarunov opened this issue Jun 17, 2019 · 1 comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. regression swift 5.0

Comments

@Agarunov
Copy link

Previous ID SR-10958
Radar None
Original Reporter @Agarunov
Type Bug
Status Resolved
Resolution Duplicate
Environment

Swift 5, Xcode 10.2.1

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

md5: 85c26fbcc1ffdd9b673d166f1f2d0ca4

duplicates:

  • SR-10285 Subclass of a class that conforms to a protocol and extends NSObject is not instantiate correctly

Issue Description:

In Swift 5, Xcode 10.2.1 this code crashes, because foo method invokes Base.init instead of Derived.init. But in Swift 4.2 no issues.

protocol EmptyInitInitializable {
    init()
}

protocol StaticFoo {
    static func foo()
}

extension StaticFoo where Self: EmptyInitInitializable {
    static func foo() {
        _ = self.init()
    }
}

class Base: NSObject, EmptyInitInitializable, StaticFoo {
    
    let value: Bool
    
    init(value: Bool) {
        self.value = value
        super.init()
    }
    
    required override init() {
        fatalError("init() has not been implemented")
    }
}

class Derived: Base {
    required init() {
        super.init(value: true)
    }
}

Derived.foo() // error: Fatal error: init() has not been implemented

But if we add convenience modifier to Base.init - no issues:

class Base: NSObject, EmptyInitInitializable, StaticFoo {
    
    let value: Bool
    
    init(value: Bool) {
        self.value = value
        super.init()
    }
    
    required override convenience init() { // convenience
        fatalError("init() has not been implemented")
    }
}
@belkadan
Copy link
Contributor

Fixed in Xcode 11!

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 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. regression swift 5.0
Projects
None yet
Development

No branches or pull requests

3 participants