tcgbug.nim 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. discard """
  2. output: '''
  3. success
  4. M1 M2
  5. ok
  6. '''
  7. """
  8. type
  9. TObj = object
  10. x, y: int
  11. PObj = ref TObj
  12. proc p(a: PObj) =
  13. a.x = 0
  14. proc q(a: var PObj) =
  15. a.p()
  16. var
  17. a: PObj
  18. new(a)
  19. q(a)
  20. # bug #914
  21. when defined(windows):
  22. import std/widestrs
  23. var x = newWideCString("Hello")
  24. echo "success"
  25. # bug #833
  26. type
  27. PFuture*[T] = ref object
  28. value*: T
  29. finished*: bool
  30. cb: proc (future: PFuture[T]) {.closure.}
  31. var k = PFuture[void]()
  32. ##bug #9297 and #13281
  33. import strutils
  34. type
  35. MyKind = enum
  36. M1, M2, M3
  37. MyObject {.exportc: "ExtObject"} = object
  38. case kind: MyKind
  39. of M1: a:int
  40. of M2: b:float
  41. of M3: c:cstring
  42. MyObjectRef {.exportc: "ExtObject2"} = ref object
  43. case kind: MyKind
  44. of M1: a:int
  45. of M2: b:float
  46. of M3: c:cstring
  47. Helper* {.exportc: "PublicHelper".} = object
  48. case isKind: bool
  49. of true:
  50. formatted: string
  51. of false:
  52. parsed1: string
  53. parsed2: string
  54. proc newMyObject(kind: MyKind, val: string): MyObject =
  55. result = MyObject(kind: kind)
  56. case kind
  57. of M1: result.a = parseInt(val)
  58. of M2: result.b = parseFloat(val)
  59. of M3: result.c = val
  60. proc newMyObjectRef(kind: MyKind, val: string): MyObjectRef =
  61. result = MyObjectRef(kind: kind)
  62. case kind
  63. of M1: result.a = parseInt(val)
  64. of M2: result.b = parseFloat(val)
  65. of M3: result.c = val
  66. echo newMyObject(M1, "2").kind, " ", newMyObjectRef(M2, "3").kind
  67. proc test(c: Helper): string =
  68. c.formatted
  69. echo test(Helper(isKind: true, formatted: "ok"))
  70. # bug #19613
  71. type
  72. Eth2Digest = object
  73. data: array[42, byte]
  74. BlockId* = object
  75. root*: Eth2Digest
  76. BlockSlotId* = object
  77. bid*: BlockId
  78. slot*: uint64
  79. func init*(T: type BlockSlotId, bid: BlockId, slot: uint64): T =
  80. #debugecho "init ", bid, " ", slot
  81. BlockSlotId(bid: bid, slot: slot)
  82. proc bug19613 =
  83. var x: BlockSlotId
  84. x.bid.root.data[0] = 42
  85. x =
  86. if x.slot > 0:
  87. BlockSlotId.init(x.bid, x.slot)
  88. else:
  89. BlockSlotId.init(x.bid, x.slot)
  90. doAssert x.bid.root.data[0] == 42
  91. bug19613()