mirror of
https://github.com/nim-lang/Nim.git
synced 2026-02-15 15:44:14 +00:00
fixes #3804
This commit is contained in:
@@ -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):
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
28
tests/vm/twrong_concat.nim
Normal file
28
tests/vm/twrong_concat.nim
Normal file
@@ -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"
|
||||
Reference in New Issue
Block a user