swiftlang / swift

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

[SR-11188] New abstract keyword for classes #53585

Open swift-ci opened 5 years ago

swift-ci commented 5 years ago
Previous ID SR-11188
Radar None
Original Reporter ColinRoache (JIRA User)
Type New Feature
Additional Detail from JIRA | | | |------------------|-----------------| |Votes | 0 | |Component/s | | |Labels | New Feature, LanguageFeatureRequest | |Assignee | None | |Priority | Medium | md5: 3568221af408b2c86b03354637ddf549

Issue Description:

I have found numerous instances in which I would like to provide partial protocol conformance in a superclass, while leaving some of the protocol requirements unfulfilled. Traditionally this is called a partially abstract class. While Swift's protocols act as traditional purely abstract classes/structs, it would be helpful to have partially abstract classes/structs which leave some requirements for descendants to fulfill.

I would expect that abstract classes and abstract structs could not be directly initialized and that the init methods could only be called from subclasses' init methods.

I would like to use an abstract keyword like this:

internal
protocol
Plant
{

    var plant_genus   : String
    { get }
    var plant_species : String
    { get }

}

internal
abstract
struct
Astragalus
: Plant
{

    internal var plant_genus : String
    { return "Astragalus" }

}

internal
strict
AstragalusAlpinus
: Astragalus
{

     internal var plant_species : String
     { return "Astragalus alpinus" }

}
belkadan commented 5 years ago

This change would have to go through the Swift Evolution Process. Note that it's come up several times before, so I recommend familiarizing yourself with previous discussions on the forums before writing a pitch.

swift-ci commented 5 years ago

Comment by Colin Roache (JIRA)

@belkadan I have enough of my own code to write, I'm just pointing out the issues remaining in Swift from a type theory perspective.