summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorAndreas Rumpf <rumpf_a@web.de>2020-11-15 18:12:53 +0100
committerGitHub <noreply@github.com>2020-11-15 18:12:53 +0100
commitfc735e4b08d9401dc2b22a1432d1231fa18b4a4f (patch)
treebdac672212785a1f9253d23f1c4fcc385828d571
parent7eb34d170a489c2a0ed90d921f3f7cc6813f19c1 (diff)
parenta86aa310813d326d88959534c36b5499870dcb95 (diff)
downloadNim-fc735e4b08d9401dc2b22a1432d1231fa18b4a4f.tar.gz
fix #15934 and #15620 (#15938) [backport:1.4]
* make workaround for #15934 and #15620
* add testcase for #9754
-rw-r--r--lib/core/typeinfo.nim5
-rw-r--r--tests/stdlib/t9754.nim6
-rw-r--r--tests/stdlib/tmarshal.nim25
3 files changed, 35 insertions, 1 deletions
diff --git a/lib/core/typeinfo.nim b/lib/core/typeinfo.nim
index 5c4e1b601..00f7c176c 100644
--- a/lib/core/typeinfo.nim
+++ b/lib/core/typeinfo.nim
@@ -327,7 +327,10 @@ proc setPointer*(x: Any, y: pointer) =
   ## ``akString``, ``akCString``, ``akProc``, ``akRef``, ``akPtr``,
   ## ``akPointer``, ``akSequence``.
   assert x.rawType.kind in pointerLike
-  genericAssign(x.value, y, x.rawType)
+  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]]) =
diff --git a/tests/stdlib/t9754.nim b/tests/stdlib/t9754.nim
new file mode 100644
index 000000000..971b5a8fb
--- /dev/null
+++ b/tests/stdlib/t9754.nim
@@ -0,0 +1,6 @@
+discard """
+  joinable: false
+"""
+
+import tmarshal
+import tparsesql
\ No newline at end of file
diff --git a/tests/stdlib/tmarshal.nim b/tests/stdlib/tmarshal.nim
index fc5703a03..315036631 100644
--- a/tests/stdlib/tmarshal.nim
+++ b/tests/stdlib/tmarshal.nim
@@ -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