Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GetHashCode infinite loop #106

Open
ingted opened this issue May 24, 2023 · 0 comments
Open

GetHashCode infinite loop #106

ingted opened this issue May 24, 2023 · 0 comments

Comments

@ingted
Copy link

ingted commented May 24, 2023

GetHashCode would cause infinite loop, please consider to fix it.

My workaround:

    override x.GetHashCode() =

        let rec jsonValue (this:Json) =
            match this with
            | Array  v -> box (v |> List.map (fun j -> jsonValue j) |> Array.ofList)
            | True     -> box true
            | False    -> box false
            | Null     -> null
            | Number v ->
                match System.Int32.TryParse v with
                | true, i -> box i
                | false, _ ->
                    match System.Int64.TryParse v with
                    | true, i64 -> box i64
                    | false, _ ->
                        match bigint.TryParse v with
                        | true, bi -> box bi
                        | false, _ ->
                            match System.Decimal.TryParse v with
                            | true, d -> box d
                            | false, _ -> 
                                match System.Single.TryParse v with
                                | true, s -> box s
                                | false, _ ->
                                    match System.Double.TryParse v with
                                    | true, db -> box db
                                    | false, _ -> box v
                            
            | Object (WriteObject v) ->
                let s = v |> Seq.map (fun (k, j) -> k, jsonValue j)
                s |> Map |> box
            | Object (ReadObject (_, v)) ->
                let s = v |> Seq.map (fun kvp -> kvp.Key, jsonValue kvp.Value)
                s |> Map |> box
            | String v -> box v

        jsonValue x |> hash
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant