treset.nim 655 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. static:
  2. type Obj = object
  3. field: int
  4. var o = Obj(field: 1)
  5. reset(o)
  6. doAssert o.field == 0
  7. var x = 4
  8. reset(x)
  9. doAssert x == 0
  10. static:
  11. type ObjB = object
  12. field: int
  13. var o = ObjB(field: 1)
  14. o = default(ObjB)
  15. doAssert o.field == 0
  16. static:
  17. var i = 2
  18. reset(i)
  19. doAssert i == 0
  20. static:
  21. var i = new int
  22. reset(i)
  23. doAssert i.isNil
  24. static:
  25. var s = @[1, 2, 3]
  26. reset(s)
  27. doAssert s == @[]
  28. static:
  29. proc f() =
  30. var i = 2
  31. reset(i)
  32. doAssert i == 0
  33. f()
  34. proc main =
  35. var y = [1, 2, 3, 4]
  36. y = default(array[4, int])
  37. for a in y: doAssert(a == 0)
  38. var x = 4
  39. x = default(int)
  40. doAssert x == 0
  41. main()