Skip to content

Commit 82561f3

Browse files
committed
backport json-related part of #17469
1 parent e5027dc commit 82561f3

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

lib/pure/json.nim

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1064,12 +1064,13 @@ when defined(nimFixedForwardGeneric):
10641064
dst = jsonNode.copy
10651065

10661066
proc initFromJson[T: SomeInteger](dst: var T; jsonNode: JsonNode, jsonPath: var string) =
1067-
when T is uint|uint64:
1067+
when T is uint|uint64 or (not defined(js) and int.sizeof == 4):
1068+
verifyJsonKind(jsonNode, {JInt, JString}, jsonPath)
10681069
case jsonNode.kind
10691070
of JString:
1070-
dst = T(parseBiggestUInt(jsonNode.str))
1071+
let x = parseBiggestUInt(jsonNode.str)
1072+
dst = cast[T](x)
10711073
else:
1072-
verifyJsonKind(jsonNode, {JInt}, jsonPath)
10731074
dst = T(jsonNode.num)
10741075
else:
10751076
verifyJsonKind(jsonNode, {JInt}, jsonPath)

tests/stdlib/tjsonutils.nim

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -72,16 +72,16 @@ template fn() =
7272
block:
7373
let a = (int32.high, uint32.high)
7474
testRoundtrip(a): "[2147483647,4294967295]"
75-
when not defined(js):
75+
when int.sizeof > 4:
7676
block:
7777
let a = (int64.high, uint64.high)
7878
testRoundtrip(a): "[9223372036854775807,18446744073709551615]"
79-
block:
80-
let a = (int.high, uint.high)
81-
when int.sizeof == 4:
82-
testRoundtrip(a): "[2147483647,4294967295]"
83-
else:
84-
testRoundtrip(a): "[9223372036854775807,18446744073709551615]"
79+
block:
80+
let a = (int.high, uint.high)
81+
when int.sizeof == 4:
82+
testRoundtrip(a): "[2147483647,4294967295]"
83+
else:
84+
testRoundtrip(a): "[9223372036854775807,18446744073709551615]"
8585

8686
block: # case object
8787
type Foo = object

0 commit comments

Comments
 (0)