tconst_views.nim 422 B

123456789101112131415161718192021222324252627
  1. discard """
  2. cmd: "nim c --experimental:views $file"
  3. output: '''(data: [1, 2, 3], other: 4)
  4. [1, 20, 3]'''
  5. """
  6. type
  7. Foo = object
  8. data: openArray[int]
  9. other: int
  10. const
  11. c = Foo(data: [1, 2, 3], other: 4)
  12. c2 = Foo(data: [1, 20, 3], other: 4)
  13. proc `$`(x: openArray[int]): string =
  14. result = "["
  15. for i in x:
  16. if result.len > 1: result.add ", "
  17. result.add $i
  18. result.add "]"
  19. echo c
  20. echo c2.data