summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorAndreas Rumpf <rumpf_a@web.de>2018-09-18 09:38:28 +0200
committerGitHub <noreply@github.com>2018-09-18 09:38:28 +0200
commitaa2d219afe8592d3764f73e8771d1e13ac5ea55b (patch)
tree0f311901ac4b7dcdb6332f4cf602b8cbd0c34639
parent597acad507f1acc8a50e9e98d83328a4c4dd8bda (diff)
parent027cc5013eedce70d5f925e18037e9d1786ebd15 (diff)
downloadNim-aa2d219afe8592d3764f73e8771d1e13ac5ea55b.tar.gz
Merge pull request #8995 from LemonBoy/fix-4952
Fix error during field access in VM
-rw-r--r--compiler/vm.nim10
-rw-r--r--tests/vm/t4952.nim17
2 files changed, 24 insertions, 3 deletions
diff --git a/compiler/vm.nim b/compiler/vm.nim
index e38642de8..faff81697 100644
--- a/compiler/vm.nim
+++ b/compiler/vm.nim
@@ -557,11 +557,15 @@ proc rawExecute(c: PCtx, start: int, tos: PStackFrame): TFullReg =
       # a = b.c
       decodeBC(rkNode)
       let src = regs[rb].node
-      if src.kind notin {nkEmpty..nkNilLit}:
-        let n = src.sons[rc + ord(src.kind == nkObjConstr)].skipColon
+      case src.kind
+      of nkEmpty..nkNilLit:
+        stackTrace(c, tos, pc, errNilAccess)
+      of nkObjConstr:
+        let n = src.sons[rc + 1].skipColon
         regs[ra].node = n
       else:
-        stackTrace(c, tos, pc, errNilAccess)
+        let n = src.sons[rc]
+        regs[ra].node = n
     of opcWrObj:
       # a.b = c
       decodeBC(rkNode)
diff --git a/tests/vm/t4952.nim b/tests/vm/t4952.nim
new file mode 100644
index 000000000..fc76fa4df
--- /dev/null
+++ b/tests/vm/t4952.nim
@@ -0,0 +1,17 @@
+import macros
+
+proc doCheck(tree: NimNode) =
+  let res: tuple[n: NimNode] = (n: tree)
+  assert: tree.kind == res.n.kind
+  for sub in tree:
+    doCheck(sub)
+
+macro id(body: untyped): untyped =
+  doCheck(body)
+
+id(foo((i: int)))
+
+static:
+  let tree = newTree(nnkExprColonExpr)
+  let t = (n: tree)
+  assert: t.n.kind == tree.kind