From 077eba7b388259ecca7e9e7990f48efe9e3641c5 Mon Sep 17 00:00:00 2001 From: flywind Date: Thu, 12 Nov 2020 23:24:45 +0800 Subject: [PATCH 1/5] make workaround for #15934 and #15620 --- lib/core/typeinfo.nim | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/core/typeinfo.nim b/lib/core/typeinfo.nim index 5c4e1b6019..2f213956b9 100644 --- a/lib/core/typeinfo.nim +++ b/lib/core/typeinfo.nim @@ -327,7 +327,8 @@ 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) proc fieldsAux(p: pointer, n: ptr TNimNode, ret: var seq[tuple[name: cstring, any: Any]]) = From 8ec3c141ae28616382a82235b2f4049eaa0ab0d7 Mon Sep 17 00:00:00 2001 From: flywind Date: Thu, 12 Nov 2020 23:58:42 +0800 Subject: [PATCH 2/5] add testcase --- tests/stdlib/tmarshal.nim | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/tests/stdlib/tmarshal.nim b/tests/stdlib/tmarshal.nim index fc5703a031..3150366316 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 From 0f53b129b78ae480f62a68877778600ba100e96c Mon Sep 17 00:00:00 2001 From: flywind Date: Fri, 13 Nov 2020 15:28:22 +0800 Subject: [PATCH 3/5] nil --- lib/core/typeinfo.nim | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/core/typeinfo.nim b/lib/core/typeinfo.nim index 2f213956b9..00f7c176ca 100644 --- a/lib/core/typeinfo.nim +++ b/lib/core/typeinfo.nim @@ -329,6 +329,8 @@ proc setPointer*(x: Any, y: pointer) = 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]]) = From a968e7dd9b2a22adeae8a71f7ca1e8dfb2e56a2c Mon Sep 17 00:00:00 2001 From: flywind Date: Fri, 13 Nov 2020 15:42:59 +0800 Subject: [PATCH 4/5] add testcase for #9754 --- tests/stdlib/t9754.nim | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 tests/stdlib/t9754.nim diff --git a/tests/stdlib/t9754.nim b/tests/stdlib/t9754.nim new file mode 100644 index 0000000000..6e81fd8bc2 --- /dev/null +++ b/tests/stdlib/t9754.nim @@ -0,0 +1,2 @@ +import tmarshal +import tparsesql \ No newline at end of file From a86aa310813d326d88959534c36b5499870dcb95 Mon Sep 17 00:00:00 2001 From: flywind Date: Fri, 13 Nov 2020 16:15:13 +0800 Subject: [PATCH 5/5] minor --- tests/stdlib/t9754.nim | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/stdlib/t9754.nim b/tests/stdlib/t9754.nim index 6e81fd8bc2..971b5a8fbe 100644 --- a/tests/stdlib/t9754.nim +++ b/tests/stdlib/t9754.nim @@ -1,2 +1,6 @@ +discard """ + joinable: false +""" + import tmarshal import tparsesql \ No newline at end of file