Thoth.Json.Net icon indicating copy to clipboard operation
Thoth.Json.Net copied to clipboard

Bug: Unexpected sign for large int64 decoding.

Open travis-leith opened this issue 1 year ago • 2 comments

open Thoth.Json.Net

type test_type = { i: int64 }

let extra = Extra.empty |> Extra.withInt64
let test_type_decoder = Decode.Auto.generateDecoder<test_type> (extra = extra)

let test_type_json1 = """{"i": 9223372036854775806}"""
let test_type_json2 = """{"i": 8223372036854775806}"""

let test_type1 = Decode.Auto.fromString<test_type> (test_type_json1, extra = extra)

let test_type2 = Decode.fromString test_type_decoder test_type_json2

printfn "test_type1: %A" test_type1
printfn "test_type2: %A" test_type2

For some reason the first value gets parsed as -ve. This seems to only happen for numbers close to the max value. Maybe some sort of overflow is happening.

travis-leith avatar Nov 05 '24 09:11 travis-leith

I found this bug by making sure that Decode.Auto.fromString works the same way as Decode.Auto.generateDecoder, if you are wondering why I use 2 different techniques here.

travis-leith avatar Nov 05 '24 10:11 travis-leith

Thank you for the report, I will investigate this issue while working on porting the Auto API to the new API.

MangelMaxime avatar Nov 26 '24 19:11 MangelMaxime