tcgbug.nim 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. discard """
  2. output: '''
  3. success
  4. M1 M2
  5. ok
  6. '''
  7. matrix: "--mm:refc;--mm:orc"
  8. """
  9. type
  10. TObj = object
  11. x, y: int
  12. PObj = ref TObj
  13. proc p(a: PObj) =
  14. a.x = 0
  15. proc q(a: var PObj) =
  16. a.p()
  17. var
  18. a: PObj
  19. new(a)
  20. q(a)
  21. # bug #914
  22. when defined(windows):
  23. import std/widestrs
  24. var x = newWideCString("Hello")
  25. echo "success"
  26. # bug #833
  27. type
  28. PFuture*[T] = ref object
  29. value*: T
  30. finished*: bool
  31. cb: proc (future: PFuture[T]) {.closure.}
  32. var k = PFuture[void]()
  33. ##bug #9297 and #13281
  34. import strutils
  35. type
  36. MyKind = enum
  37. M1, M2, M3
  38. MyObject {.exportc: "ExtObject"} = object
  39. case kind: MyKind
  40. of M1: a:int
  41. of M2: b:float
  42. of M3: c:cstring
  43. MyObjectRef {.exportc: "ExtObject2"} = ref object
  44. case kind: MyKind
  45. of M1: a:int
  46. of M2: b:float
  47. of M3: c:cstring
  48. Helper* {.exportc: "PublicHelper".} = object
  49. case isKind: bool
  50. of true:
  51. formatted: string
  52. of false:
  53. parsed1: string
  54. parsed2: string
  55. proc newMyObject(kind: MyKind, val: string): MyObject =
  56. result = MyObject(kind: kind)
  57. case kind
  58. of M1: result.a = parseInt(val)
  59. of M2: result.b = parseFloat(val)
  60. of M3: result.c = val
  61. proc newMyObjectRef(kind: MyKind, val: string): MyObjectRef =
  62. result = MyObjectRef(kind: kind)
  63. case kind
  64. of M1: result.a = parseInt(val)
  65. of M2: result.b = parseFloat(val)
  66. of M3: result.c = val
  67. echo newMyObject(M1, "2").kind, " ", newMyObjectRef(M2, "3").kind
  68. proc test(c: Helper): string =
  69. c.formatted
  70. echo test(Helper(isKind: true, formatted: "ok"))
  71. # bug #19613
  72. type
  73. Eth2Digest = object
  74. data: array[42, byte]
  75. BlockId* = object
  76. root*: Eth2Digest
  77. BlockSlotId* = object
  78. bid*: BlockId
  79. slot*: uint64
  80. func init*(T: type BlockSlotId, bid: BlockId, slot: uint64): T =
  81. #debugecho "init ", bid, " ", slot
  82. BlockSlotId(bid: bid, slot: slot)
  83. proc bug19613 =
  84. var x: BlockSlotId
  85. x.bid.root.data[0] = 42
  86. x =
  87. if x.slot > 0:
  88. BlockSlotId.init(x.bid, x.slot)
  89. else:
  90. BlockSlotId.init(x.bid, x.slot)
  91. doAssert x.bid.root.data[0] == 42
  92. bug19613()
  93. proc foo = # bug #23280
  94. let foo = @[1,2,3,4,5,6]
  95. doAssert toOpenArray(foo, 0, 5).len == 6
  96. doAssert toOpenArray(foo, 0, 5).len mod 6 == 0 # this should output 0
  97. doAssert toOpenArray(foo, 0, 5).max mod 6 == 0
  98. let L = toOpenArray(foo, 0, 5).len
  99. doAssert L mod 6 == 0
  100. foo()
  101. block: # bug #9940
  102. {.emit:"""/*TYPESECTION*/
  103. typedef struct { int base; } S;
  104. """.}
  105. type S {.importc: "S", completeStruct.} = object
  106. base: cint
  107. proc init(x:ptr S) =
  108. x.base = 1
  109. type
  110. Foo = object
  111. a: seq[float]
  112. b: seq[float]
  113. c: seq[float]
  114. d: seq[float]
  115. s: S
  116. proc newT(): Foo =
  117. var t: Foo
  118. t.s.addr.init
  119. doAssert t.s.base == 1
  120. t
  121. var t = newT()
  122. doAssert t.s.base == 1