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-3510] Allow Enum case to conform to a protocol static function and static variable #46098

Closed
swift-ci opened this issue Dec 30, 2016 · 0 comments
Assignees
Labels
compiler The Swift compiler in itself improvement

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-3510
Radar None
Original Reporter hanjustin (JIRA User)
Type Improvement
Status Resolved
Resolution Duplicate
Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Improvement
Assignee @slavapestov
Priority Medium

md5: 58619f930d98188e216158a195bf28e0

duplicates:

  • SR-3170 Enum cases should satisfy static var {get} protocol requirements

Issue Description:

I would like to use enum's case to conform to protocol.
I would be happy even if only the first example was possible...

// Example 1

protocol ShapeCreator {
    static func objectWith(area: Int) -> Self
}

enum TheCreator: ShapeCreator {
    case objectWith(area: Int)
}

TheCreator.objectWith(area: 99)

// Example 2

protocol ShapeCreator {
    static var defaultCreator: Self { get }
    func createStuff()
}

enum CreatorWithDefault: ShapeCreator {
    case defaultCreator

    func createStuff()
}

CreatorWithDefault.defaultCreator.createStuff()

// Example 3
// This probably is a bit of a stretch

protocol ShapeCreator {
    static var defaultArea: Int
}

enum Default: Int, ShapeCreator {
    case defaultArea = 100
}


@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
compiler The Swift compiler in itself improvement
Projects
None yet
Development

No branches or pull requests

1 participant