tmitems_vm.nim 808 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. discard """
  2. nimout: '''13'''
  3. output: '''3
  4. 3
  5. 3'''
  6. """
  7. # bug #3731
  8. var list {.compileTime.} = newSeq[int]()
  9. macro calc*(): void =
  10. list.add(1)
  11. for c in list.mitems:
  12. c = 13
  13. for c in list:
  14. echo c
  15. calc()
  16. # bug #3859
  17. import macros
  18. macro m: void =
  19. var s = newseq[NimNode](3)
  20. # var s: array[3,NimNode] # not working either
  21. for i in 0..<s.len: s[i] = newLit(3) # works
  22. #for x in s.mitems: x = newLit(3)
  23. result = newStmtList()
  24. for i in s:
  25. result.add newCall(bindsym"echo", i)
  26. m()
  27. # bug 4741 & 5013
  28. proc test() =
  29. var s = [("baz", 42), ("bath", 42)]
  30. for i in s.mitems:
  31. i[1] = 3
  32. doAssert(s == [("baz", 3), ("bath", 3)])
  33. static:
  34. test()
  35. var s = [("baz", 42), ("bath", 42)]
  36. for i in s.mitems:
  37. i[1] = 3
  38. doAssert(s == [("baz", 3), ("bath", 3)])