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:Intstaticvar main: Section {
Section(base: 0)
}
staticvar secondary: Section {
Section(base: 1)
}
}
let section = Section.mainswitch 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) let base: Intpublicprivate(set) let description: String?=nilcasevar main: Section {
Section(base: 0)
}
casevar secondary: Section {
Section(base: 1)
}
casefunctertiary(description: String) {
Section(base: 2, description: description)
}
}
let section = Section.mainswitch 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:
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: