summary refs log tree commit diff stats
path: root/tests/generics
diff options
context:
space:
mode:
authorJason Beetham <beefers331@gmail.com>2021-09-13 01:35:19 -0600
committerGitHub <noreply@github.com>2021-09-13 09:35:19 +0200
commit3f3e0fa303a2729d0d6a9ffe54936c1c830e2d7e (patch)
treeac37b283db52feb6b6d99f15928834ab86e8c8b9 /tests/generics
parent5d1608c9764416e74b36f6a772f16a66d58ddc28 (diff)
downloadNim-3f3e0fa303a2729d0d6a9ffe54936c1c830e2d7e.tar.gz
Fixed #18838 (#18841) [backport]
Diffstat (limited to 'tests/generics')
-rw-r--r--tests/generics/trecursivegenerics.nim36
1 files changed, 35 insertions, 1 deletions
diff --git a/tests/generics/trecursivegenerics.nim b/tests/generics/trecursivegenerics.nim
index 56c074e3f..e4c0e720f 100644
--- a/tests/generics/trecursivegenerics.nim
+++ b/tests/generics/trecursivegenerics.nim
@@ -1,6 +1,7 @@
 block: # Replicates #18728
   type
     FlipFlop[A, B] = ref object
+      val: A
       next: FlipFlop[B, A]
   
     Trinary[A, B, C] = ref object
@@ -9,4 +10,37 @@ block: # Replicates #18728
   assert typeof(FlipFlop[int, string]().next) is FlipFlop[string, int]
   assert typeof(FlipFlop[string, int]().next) is FlipFlop[int, string]
   assert typeof(Trinary[int, float, string]().next) is Trinary[float, string, int]
-  assert typeof(Trinary[int, float, string]().next.next) is Trinary[string, int, float]
\ No newline at end of file
+  assert typeof(Trinary[int, float, string]().next.next) is Trinary[string, int, float]
+  var a = FlipFlop[int, string](val: 100, next: FlipFlop[string, int](val: "Hello"))
+  assert a.val == 100
+  assert a.next.val == "Hello"
+
+block: # 18838
+  type
+    DoublyLinkedNodeObj[T] = object
+      value: T
+
+    DoublyLinkedNode[T] = ref DoublyLinkedNodeObj[T]
+
+    Item[T] = ref object
+      link: DoublyLinkedNode[Item[T]]
+
+    Box = object
+
+  proc newDoublyLinkedNode[T](value: T): DoublyLinkedNode[T] =
+    new(result)
+    result.value = value 
+
+  let link = newDoublyLinkedNode(Item[Box]())
+
+import lists
+block:
+  type
+    Box = object
+    Item[T] = ref object
+      link:DoublyLinkedNode[ Item[T] ]
+
+    ItemSimple = ref object
+      link:DoublyLinkedNode[ ItemSimple ]
+
+  let link = newDoublyLinkedNode( Item[Box]() )
\ No newline at end of file