fix #15934 and #15620 (#15938) [backport:1.4]

* make workaround for #15934 and #15620
* add testcase for #9754
This commit is contained in:
Andreas Rumpf 2020-11-15 18:12:53 +01:00 • committed by GitHub
commit fc735e4b08
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 35 additions and 1 deletions

View file

@ -327,7 +327,10 @@ proc setPointer*(x: Any, y: pointer) =
## ``akString``, ``akCString``, ``akProc``, ``akRef``, ``akPtr``,
## ``akPointer``, ``akSequence``.
assert x.rawType.kind in pointerLike
if y != nil:
genericAssign(x.value, y, x.rawType)
else:
cast[ppointer](x.value)[] = nil
proc fieldsAux(p: pointer, n: ptr TNimNode,
ret: var seq[tuple[name: cstring, any: Any]]) =

6
tests/stdlib/t9754.nim Normal file
View file

@ -0,0 +1,6 @@
discard """
joinable: false
"""
import tmarshal
import tparsesql

View file

@ -4,6 +4,9 @@ true
true
alpha 100
omega 200
Some(null)
None[JsonNode]
(numeric: "")
'''
joinable: false
"""
@ -123,3 +126,25 @@ var foo = Foo(a2: "", a4: @[], a6: @[1])
foo.a6.setLen 0
doAssert $$foo == """{"a1": "", "a2": "", "a3": [], "a4": [], "a5": [], "a6": []}"""
testit(foo)
import options, json
# bug #15934
block:
let
a1 = some(newJNull())
a2 = none(JsonNode)
echo ($$a1).to[:Option[JsonNode]]
echo ($$a2).to[:Option[JsonNode]]
# bug #15620
block:
let str = """{"numeric": null}"""
type
LegacyEntry = object
numeric: string
let test = to[LegacyEntry](str)
echo test