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
[SR-2062] Optionals do not conform to CustomStringConvertible #44671
Comments
In order to do this properly we would need conditional conformances. But in most cases you don't really want to print an Optional directly anyway. I'll admit playgrounds are an exception. |
This behavior is intentional. Optional does conform to |
Comment by Shai Mishali (JIRA) I'm not exactly sure how printing out an adjusted/wrong value gives clarity on the fact it's wrapped ? The issue is getting Optional(3.79999995) instead of the expected Optional(3.8) eventually |
I think that's because |
Comment by Shai Mishali (JIRA) That's very interesting, thanks for elaborating on the possible cause 🙂 I would still think this is more of a bug/side-effect then actual intended behaviour... When I got around to just printing a result of some request returning an optional Float, i was sure something was wrong until unwrapping that value. I do agree most users would print an already-unwrapped value, but it still seems kinda odd and somewhat confusing to leave it this way. Is there anything preventing using `description` over `debugDescription` in that scenario ? |
Strings in particular don't compose well with other context. Is |
We generally use |
Comment by Shai Mishali (JIRA) Understood 🙂 Thanks again for the explanation. Jordan, that's actually a great point as well. |
Is this actually a bug? It seems just a natural consequence of `Optional` using it's wrapped value's `debugDescription` as part of it's `description`. |
Additional Detail from JIRA
md5: 983c4522a7cfa08be3464f79fc4e1593
relates to:
Issue Description:
Optionals do not currently conform to CustomStringConvertible so their representations do not use the preferred representation of the wrapped value:
Conforming Optional to CustomStringConvertible pricks up the value's preferred output style:
When added, the output is
The text was updated successfully, but these errors were encountered: