-
Notifications
You must be signed in to change notification settings - Fork 795
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
string
can throw for voptions
#6782
Comments
Apparently, the implementation of This |
I suspect it might actually be due to the anyToString function. Even with regular options I can do:
So it has to do with the magic of the
so |
The reason that's relevant for Option is that That can't possibly apply to ValueOption, as it is a value type. In fact, the correct representation of |
Oh I understand your point now, thanks for clarifying. |
Closing in favor of #7693, since I apparently missed this one and I'd like to consolidate |
string
doesn't seem to have the same support for voptions that it has for options. For both voptions and options, using the .ToString() method can throw: (None.ToString()
&ValueNone.ToString()
), butstring
handles None by somewhat elegantly returning an empty string (and has the same behavior fornull
). When callingstring ValueNone
though, it throws an exception. Interestingly,string [None]
andstring [null]
both return "[null]", butstring [ValueNone]
throws an exception as well.I apologize if this is intended behavior and I just can't find the discussion of it.
Repro steps
string ValueNone;;
and witness the exceptionstring [ValueNone];;
and witness the exceptionExpected behavior
I expected it to return "" and "[null]" or some other sensible values.
Actual behavior
It throws exceptions.
Known workarounds
Use
sprintf "%A"
or pattern match before attempting to callstring
.Related information
Windows 10 Pro
.NET Core SDK: 2.2.204
Visual Studio 2019: 16.0.4
fsi is from "C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\Common7\IDE\CommonExtensions\Microsoft\FSharp\fsi.exe"
(I'm using whatever FSharp.Core comes bundled with fsi)
The text was updated successfully, but these errors were encountered: