-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[SR-6753] CodingUserInfoKey's init?(rawValue:) shouldn't be failable #49302
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
Comments
cc @itaiferber. I'm happy to fix this myself if you want, although what would be the best way to minimise source-breakage for the failable to non-failable init? Unfortunately,
Is there a way around this? Or is it simply not worth fixing this, and better to just add a non-failable |
@hamishknight Good catch, Hamish! I believe this is a typo in the proposal, though.
while the second looks like
I think the non-failable Since Is this preventing you from doing anything with the type? |
@itaiferber It's not preventing any usage of the type, but having a failable initialiser that never fails feels pretty unsatisfactory. For any failable initialiser, the developer has to reason about the exact cases under which it returns It's also worth noting that there's an example in the evolution proposal that uses the non-failable
So I do really think we should have at least an Although a quick Google search across GitHub repos shows that |
@hamishknight Fair! I tried to look search for how common `init?(rawValue🙂` vs. `init(rawValue🙂` is in the SDKs that ship with Swift, but GitHub's search functionality didn't differ between the queries. I think the easiest solution here would be to at least add `init(_ rawValue🙂`; I'll see about whether we can reasonably change `init?(rawValue🙂` to `init(rawValue🙂`. |
@itaiferber Awesome, thanks 🙂 If it's of use to you, here's the result of a quick grep for both in /stdlib:
The only other ones that stands out among the failable ones are those in |
@hamishknight Interesting, thanks for looking through this! Looks like this might be worth fixing, then, for consistency. Although this is a small change, this will likely need to go through API review with other changes as well. |
@swift-ci Create |
@itaiferber No worries! By "API review", are we talking about a full blown round of Swift evolution, or just an internal review? |
@hamishknight I'm not sure at the moment, but I think we're going to need to go through swift-evo for this, since |
Environment
Swift version 4.1-dev (LLVM db86aaee13, Clang c336c4829f, Swift cd7600c)
Target: x86_64-apple-darwin17.3.0
Additional Detail from JIRA
md5: f6c9f746f91348e1f3a619642dc94a77
Issue Description:
Currently,
CodingUserInfoKey
'sinit?(rawValue:)
is failable (despite never returningnil
), so you have to force unwrap the result. In addition, SE-0166 proposed a non-failableinit(_ value: String)
, which is yet to be implemented.IMO, the API should be changed to have both a non-failable
init(rawValue:)
and (convenience)init(_ rawValue:)
.The text was updated successfully, but these errors were encountered: