summary refs log tree commit diff stats
path: root/lib
diff options
context:
space:
mode:
authorVindaar <basti90@gmail.com>2019-08-27 22:23:47 +0200
committerAndreas Rumpf <rumpf_a@web.de>2019-08-27 22:23:47 +0200
commiteff0837ff40e4a5f5659ff02a56d9936bcbd7bcd (patch)
tree6b189c3ed12d58b63b015bf86e84d5333c4c8756 /lib
parent00d46ca1c04935b7b4fe16e7f72204b46f5651fa (diff)
downloadNim-eff0837ff40e4a5f5659ff02a56d9936bcbd7bcd.tar.gz
fixes #12015 by also checking kind of `typeNode` (#12016)
* fixes #12015 by also checking kind of `typeNode`

If a tuple field is aliased it'll appear the same as a ref type in a
call to `getType` if only for the kind of the resulting `NimNode` is
checked (that is a `nnkBracketExpr`)

* fix test case due to #12017 and add more realistic test case

Adds an additional test case, which includes generics and is closer to
the real failure I encountered

* remove previous fix and fix differently after all

The previous fix was incomplete, because it failed for generics.

Note that the `of "tuple"` is not actually needed, the
`nnkBracketExpr` branch in the `else` branch would catch it too, but I
decided to introduce it for clarity. However, the latter is actually
needed, because it seems for aliases of `seq` we end up in it.

* update comment about global `%` proc in json test
Diffstat (limited to 'lib')
-rw-r--r--lib/pure/json.nim17
1 files changed, 13 insertions, 4 deletions
diff --git a/lib/pure/json.nim b/lib/pure/json.nim
index 1ef08f547..23b23b4a4 100644
--- a/lib/pure/json.nim
+++ b/lib/pure/json.nim
@@ -1369,11 +1369,20 @@ proc createConstructor(typeSym, jsonNode: NimNode): NimNode =
           for `forLoopI` in 0 ..< `jsonNode`.len: list[`forLoopI`] =`constructorNode`;
           list
         )
-
+    of "tuple":
+      let typeNode = getTypeImpl(typeSym)
+      result = createConstructor(typeNode, jsonNode)
     else:
-      # Generic type.
+      # Generic type or some `seq[T]` alias
       let obj = getType(typeSym)
-      result = processType(typeSym, obj, jsonNode, false)
+      case obj.kind
+      of nnkBracketExpr:
+        # probably a `seq[T]` alias
+        let typeNode = getTypeImpl(typeSym)
+        result = createConstructor(typeNode, jsonNode)
+      else:
+        # generic type
+        result = processType(typeSym, obj, jsonNode, false)
   of nnkSym:
     # Handle JsonNode.
     if ($typeSym).cmpIgnoreStyle("jsonnode") == 0:
@@ -1385,7 +1394,7 @@ proc createConstructor(typeSym, jsonNode: NimNode): NimNode =
     if typeNode.typeKind == ntyDistinct:
       result = createConstructor(typeNode, jsonNode)
     elif obj.kind == nnkBracketExpr:
-      # When `Sym "Foo"` turns out to be a `ref object`.
+      # When `Sym "Foo"` turns out to be a `ref object` or `tuple`
       result = createConstructor(obj, jsonNode)
     else:
       result = processType(typeSym, obj, jsonNode, false)