alternative way to fix #16022 (#16064) [backport:1.4]

* alternative way to fix #16022
* add testcase for #16022

[backport:1.4]
This commit is contained in:
flywind 2020-11-20 16:06:18 +08:00 • committed by GitHub
commit 6cf5ca1dc2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 3 deletions

View file

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

View file

@ -7,6 +7,7 @@ omega 200
Some(null) Some(null)
None[JsonNode] None[JsonNode]
(numeric: "") (numeric: "")
hello world
''' '''
joinable: false joinable: false
""" """
@ -138,7 +139,7 @@ block:
echo ($$a2).to[:Option[JsonNode]] echo ($$a2).to[:Option[JsonNode]]
# bug #15620 # bug #15620
block: block:
let str = """{"numeric": null}""" let str = """{"numeric": null}"""
@ -148,3 +149,9 @@ block:
let test = to[LegacyEntry](str) let test = to[LegacyEntry](str)
echo test echo test
# bug #16022
block:
let p: proc () = proc () = echo "hello world"
let poc = (to[typeof(p)]($$p))
poc()