From 82561f31eb8ebfe14df8b0299393aafbfca47c0b Mon Sep 17 00:00:00 2001 From: narimiran Date: Wed, 24 Mar 2021 17:48:39 +0100 Subject: [PATCH] backport json-related part of #17469 --- lib/pure/json.nim | 7 ++++--- tests/stdlib/tjsonutils.nim | 14 +++++++------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/lib/pure/json.nim b/lib/pure/json.nim index 898639dbf4..963ce9c1a8 100644 --- a/lib/pure/json.nim +++ b/lib/pure/json.nim @@ -1064,12 +1064,13 @@ when defined(nimFixedForwardGeneric): dst = jsonNode.copy proc initFromJson[T: SomeInteger](dst: var T; jsonNode: JsonNode, jsonPath: var string) = - when T is uint|uint64: + when T is uint|uint64 or (not defined(js) and int.sizeof == 4): + verifyJsonKind(jsonNode, {JInt, JString}, jsonPath) case jsonNode.kind of JString: - dst = T(parseBiggestUInt(jsonNode.str)) + let x = parseBiggestUInt(jsonNode.str) + dst = cast[T](x) else: - verifyJsonKind(jsonNode, {JInt}, jsonPath) dst = T(jsonNode.num) else: verifyJsonKind(jsonNode, {JInt}, jsonPath) diff --git a/tests/stdlib/tjsonutils.nim b/tests/stdlib/tjsonutils.nim index 44ddf61540..e3f529ce31 100644 --- a/tests/stdlib/tjsonutils.nim +++ b/tests/stdlib/tjsonutils.nim @@ -72,16 +72,16 @@ template fn() = block: let a = (int32.high, uint32.high) testRoundtrip(a): "[2147483647,4294967295]" - when not defined(js): + when int.sizeof > 4: block: let a = (int64.high, uint64.high) testRoundtrip(a): "[9223372036854775807,18446744073709551615]" - block: - let a = (int.high, uint.high) - when int.sizeof == 4: - testRoundtrip(a): "[2147483647,4294967295]" - else: - testRoundtrip(a): "[9223372036854775807,18446744073709551615]" + block: + let a = (int.high, uint.high) + when int.sizeof == 4: + testRoundtrip(a): "[2147483647,4294967295]" + else: + testRoundtrip(a): "[9223372036854775807,18446744073709551615]" block: # case object type Foo = object