You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is my first post, so please let me know if I have any mistakes in the filing process 🙂.
I'd like to propose an idea for Swift. Essentially, my idea would pertain to the scenario when you have a struct/class when you have static members used for initialization. Imagine the following example:
structSection{publicprivate(set) base: Int
staticvarmain:Section{Section(base:0)}staticvarsecondary:Section{Section(base:1)}}letsection=Section.main
switch section {case.main:print("main")case.secondary:print("secondary")default:print("This should never happen")}
When switching through an instance of Section, you must define a default case, even though the default case should never have to be called. One possibility would be the introduction of 'case' members that would replace the static member initializers. Imagine:
@exhaustiblestructSection{publicprivate(set)letbase:Intpublicprivate(set)letdescription:String?=nil
case varmain:Section{Section(base:0)}
case varsecondary:Section{Section(base:1)}
case func tertiary(description:String){Section(base:2, description: description)}}letsection=Section.main
switch section {case.main:print("main")case.secondary:print("secondary")case.tertiary(let description):print("tertiary: \(description)")}
This implementation would (somehow) allow for the compiler to recognize that these methods should be used for switch statements and remove the need for default cases if the type uses a hypothetical `exhaustible` attribute.
An alternative idea would be to have an `Exhaustible` protocol:
protocolExhaustible{staticvar cases:[Self]}structSection:Exhaustible{publicprivate(set) base: Int
staticvarmain:Section{Section(base:0)}staticvarsecondary:Section{Section(base:1)}staticvarcases:[Section]{[.main,.secondary]}}letsection=Section.main
switch section {case.main:print("main")case.secondary:print("secondary")}
Then perhaps the compiler could (somehow) know that a default case is not needed. I do not know how this could look/work with static functions (such as the tertiary case).
Maybe this isn't a good idea or has been suggested before, but I couldn't find anything online. If anyone has feedback, I'd love to hear it! 🙂.
The text was updated successfully, but these errors were encountered:
Additional Detail from JIRA
md5: 976bf074a3f76098f22719cc2c027066
Issue Description:
This is my first post, so please let me know if I have any mistakes in the filing process 🙂.
I'd like to propose an idea for Swift. Essentially, my idea would pertain to the scenario when you have a struct/class when you have static members used for initialization. Imagine the following example:
When switching through an instance of Section, you must define a default case, even though the default case should never have to be called. One possibility would be the introduction of 'case' members that would replace the static member initializers. Imagine:
This implementation would (somehow) allow for the compiler to recognize that these methods should be used for switch statements and remove the need for default cases if the type uses a hypothetical `exhaustible` attribute.
An alternative idea would be to have an `Exhaustible` protocol:
Then perhaps the compiler could (somehow) know that a default case is not needed. I do not know how this could look/work with static functions (such as the tertiary case).
Maybe this isn't a good idea or has been suggested before, but I couldn't find anything online. If anyone has feedback, I'd love to hear it! 🙂.
The text was updated successfully, but these errors were encountered: