summary refs log tree commit diff stats
path: root/tests/destructor
diff options
context:
space:
mode:
authorAraq <rumpf_a@web.de>2020-05-02 13:37:57 +0200
committerAndreas Rumpf <rumpf_a@web.de>2020-05-02 22:31:19 +0200
commit87ac28d19ac9740d871ac85a8c79178344c6b7b3 (patch)
treec5eda6ef081a806983b9c957d359f16c3964e2dd /tests/destructor
parent4301a7bdf06159501f8affc3e7f8de80a196cd4f (diff)
downloadNim-87ac28d19ac9740d871ac85a8c79178344c6b7b3.tar.gz
fixes #14159 [backport:1.2]
Diffstat (limited to 'tests/destructor')
-rw-r--r--tests/destructor/tcycle3.nim33
1 files changed, 33 insertions, 0 deletions
diff --git a/tests/destructor/tcycle3.nim b/tests/destructor/tcycle3.nim
index 584321bab..8662136e7 100644
--- a/tests/destructor/tcycle3.nim
+++ b/tests/destructor/tcycle3.nim
@@ -2,6 +2,8 @@ discard """
   output: '''BEGIN
 END
 END 2
+cpu.nes false
+cpu step nes is nil? - false
 0'''
   cmd: '''nim c --gc:orc $file'''
 """
@@ -59,7 +61,38 @@ proc main =
   c.run
   echo "END 2"
 
+# bug #14159
+type
+  NES = ref object
+    cpu: CPU
+    apu: APU
+
+  CPU = ref object
+    nes: NES
+
+  APU = object
+    nes: NES
+    cpu: CPU
+
+proc initAPU(nes: sink NES): APU {.nosinks.} =
+  result.nes = nes
+  result.cpu = nes.cpu
+
+proc step(cpu: CPU): int =
+  echo "cpu.nes ", cpu.isNil
+  echo "cpu step nes is nil? - ", cpu.nes.isNil()
+
+proc newNES(): NES =
+  new result
+  result.cpu = CPU(nes: result)
+  result.apu = initAPU(result)
+
+proc bug14159 =
+  var nesConsole = newNES()
+  discard nesConsole.cpu.step()
+
 let mem = getOccupiedMem()
 main()
+bug14159()
 GC_fullCollect()
 echo getOccupiedMem() - mem