Skip to content

GetHashCode infinite loop #106

@ingted

Description

@ingted

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions