Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
* fix nim-lang#15835

* add tests
  • Loading branch information
ringabout authored Nov 4, 2020
1 parent b0e26d8 commit 7d640e0
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/pure/json.nim
Original file line number Diff line number Diff line change
Expand Up @@ -1052,6 +1052,8 @@ when defined(nimFixedForwardGeneric):
dst = jsonNode.bval

proc initFromJson(dst: var JsonNode; jsonNode: JsonNode; jsonPath: var string) =
if jsonNode == nil:
raise newException(KeyError, "key not found: " & jsonPath)
dst = jsonNode.copy

proc initFromJson[T: SomeInteger](dst: var T; jsonNode: JsonNode, jsonPath: var string) =
Expand Down
17 changes: 17 additions & 0 deletions tests/stdlib/t15835.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import json

type
Foo = object
ii*: int
data*: JsonNode

block:
const jt = """{"ii": 123, "data": ["some", "data"]}"""
let js = parseJson(jt)
discard js.to(Foo)

block:
const jt = """{"ii": 123}"""
let js = parseJson(jt)
doAssertRaises(KeyError):
echo js.to(Foo)

0 comments on commit 7d640e0

Please sign in to comment.