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-3170] Enum cases should satisfy static var {get} protocol requirements #45758

Closed
lilyball mannequin opened this issue Nov 9, 2016 · 3 comments
Closed

[SR-3170] Enum cases should satisfy static var {get} protocol requirements #45758

lilyball mannequin opened this issue Nov 9, 2016 · 3 comments

Comments

@lilyball
Copy link
Mannequin

lilyball mannequin commented Nov 9, 2016

Previous ID SR-3170
Radar None
Original Reporter @lilyball
Type Improvement
Status Resolved
Resolution Done
Additional Detail from JIRA
Votes 5
Component/s Compiler
Labels Improvement
Assignee @theblixguy
Priority Medium

md5: d9521650445f1899139f2653dbcaffff

is duplicated by:

  • SR-3510 Allow Enum case to conform to a protocol static function and static variable
  • SR-9099 Enum case does not satisfy protocol static var

Issue Description:

Outside of pattern-matching, enum cases are used the same way static let properties are. To that end, they should be able to satisfy protocol requirements for static var { get } properties.

For example:

protocol Foo {
    static var bar: Self { get }
}

enum Baz: Foo {
    case bar
}

Right now this gives the following error:

unnamed.swift:5:6: error: type 'Baz' does not conform to protocol 'Foo'
enum Baz: Foo {
     ^
unnamed.swift:2:16: note: protocol requires property 'bar' with type 'Baz'; do you want to add a stub?
    static var bar: Self { get }
               ^
unnamed.swift:6:10: note: candidate is not a variable
    case bar
         ^
@belkadan
Copy link
Contributor

belkadan commented Jan 4, 2017

The dup mentions cases with payloads matching static function requirements.

@DevAndArtist
Copy link
Mannequin

DevAndArtist mannequin commented Feb 15, 2019

@slavapestov sorry, I was trying to type a comment, but Jira triggered some weird key-combo and assigned me to the ticket.


The improvement in that area should not only be limited to static properties right?

protocol Foo {
  static func baz(_ something: Int) -> Self
  static func abc(label: String) -> Self
}

enum Baz: Foo {
  case baz(Int)
  case abc(label: String)
}

@theblixguy
Copy link
Collaborator

theblixguy commented Mar 28, 2020

Implemented on master: #28916

Please verify using the next available snapshot.

@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
Projects
None yet
Development

No branches or pull requests

2 participants