tsetlen.nim 485 B

12345678910111213141516171819202122232425262728293031
  1. type Foo = object
  2. index: int
  3. block:
  4. proc fun[T]() =
  5. var foo: T
  6. var n = 10
  7. var foos: seq[T]
  8. foos.setLen n
  9. n.inc
  10. foos.setLen n
  11. for i in 0 ..< n:
  12. let temp = foos[i]
  13. when T is object:
  14. doAssert temp.index == 0
  15. when T is ref object:
  16. doAssert temp == nil
  17. doAssert temp == foo
  18. static:
  19. fun[Foo]()
  20. fun[int]()
  21. fun[float]()
  22. fun[string]()
  23. fun[(int, string)]()
  24. fun[ref Foo]()
  25. fun[seq[int]]()