summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--lib/core/typeinfo.nim4
-rw-r--r--tests/stdlib/tmarshal.nim9
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()