summary refs log tree commit diff stats
path: root/tests/ccgbugs/tcgbug.nim
diff options
context:
space:
mode:
Diffstat (limited to 'tests/ccgbugs/tcgbug.nim')
-rw-r--r--tests/ccgbugs/tcgbug.nim88
1 files changed, 87 insertions, 1 deletions
diff --git a/tests/ccgbugs/tcgbug.nim b/tests/ccgbugs/tcgbug.nim
index ba0c16fa8..2eddc6fdd 100644
--- a/tests/ccgbugs/tcgbug.nim
+++ b/tests/ccgbugs/tcgbug.nim
@@ -2,7 +2,9 @@ discard """
 output: '''
 success
 M1 M2
+ok
 '''
+matrix: "--mm:refc;--mm:orc"
 """
 
 type
@@ -23,6 +25,7 @@ q(a)
 
 # bug #914
 when defined(windows):
+  import std/widestrs
   var x = newWideCString("Hello")
 
 echo "success"
@@ -39,7 +42,8 @@ type
 var k = PFuture[void]()
 
 
-##bug #9297
+##bug #9297 and #13281
+
 import strutils
 
 type
@@ -58,6 +62,14 @@ type
       of M2: b:float
       of M3: c:cstring
 
+  Helper* {.exportc: "PublicHelper".} = object
+    case isKind: bool
+      of true:
+        formatted: string
+      of false:
+        parsed1: string
+        parsed2: string
+
 proc newMyObject(kind: MyKind, val: string): MyObject =
   result = MyObject(kind: kind)
 
@@ -75,3 +87,77 @@ proc newMyObjectRef(kind: MyKind, val: string): MyObjectRef =
 
 
 echo newMyObject(M1, "2").kind, " ", newMyObjectRef(M2, "3").kind
+
+
+proc test(c: Helper): string =
+  c.formatted
+
+echo test(Helper(isKind: true, formatted: "ok"))
+
+
+# bug #19613
+
+type
+  Eth2Digest = object
+    data: array[42, byte]
+
+  BlockId* = object
+    root*: Eth2Digest
+
+  BlockSlotId* = object
+    bid*: BlockId
+    slot*: uint64
+
+func init*(T: type BlockSlotId, bid: BlockId, slot: uint64): T =
+  #debugecho "init ", bid, " ", slot
+  BlockSlotId(bid: bid, slot: slot)
+
+proc bug19613 =
+  var x: BlockSlotId
+  x.bid.root.data[0] = 42
+
+  x =
+    if x.slot > 0:
+      BlockSlotId.init(x.bid, x.slot)
+    else:
+      BlockSlotId.init(x.bid, x.slot)
+  doAssert x.bid.root.data[0] == 42
+
+bug19613()
+
+proc foo = # bug #23280
+  let foo = @[1,2,3,4,5,6]
+  doAssert toOpenArray(foo, 0, 5).len == 6
+  doAssert toOpenArray(foo, 0, 5).len mod 6 == 0 # this should output 0
+  doAssert toOpenArray(foo, 0, 5).max mod 6 == 0
+  let L = toOpenArray(foo, 0, 5).len
+  doAssert L mod 6 == 0 
+
+foo()
+
+block: # bug #9940
+  {.emit:"""/*TYPESECTION*/
+typedef struct { int base; } S;
+""".}
+
+  type S {.importc: "S", completeStruct.} = object
+    base: cint
+  proc init(x:ptr S) =
+    x.base = 1
+
+  type
+    Foo = object
+      a: seq[float]
+      b: seq[float]
+      c: seq[float]
+      d: seq[float]
+      s: S
+
+  proc newT(): Foo =
+    var t: Foo
+    t.s.addr.init
+    doAssert t.s.base == 1
+    t
+
+  var t = newT()
+  doAssert t.s.base == 1