Open 05262b81-54a9-4fe1-bf6a-96f8042de10e opened 5 years ago
I realize this is a change that needs to be made on the Obj-C side, which hopefully zero changes on the Swift side (as a closed enum is ultimately just an attribute, which the NS_CLOSED_ERROR_ENUM
macro would add), but since the previous macros were driven by Swift needs I figured it was appropriate to put this here. And who knows, maybe we need to teach ClangImporter about this new macro anyway, as I seem to recall it knew how to identify previous Swift-compatibility macros for some reason.
Yeah, these days you can construct it yourself with the two attributes enum_extensibility(closed)
and ns_error_domain(…)
. I don't think we considered NS_CLOSED_ERROR_ENUM
at the time because it's rare to switch exhaustively over an error enum (and will likely never happen for any of Apple's public error enums), but I guess it's something you can do if you control the enum too.
Since there's nothing to change on the Swift side, do you want to file the Radar or should I?
If you're willing to file the radar, I'd appreciate that. Thanks!
Additional Detail from JIRA
| | | |------------------|-----------------| |Votes | 0 | |Component/s | | |Labels | Improvement | |Assignee | None | |Priority | Medium | md5: 3121bbee1a033124a692365436f30c0eIssue Description:
In order to interoperate with Swift, Obj-C gained the
NS_CLOSED_ENUM
macro for declaring a C enum that has "closed" semantics, and it gained theNS_ERROR_ENUM
macro for declaring a set ofNSError
error codes that automatically get wrapped into a Swift error type. Unfortunately there seems to be noNS_CLOSED_ERROR_ENUM
, which means when I consume the Swift error type I need an@unknown default
case despite the error type originating from my own application code.Just as we support
NS_CLOSED_ENUM
both for application developers and for libraries that promise to never introduce new cases, we should supportNS_CLOSED_ERROR_ENUM
.