diff options
author | Andreas Rumpf <rumpf_a@web.de> | 2016-04-04 01:41:14 +0200 |
---|---|---|
committer | Andreas Rumpf <rumpf_a@web.de> | 2016-04-04 01:41:14 +0200 |
commit | 86e79f5cec118587c7e52f614c245176cf480597 (patch) | |
tree | db6d9825a07a7c8a3d01573cf4a6dfcafe405d9a | |
parent | cb3a38afa2de4401af55fbb7b6050f499b182bf4 (diff) | |
download | Nim-86e79f5cec118587c7e52f614c245176cf480597.tar.gz |
fixes #3804
-rw-r--r-- | compiler/vm.nim | 2 | ||||
-rw-r--r-- | compiler/vmgen.nim | 4 | ||||
-rw-r--r-- | tests/vm/twrong_concat.nim | 28 |
3 files changed, 33 insertions, 1 deletions
diff --git a/compiler/vm.nim b/compiler/vm.nim index 7be208089..1235a648d 100644 --- a/compiler/vm.nim +++ b/compiler/vm.nim @@ -123,7 +123,7 @@ template move(a, b: expr) {.immediate, dirty.} = system.shallowCopy(a, b) # XXX fix minor 'shallowCopy' overloading bug in compiler proc createStrKeepNode(x: var TFullReg; keepNode=true) = - if x.node.isNil: + if x.node.isNil or not keepNode: x.node = newNode(nkStrLit) elif x.node.kind == nkNilLit and keepNode: when defined(useNodeIds): diff --git a/compiler/vmgen.nim b/compiler/vmgen.nim index 43c7ca2db..7e506f8a0 100644 --- a/compiler/vmgen.nim +++ b/compiler/vmgen.nim @@ -102,6 +102,10 @@ proc gABC(ctx: PCtx; n: PNode; opc: TOpcode; a, b, c: TRegister = 0) = let ins = (opc.uint32 or (a.uint32 shl 8'u32) or (b.uint32 shl 16'u32) or (c.uint32 shl 24'u32)).TInstr + when false: + if ctx.code.len == 72: + writeStackTrace() + echo "generating ", opc ctx.code.add(ins) ctx.debug.add(n.info) diff --git a/tests/vm/twrong_concat.nim b/tests/vm/twrong_concat.nim new file mode 100644 index 000000000..538ea2527 --- /dev/null +++ b/tests/vm/twrong_concat.nim @@ -0,0 +1,28 @@ +discard """ + output: '''success''' +""" + +# bug #3804 + +#import sequtils + +type AnObj = ref object + field: string + +#proc aBug(objs: seq[AnObj]) {.compileTime.} = +# discard objs.mapIt(it.field & " bug") + +proc sameBug(objs: seq[AnObj]) {.compileTime.} = + var strSeq = newSeq[string](objs.len) + strSeq[0] = objs[0].field & " bug" + +static: + var objs: seq[AnObj] = @[] + objs.add(AnObj(field: "hello")) + + sameBug(objs) + # sameBug(objs) + echo objs[0].field + assert(objs[0].field == "hello") # fails, because (objs[0].field == "hello bug") - mutated! + +echo "success" |