mirror of
https://github.com/nim-lang/Nim.git
synced 2026-02-15 07:43:26 +00:00
Fix infinite recursion when using json.to on ref with cycle.
This commit is contained in:
committed by
Dominik Picheta
parent
8d61262372
commit
2bb2e6975e
@@ -354,6 +354,4 @@ when isMainModule:
|
||||
let dataDeser = to(dataParsed, Test)
|
||||
doAssert dataDeser.name == "FooBar"
|
||||
doAssert dataDeser.fallback.kind == JFloat
|
||||
doAssert dataDeser.fallback.getFloat() == 56.42
|
||||
|
||||
# TODO: Cycles lead to infinite loops.
|
||||
doAssert dataDeser.fallback.getFloat() == 56.42
|
||||
21
tests/stdlib/tjsonmacro_reject2.nim
Normal file
21
tests/stdlib/tjsonmacro_reject2.nim
Normal file
@@ -0,0 +1,21 @@
|
||||
discard """
|
||||
file: "tjsonmacro_reject2.nim"
|
||||
line: 10
|
||||
errormsg: "The `to` macro does not support ref objects with cycles."
|
||||
"""
|
||||
import json
|
||||
|
||||
type
|
||||
Misdirection = object
|
||||
cycle: Cycle
|
||||
|
||||
Cycle = ref object
|
||||
foo: string
|
||||
cycle: Misdirection
|
||||
|
||||
let data = """
|
||||
{"cycle": null}
|
||||
"""
|
||||
|
||||
let dataParsed = parseJson(data)
|
||||
let dataDeser = to(dataParsed, Cycle)
|
||||
Reference in New Issue
Block a user