swiftlang / swift

The Swift Programming Language
https://swift.org
Apache License 2.0
67.41k stars 10.34k forks source link

[SR-1253] Convenience initializer which never calls designated initializer should not be compillable #43861

Open swift-ci opened 8 years ago

swift-ci commented 8 years ago
Previous ID SR-1253
Radar None
Original Reporter akio0911 (JIRA User)
Type Improvement
Additional Detail from JIRA | | | |------------------|-----------------| |Votes | 0 | |Component/s | Compiler | |Labels | Improvement | |Assignee | None | |Priority | Medium | md5: ee18870e8b6864c932de09b6b386518c

Issue Description:

class Food {
    var name: String

    init(name: String) {
        self.name = name
    }

    // This convenience initializer never calls designated initializer.
    // But this code is compilable. 
    convenience init() {
        self.init() 
    }
}

let food = Food()
belkadan commented 8 years ago

Convenience initializers are allowed to chain to other convenience initializers, and I don't think we can solve the problem in general. But we could certainly prohibit a convenience initializer that only chains to itself.

Dante-Broggi commented 6 years ago

Is this resolved? If so, this should be closed.