tobjconstr.nim 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. discard """
  2. output: '''
  3. (k: kindA, a: (x: "abc", z: @[1, 1, 3]), method: ())
  4. (k: kindA, a: (x: "abc", z: @[1, 2, 3]), method: ())
  5. (k: kindA, a: (x: "abc", z: @[1, 3, 3]), method: ())
  6. (k: kindA, a: (x: "abc", z: @[1, 4, 3]), method: ())
  7. (k: kindA, a: (x: "abc", z: @[1, 5, 3]), method: ())
  8. (k: kindA, a: (x: "abc", z: @[1, 6, 3]), method: ())
  9. (k: kindA, a: (x: "abc", z: @[1, 7, 3]), method: ())
  10. (k: kindA, a: (x: "abc", z: @[1, 8, 3]), method: ())
  11. (k: kindA, a: (x: "abc", z: @[1, 9, 3]), method: ())
  12. (k: kindA, a: (x: "abc", z: @[1, 10, 3]), method: ())
  13. (y: 0, x: 123)
  14. (y: 678, x: 123)
  15. (z: 89, y: 0, x: 128)
  16. (y: 678, x: 123)
  17. (y: 678, x: 123)
  18. (y: 0, x: 123)
  19. (y: 678, x: 123)
  20. (y: 123, x: 678)
  21. '''
  22. """
  23. type
  24. TArg = object
  25. x: string
  26. z: seq[int]
  27. TKind = enum kindXY, kindA
  28. TEmpty = object
  29. TDummy = ref object
  30. case k: TKind
  31. of kindXY: x, y: int
  32. of kindA:
  33. a: TArg
  34. `method`: TEmpty # bug #1791
  35. proc main() =
  36. for i in 1..10:
  37. let d = TDummy(k: kindA, a: TArg(x: "abc", z: @[1,i,3]), `method`: TEmpty())
  38. echo d[]
  39. main()
  40. # bug #6294
  41. type
  42. A = object of RootObj
  43. x*: int
  44. B = object of A
  45. y*: int
  46. BS = object of B
  47. C = object of BS
  48. z*: int
  49. # inherited fields are ignored, so no fields are set
  50. when true:
  51. var
  52. o: B
  53. o = B(x: 123)
  54. echo o
  55. o = B(y: 678, x: 123)
  56. echo o
  57. # inherited fields are ignored
  58. echo C(x: 128, z: 89) # (y: 0, x: 0)
  59. echo B(y: 678, x: 123) # (y: 678, x: 0)
  60. echo B(x: 123, y: 678) # (y: 678, x: 0)
  61. when true:
  62. # correct, both with `var` and `let`;
  63. var b=B(x: 123)
  64. echo b # (y: 0, x: 123)
  65. b=B(y: 678, x: 123)
  66. echo b # (y: 678, x: 123)
  67. b=B(y: b.x, x: b.y)
  68. echo b # (y: 123, x: 678)
  69. GC_fullCollect()