You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Custom hash functions are never called on Record Types.
Repro code
test.fsx
[<CustomEquality>][<NoComparison>]typeMyRecord={Name :string; Age:int }overridethis.Equals(that)=
this.GetHashCode()= that.GetHashCode()/// Hash should just return age of personoverridethis.GetHashCode()=
this.Age
letp1={Name ="John"; Age =30}// Should return 30, but returns -4426817161268664163
printfn "Hash1: %A"(p1.GetHashCode())
test.cmd
dotnet fable . --lang python
python test.py
Explanation
In the transpiled code, the class MyRecord now implements a __hash__ method. But the method call is transpiled to safe_hash, which first checks for the existence of an GetHashCode method. This is always true for Record Types, so the custom __hash__ methdo is never called.
Description
Custom hash functions are never called on Record Types.
Repro code
test.fsx
test.cmd
dotnet fable . --lang python python test.py
Explanation
In the transpiled code, the class
MyRecord
now implements a__hash__
method. But the method call is transpiled tosafe_hash
, which first checks for the existence of anGetHashCode
method. This is always true for Record Types, so the custom__hash__
methdo is never called.Related information
dotnet fable --version
: 4.13.0dotnet tool list/update/install
: 4.13.0Workaround Code
@Freymaurer
The text was updated successfully, but these errors were encountered: