tref.nim 955 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. static:
  2. var
  3. a: ref string
  4. b: ref string
  5. new a
  6. a[] = "Hello world"
  7. b = a
  8. b[5] = 'c'
  9. doAssert a[] == "Hellocworld"
  10. doAssert b[] == "Hellocworld"
  11. proc notGlobal() =
  12. var
  13. a: ref string
  14. b: ref string
  15. new a
  16. a[] = "Hello world"
  17. b = a
  18. b[5] = 'c'
  19. doAssert a[] == "Hellocworld"
  20. doAssert b[] == "Hellocworld"
  21. notGlobal()
  22. static: # bug 6081
  23. block:
  24. type Obj = object
  25. field: ref int
  26. var i: ref int
  27. new(i)
  28. var r = Obj(field: i)
  29. var rr = r
  30. r.field = nil
  31. doAssert rr.field != nil
  32. proc foo() = # Proc to avoid special global logic
  33. var s: seq[ref int]
  34. var i: ref int
  35. new(i)
  36. s.add(i)
  37. var head = s[0]
  38. s[0] = nil
  39. doAssert head != nil
  40. foo()
  41. static:
  42. block: # global alias
  43. var s: ref int
  44. new(s)
  45. var ss = s
  46. s[] = 1
  47. doAssert ss[] == 1
  48. static: # bug #8402
  49. type R = ref object
  50. var empty: R
  51. let otherEmpty = empty