summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorArne Döring <arne.doering@gmx.net>2017-01-19 20:10:01 +0100
committerAndreas Rumpf <rumpf_a@web.de>2017-01-19 20:10:01 +0100
commite8a00b805f841a68911026f4461c1cb5c936711b (patch)
treea4f7344646ee6b7980e6b8d2812a72de130b566e
parentecf180256827df4bbe5e28297c7f1ccb064a5e2e (diff)
downloadNim-e8a00b805f841a68911026f4461c1cb5c936711b.tar.gz
fix seq add for nim node in VM (#5253)
fixes #4821 
-rw-r--r--compiler/vm.nim2
-rw-r--r--tests/vm/tnimnode.nim9
2 files changed, 8 insertions, 3 deletions
diff --git a/compiler/vm.nim b/compiler/vm.nim
index 344ad6610..c8a854247 100644
--- a/compiler/vm.nim
+++ b/compiler/vm.nim
@@ -821,7 +821,7 @@ proc rawExecute(c: PCtx, start: int, tos: PStackFrame): TFullReg =
     of opcAddSeqElem:
       decodeB(rkNode)
       if regs[ra].node.kind == nkBracket:
-        regs[ra].node.add(copyTree(regs[rb].regToNode))
+        regs[ra].node.add(copyValue(regs[rb].regToNode))
       else:
         stackTrace(c, tos, pc, errNilAccess)
     of opcGetImpl:
diff --git a/tests/vm/tnimnode.nim b/tests/vm/tnimnode.nim
index 1508419c4..cca03cd62 100644
--- a/tests/vm/tnimnode.nim
+++ b/tests/vm/tnimnode.nim
@@ -10,7 +10,7 @@ static:
   # an assignment of stmtList into an array
   var nodeArray: array[1, NimNode]
   # an assignment of stmtList into a seq
-  var nodeSeq = newSeq[NimNode](1)
+  var nodeSeq = newSeq[NimNode](2)
 
 
 proc checkNode(arg: NimNode; name: string): void {. compileTime .} =
@@ -21,12 +21,17 @@ proc checkNode(arg: NimNode; name: string): void {. compileTime .} =
   node = arg
   nodeArray = [arg]
   nodeSeq[0] = arg
+  var seqAppend = newSeq[NimNode](0)
+  seqAppend.add([arg]) # at the time of this writing this works
+  seqAppend.add(arg)   # bit this creates a copy
   arg.add newCall(ident"echo", newLit("Hello World"))
 
-  assertEq arg.lispRepr     , """StmtList(DiscardStmt(Empty()), Call(Ident(!"echo"), StrLit(Hello World)))"""
+  assertEq arg.lispRepr          , """StmtList(DiscardStmt(Empty()), Call(Ident(!"echo"), StrLit(Hello World)))"""
   assertEq node.lispRepr         , """StmtList(DiscardStmt(Empty()), Call(Ident(!"echo"), StrLit(Hello World)))"""
   assertEq nodeArray[0].lispRepr , """StmtList(DiscardStmt(Empty()), Call(Ident(!"echo"), StrLit(Hello World)))"""
   assertEq nodeSeq[0].lispRepr   , """StmtList(DiscardStmt(Empty()), Call(Ident(!"echo"), StrLit(Hello World)))"""
+  assertEq seqAppend[0].lispRepr , """StmtList(DiscardStmt(Empty()), Call(Ident(!"echo"), StrLit(Hello World)))"""
+  assertEq seqAppend[1].lispRepr , """StmtList(DiscardStmt(Empty()), Call(Ident(!"echo"), StrLit(Hello World)))"""
 
   echo "OK"