language-ext
language-ext copied to clipboard
Fix [Record] HashableAttribute (runtime error)
Using [Hashable(...)]
in [Record]
results in runtime error.
Found this bug because I didn't use [Hashable(...)]
but just [Eq(...)]
and [Ord(...)]
resulting in different hash codes.
IMHO it's error-prone (and boilerplate) to require all three attributes for simple cases like the one shown in the test case.
GetHashCode maybe should be implemented by using the first existing of
- [Hashable]
- [Eq]
- [Ord]
- HashDefault
I'm not sure whether Ord
should (or does) fully superseed Eq
which could result in a similar list for implementation of Equals
. I often use [Record] types having one or more case insensitive string properties as keys for e.g. Map
and HashMap
or with .GroupBy(..)
.
Edit: somehow related to https://github.com/louthy/language-ext/pull/842 (CompareTo==0 vs. Equals==true)