From ae69e571e1c9c2ce5e29b938ad9c376c74b3cd5b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oscar=20Nihlg=C3=A5rd?= Date: Fri, 29 Jun 2018 16:00:53 +0200 Subject: [PATCH] VM regression fixes (#8146) --- compiler/vm.nim | 4 +++- tests/vm/tvmmisc.nim | 32 +++++++++++++++++++++++++++++++- 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/compiler/vm.nim b/compiler/vm.nim index b16eb0fd4..c8e595f5d 100644 --- a/compiler/vm.nim +++ b/compiler/vm.nim @@ -209,7 +209,7 @@ proc writeField(n: var PNode, x: TFullReg) = of rkNone: discard of rkInt: n.intVal = x.intVal of rkFloat: n.floatVal = x.floatVal - of rkNode: n = x.node + of rkNode: n = copyValue(x.node) of rkRegisterAddr: writeField(n, x.regAddr[]) of rkNodeAddr: n = x.nodeAddr[] @@ -912,6 +912,7 @@ proc rawExecute(c: PCtx, start: int, tos: PStackFrame): TFullReg = if a.kind == nkSym: regs[ra].node = if a.sym.ast.isNil: newNode(nkNilLit) else: copyTree(a.sym.ast) + regs[ra].node.flags.incl nfIsRef else: stackTrace(c, tos, pc, "node is not a symbol") of opcEcho: @@ -1462,6 +1463,7 @@ proc rawExecute(c: PCtx, start: int, tos: PStackFrame): TFullReg = else: regs[ra].node = newNodeI(nkIdent, c.debug[pc]) regs[ra].node.ident = getIdent(c.cache, regs[rb].node.strVal) + regs[ra].node.flags.incl nfIsRef of opcSetType: if regs[ra].kind != rkNode: internalError(c.config, c.debug[pc], "cannot set type") diff --git a/tests/vm/tvmmisc.nim b/tests/vm/tvmmisc.nim index 80f5aeee0..7e4af8b75 100644 --- a/tests/vm/tvmmisc.nim +++ b/tests/vm/tvmmisc.nim @@ -89,4 +89,34 @@ block: proc f(size: int): int = var some = newStringOfCap(size) result = size - doAssert f(4) == 4 \ No newline at end of file + doAssert f(4) == 4 + +# #7871 +static: + type Obj = object + field: int + var s = newSeq[Obj](1) + var o = Obj() + s[0] = o + o.field = 2 + doAssert s[0].field == 0 + +# #8125 +static: + let def_iter_var = ident("it") + +# #8142 +static: + type Obj = object + names: string + + proc pushName(o: var Obj) = + var s = "" + s.add("FOOBAR") + o.names.add(s) + + var o = Obj() + o.names = "" + o.pushName() + o.pushName() + doAssert o.names == "FOOBARFOOBAR" \ No newline at end of file