diff options
author | flywind <43030857+xflywind@users.noreply.github.com> | 2020-11-20 16:06:18 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-11-20 09:06:18 +0100 |
commit | 6cf5ca1dc2c1c0388e0998a24d26f4a9c9b7e60e (patch) | |
tree | 2817d94f3319596aae1e87a7ea544c8d65ff7a02 | |
parent | 109cc45398bcdafc22f0a5e49cdfda8234bc46de (diff) | |
download | Nim-6cf5ca1dc2c1c0388e0998a24d26f4a9c9b7e60e.tar.gz |
alternative way to fix #16022 (#16064) [backport:1.4]
* alternative way to fix #16022 * add testcase for #16022 [backport:1.4]
-rw-r--r-- | lib/core/typeinfo.nim | 4 | ||||
-rw-r--r-- | tests/stdlib/tmarshal.nim | 9 |
2 files changed, 10 insertions, 3 deletions
diff --git a/lib/core/typeinfo.nim b/lib/core/typeinfo.nim index 00f7c176c..ca531b4b9 100644 --- a/lib/core/typeinfo.nim +++ b/lib/core/typeinfo.nim @@ -327,10 +327,10 @@ proc setPointer*(x: Any, y: pointer) = ## ``akString``, ``akCString``, ``akProc``, ``akRef``, ``akPtr``, ## ``akPointer``, ``akSequence``. assert x.rawType.kind in pointerLike - if y != nil: + if y != nil and x.rawType.kind != tyPointer: genericAssign(x.value, y, x.rawType) else: - cast[ppointer](x.value)[] = nil + cast[ppointer](x.value)[] = y proc fieldsAux(p: pointer, n: ptr TNimNode, ret: var seq[tuple[name: cstring, any: Any]]) = diff --git a/tests/stdlib/tmarshal.nim b/tests/stdlib/tmarshal.nim index 315036631..d76be73f3 100644 --- a/tests/stdlib/tmarshal.nim +++ b/tests/stdlib/tmarshal.nim @@ -7,6 +7,7 @@ omega 200 Some(null) None[JsonNode] (numeric: "") +hello world ''' joinable: false """ @@ -138,7 +139,7 @@ block: echo ($$a2).to[:Option[JsonNode]] -# bug #15620 +# bug #15620 block: let str = """{"numeric": null}""" @@ -148,3 +149,9 @@ block: let test = to[LegacyEntry](str) echo test + +# bug #16022 +block: + let p: proc () = proc () = echo "hello world" + let poc = (to[typeof(p)]($$p)) + poc() |