twrong_concat.nim 566 B

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