-
Notifications
You must be signed in to change notification settings - Fork 289
Generate swift CaseIterable for simple enums and errors #2489
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
Conversation
I'm interested to know why this wouldn't need a config option whereas, say, |
Yes, why not. I have added a config flag similar to the one about In general the default conformance autogenerated by swift should not produce anything out-of-ordinary. Similar to the automatic generation of |
mhammond
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, this is great - I like that it's enabled by default rather than opt-in as it seems useful and something we should maybe do in #2490?
I'm mildly confused by the contains_variant_fields rather than object_references checks though?
|
|
||
| {% if !config.omit_case_iterable_conformance() && !e.is_flat() && !e.contains_variant_fields() %} | ||
| extension {{ type_name }}: CaseIterable {} | ||
| {% endif %} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nano-nit, please fix this eol
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should be OK now
The public enum ConnectionEventEnum {
case dummy
case connected(deviceAddress: String)
case disconnected(deviceAddress: String)
}
extension ConnectionEventEnum: CaseIterable {} // ERROR, this will not compile, because some variants contain fields
public enum AnimalEnum {
case dog
case cat
}
extension AnimalEnum: CaseIterable {} // OK here, all variants are simple (no additional fields) |
mhammond
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given the discussion in #2490, we want to default this to off, right? cc @crazytonyli . And any chance of a changelog note for both PRs? :)
…se_iterable # Conflicts: # docs/manual/src/swift/configuration.md # uniffi_bindgen/src/bindings/swift/gen_swift/mod.rs
|
I have changed the config setting to off-by-default and renamed to |
mhammond
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the delay, thank you for your patience!
Co-authored-by: Pavel Zarecky <zarecky@procivis.ch>
Identifying enums that conform to the
CaseIterableprotocol is relatively simple, so we probably can autogenerate the swift protocol conformance code without any risks.Potentially we could add a new config toggle specifically for this protocol.