tconstobj.nim 535 B

12345678910111213141516171819202122232425262728293031323334353637
  1. discard """
  2. output: '''(name: hello)
  3. (-1, 0)'''
  4. """
  5. # bug #2774, bug #3195
  6. type Foo = object
  7. name: string
  8. const fooArray = [
  9. Foo(name: "hello")
  10. ]
  11. echo fooArray[0]
  12. type
  13. Position = object
  14. x, y: int
  15. proc `$`(pos: Position): string =
  16. result = "(" & $pos.x & ", " & $pos.y & ")"
  17. proc newPos(x, y: int): Position =
  18. result = Position(x: x, y: y)
  19. const
  20. offset: array[1..4, Position] = [
  21. newPos(-1, 0),
  22. newPos(1, 0),
  23. newPos(0, -1),
  24. newPos(0, 1)
  25. ]
  26. echo offset[1]