diff options
-rw-r--r-- | compiler/vm.nim | 10 | ||||
-rw-r--r-- | tests/vm/tref.nim | 12 |
2 files changed, 20 insertions, 2 deletions
diff --git a/compiler/vm.nim b/compiler/vm.nim index 6c36a1458..27135d2e7 100644 --- a/compiler/vm.nim +++ b/compiler/vm.nim @@ -210,8 +210,14 @@ proc putIntoNode(n: var PNode; x: TFullReg) = of rkInt: n.intVal = x.intVal of rkFloat: n.floatVal = x.floatVal of rkNode: - if nfIsRef in x.node.flags: n = x.node - else: n[] = x.node[] + if nfIsRef in x.node.flags: + n = x.node + else: + let destIsRef = nfIsRef in n.flags + n[] = x.node[] + # Ref-ness must be kept for the destination + if destIsRef: + n.flags.incl nfIsRef of rkRegisterAddr: putIntoNode(n, x.regAddr[]) of rkNodeAddr: n[] = x.nodeAddr[][] diff --git a/tests/vm/tref.nim b/tests/vm/tref.nim new file mode 100644 index 000000000..517a67fb0 --- /dev/null +++ b/tests/vm/tref.nim @@ -0,0 +1,12 @@ +static: + var + a: ref string + b: ref string + new a + + a[] = "Hello world" + b = a + + b[5] = 'c' + doAssert a[] == "Hellocworld" + doAssert b[] == "Hellocworld" \ No newline at end of file |