tsink.nim 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. discard """
  2. matrix: "--mm:arc"
  3. """
  4. type AnObject = object of RootObj
  5. value*: int
  6. proc mutate(shit: sink AnObject) =
  7. shit.value = 1
  8. proc foo = # bug #23359
  9. var bar = AnObject(value: 42)
  10. mutate(bar)
  11. doAssert bar.value == 42
  12. foo()
  13. block: # bug #23902
  14. proc foo(a: sink string): auto = (a, a)
  15. proc bar(a: sink int): auto = return a
  16. proc foo(a: sink string) =
  17. var x = (a, a)
  18. block: # bug #24175
  19. block:
  20. func mutate(o: sink string): string =
  21. o[1] = '1'
  22. result = o
  23. static:
  24. let s = "999"
  25. let m = mutate(s)
  26. doAssert s == "999"
  27. doAssert m == "919"
  28. func foo() =
  29. let s = "999"
  30. let m = mutate(s)
  31. doAssert s == "999"
  32. doAssert m == "919"
  33. static:
  34. foo()
  35. foo()
  36. block:
  37. type O = object
  38. a: int
  39. func mutate(o: sink O): O =
  40. o.a += 1
  41. o
  42. static:
  43. let x = O(a: 1)
  44. let y = mutate(x)
  45. doAssert x.a == 1
  46. doAssert y.a == 2
  47. proc foo() =
  48. let x = O(a: 1)
  49. let y = mutate(x)
  50. doAssert x.a == 1
  51. doAssert y.a == 2
  52. static:
  53. foo()
  54. foo()