targ_lefttoright.nim 917 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. discard """
  2. nimout: '''1,2
  3. 2,3
  4. 2,2
  5. 1,2
  6. 1,2
  7. 2,2
  8. 1,2
  9. '''
  10. output: '''1,2
  11. 2,3
  12. 1,2
  13. 2,2
  14. 1,2
  15. 1,2
  16. 2,2
  17. 1,2
  18. '''
  19. """
  20. template test =
  21. proc say(a, b: int) =
  22. echo a,",",b
  23. var a = 1
  24. say a, (a += 1; a) #1,2
  25. var b = 1
  26. say (b += 1; b), (b += 1; b) #2,3
  27. type C = object {.byRef.}
  28. i: int
  29. proc say(a, b: C) =
  30. echo a.i,",",b.i
  31. proc `+=`(x: var C, y: C) = x.i += y.i
  32. var c = C(i: 1)
  33. when nimvm: #XXX: This would output 2,2 in the VM, which is wrong
  34. discard
  35. else:
  36. say c, (c += C(i: 1); c) #1,2
  37. proc sayVar(a: var int, b: int) =
  38. echo a,",",b
  39. var d = 1
  40. sayVar d, (d += 1; d) #2,2
  41. var e = 1
  42. say (addr e)[], (e += 1; e) #1,2
  43. var f = 1
  44. say f, if false: f
  45. else: f += 1; f #1,2
  46. var g = 1
  47. say g + 1, if false: g
  48. else: g += 1; g #2,2
  49. proc `+=+`(x: var int, y: int): int = (inc(x, y); x)
  50. var h = 1
  51. say h, h +=+ 1 # 1,2
  52. test
  53. static:
  54. test