Fable: GetHashCode seems to be behaving strange in some circumstances

Created on 27 May 2020  路  2Comments  路  Source: fable-compiler/Fable

Description

I seem to be getting different behaviour between Fable's built in "hash" function and Object.GetHashCode(). Hash seems to be correct, but GetHashCode() is not working comprehensively for tuples, lists, and maps. It seems to produce a non-deterministic output for each call, although the sequence seems to be.

Normally I would just go ahead and use hash, but my particular case is using an evil mutable dotnet dictionary, which I believe uses GetHashCode internally. This seems to be manifesting in some unpredictable behaviour.

Fable.Core issue I think. I think this is the right repo?

Repro code

module GetHashCode

("hello", 1).GetHashCode() = ("hello", 1).GetHashCode() |> printf "%A"
(("hello", 1) |> hash)= (("hello", 1) |> hash) |> printf "%A"

["hello", 1].GetHashCode() = ["hello", 1].GetHashCode() |> printf "%A"
(["hello", 1] |> hash)= (["hello", 1] |> hash) |> printf "%A"

(Map.ofList ["hello", 1]).GetHashCode() = (Map.ofList ["hello", 1]).GetHashCode() |> printf "%A"
(Map.ofList ["hello", 1] |> hash)= (Map.ofList ["hello", 1] |> hash) |> printf "%A"

fable repl example

Expected and actual results

Both cases should return true, at the moment the GetHashCode version returns false, which implies it is not deterministic for multiple calls.

Related information

  • Fable.Core: 3.1.5
  • fable-compiler 2.8.1

Alternatively, this breaks on whatever the version running on fable.io/repl also. (see link above).

Most helpful comment

Fixed in #2065.

All 2 comments

Fixed in #2065.

Super fast, thanks @ncave your a star :)

Was this page helpful?
0 / 5 - 0 ratings