treset.nim 680 B

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