tconstobj.nim 779 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. discard """
  2. output: '''
  3. (name: "hello")
  4. (-1, 0)
  5. (FirstName: "James", LastName: "Franco")
  6. '''
  7. """
  8. # bug #2774, bug #3195
  9. type Foo = object
  10. name: string
  11. const fooArray = [
  12. Foo(name: "hello")
  13. ]
  14. echo fooArray[0]
  15. type
  16. Position = object
  17. x, y: int
  18. proc `$`(pos: Position): string =
  19. result = "(" & $pos.x & ", " & $pos.y & ")"
  20. proc newPos(x, y: int): Position =
  21. result = Position(x: x, y: y)
  22. const
  23. offset: array[1..4, Position] = [
  24. newPos(-1, 0),
  25. newPos(1, 0),
  26. newPos(0, -1),
  27. newPos(0, 1)
  28. ]
  29. echo offset[1]
  30. # bug #1547
  31. import tables
  32. type Person* = object
  33. FirstName*: string
  34. LastName*: string
  35. let people = {
  36. "001": Person(FirstName: "James", LastName: "Franco")
  37. }.toTable()
  38. echo people["001"]