tobjconstr.nim 1.8 KB

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