tobjconstr.nim 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. proc main2 =
  50. # inherited fields are ignored, so no fields are set
  51. when true:
  52. var
  53. o: B
  54. o = B(x: 123)
  55. echo o
  56. o = B(y: 678, x: 123)
  57. echo o
  58. # inherited fields are ignored
  59. echo C(x: 128, z: 89) # (y: 0, x: 0)
  60. echo B(y: 678, x: 123) # (y: 678, x: 0)
  61. echo B(x: 123, y: 678) # (y: 678, x: 0)
  62. when true:
  63. # correct, both with `var` and `let`;
  64. var b=B(x: 123)
  65. echo b # (y: 0, x: 123)
  66. b=B(y: 678, x: 123)
  67. echo b # (y: 678, x: 123)
  68. b=B(y: b.x, x: b.y)
  69. echo b # (y: 123, x: 678)
  70. main2()
  71. GC_fullCollect()