tgenericconst.nim 544 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. discard """
  2. output: '''
  3. @[1, 2]
  4. @[3, 4]
  5. 1
  6. '''
  7. """
  8. # https://github.com/nim-lang/Nim/issues/5756
  9. type
  10. Vec*[N : static[int]] = object
  11. x: int
  12. arr*: array[N, int32]
  13. Mat*[M,N: static[int]] = object
  14. x: int
  15. arr*: array[M, Vec[N]]
  16. proc vec2*(x,y:int32) : Vec[2] =
  17. result.arr = [x,y]
  18. result.x = 10
  19. proc mat2*(a,b: Vec[2]): Mat[2,2] =
  20. result.arr = [a,b]
  21. result.x = 20
  22. const M = mat2(vec2(1, 2), vec2(3, 4))
  23. let m1 = M
  24. echo @(m1.arr[0].arr)
  25. echo @(m1.arr[1].arr)
  26. proc foo =
  27. let m2 = M
  28. echo m1.arr[0].arr[0]
  29. foo()