Generate swift CaseIterable for simple enums and errors#2489
Generate swift CaseIterable for simple enums and errors#2489mhammond merged 6 commits intomozilla:mainfrom
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.
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 %} No newline at end of file |
There was a problem hiding this comment.
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.
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.
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.