summary refs log tree commit diff stats
path: root/lib
diff options
context:
space:
mode:
authorTimothee Cour <timothee.cour2@gmail.com>2021-06-03 13:29:45 -0700
committerGitHub <noreply@github.com>2021-06-03 22:29:45 +0200
commit654a20166eabb614cbf0379c67115981f0532079 (patch)
tree167efee61da1fca45f0ebc648a20782d7b17ab32 /lib
parentd91d78f8aed2b1b59effa3b98765aaf675d7e4c3 (diff)
downloadNim-654a20166eabb614cbf0379c67115981f0532079.tar.gz
simplify extccomp.nim json logic via jsonutils; fix #18084 (#18100)
* simplify extccomp.nim json logic via jsonutils
* fix #18084
* simplify further
* workaround for bootstrap that can be removed after updating csources_v1 >= 1.2
Diffstat (limited to 'lib')
-rw-r--r--lib/std/jsonutils.nim18
1 files changed, 17 insertions, 1 deletions
diff --git a/lib/std/jsonutils.nim b/lib/std/jsonutils.nim
index e33ae4401..60d78fea5 100644
--- a/lib/std/jsonutils.nim
+++ b/lib/std/jsonutils.nim
@@ -34,6 +34,23 @@ import macros
 from enumutils import symbolName
 from typetraits import OrdinalEnum
 
+when not defined(nimFixedForwardGeneric):
+  # xxx remove pending csources_v1 update >= 1.2.0
+  proc to[T](node: JsonNode, t: typedesc[T]): T =
+    when T is string: node.getStr
+    elif T is bool: node.getBool
+    else: static: doAssert false, $T # support as needed (only needed during bootstrap)
+  proc isNamedTuple(T: typedesc): bool = # old implementation
+    when T isnot tuple: result = false
+    else:
+      var t: T
+      for name, _ in t.fieldPairs:
+        when name == "Field0": return compiles(t.Field0)
+        else: return true
+      return false
+else:
+  proc isNamedTuple(T: typedesc): bool {.magic: "TypeTrait".}
+
 type
   Joptions* = object # xxx rename FromJsonOptions
     ## Options controlling the behavior of `fromJson`.
@@ -61,7 +78,6 @@ proc initToJsonOptions*(): ToJsonOptions =
   ## initializes `ToJsonOptions` with sane options.
   ToJsonOptions(enumMode: joptEnumOrd, jsonNodeMode: joptJsonNodeAsRef)
 
-proc isNamedTuple(T: typedesc): bool {.magic: "TypeTrait".}
 proc distinctBase(T: typedesc): typedesc {.magic: "TypeTrait".}
 template distinctBase[T](a: T): untyped = distinctBase(typeof(a))(a)