twrong_concat.nim 511 B

1234567891011121314151617181920212223
  1. # bug #3804
  2. #import sequtils
  3. type AnObj = ref object
  4. field: string
  5. #proc aBug(objs: seq[AnObj]) {.compileTime.} =
  6. # discard objs.mapIt(it.field & " bug")
  7. proc sameBug(objs: seq[AnObj]) {.compileTime.} =
  8. var strSeq = newSeq[string](objs.len)
  9. strSeq[0] = objs[0].field & " bug"
  10. static:
  11. var objs: seq[AnObj] = @[]
  12. objs.add(AnObj(field: "hello"))
  13. sameBug(objs)
  14. # sameBug(objs)
  15. echo objs[0].field
  16. doAssert(objs[0].field == "hello") # fails, because (objs[0].field == "hello bug") - mutated!