dotnet / dotnet/fsharp

Emit a warning when x.ToString(), x.GetHashCode or x.Equals(y) are used directly on option-typed values

Open
#4,345 20 comments 0 reactions 0 assignees View on GitHub
Area-Diagnostics Feature Improvement
Dominant language
F#
Stars
4.3k
Forks
876
Avg merge
4d 11h
Merged PRs (30d)
131

Description

[@dsyme says] Proposal after discussion: emit a warning when x.ToString(), x.GetHashCode or x.Equals(y) are used directly on option-typed values, suggesting to use string or x = y instead. Or more generally when Equals, GetHashCode or ToString are used on F#-declared types known to have null as a representation.

### Description

None.ToString();;
None.GetHashCode();;
None.Equals(None);;

lead to NullReferenceException in fsi and fsc.

#### Known workarounds

Use ``string x``, ``hash x`` and ``x = y``

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.