I suggest we ...

Handle null values in Records gracefully instead of crashing with a NRE

Please see https://github.com/Microsoft/visualfsharp/issues/1044

Currently, if a nonnull field in a record (e.g. another record, or FSharpList<'T>, ...) is null, .GetHashCode (and potentially other methods) throw a NullReferenceException.

While these objects are obviously invalid and AFAIK can't be easily created in pure F#, this case sometimes happens out of the control of the user.

Examples are DataBinding in WPF and Serialization.

If the external code ever calls .GetHashCode on an object under construction, it will blow up.

The suggestion is NOT to change anything semantically but to handle null values gracefully where possible to ease the interop with these external libraries. This is especially important for .GetHashCode, since it is expected that it is always safe to call this method.

In the case of .GetHashCode, this could be handled backwards-compatible by returning a fixed hash for a null value.

0 votes
Vote
Sign in
(thinking…)
Sign in with: Facebook Google
Signed in as (Sign out)
You have left! (?) (thinking…)
lr shared this idea  ·   ·  Flag idea as inappropriate…  ·  Admin →

0 comments

Sign in
(thinking…)
Sign in with: Facebook Google
Signed in as (Sign out)
Submitting...

F# Language

Feedback and Knowledge Base