summary refs log tree commit diff stats
path: root/tests
diff options
context:
space:
mode:
authorAraq <rumpf_a@web.de>2019-04-10 20:32:07 +0200
committerAraq <rumpf_a@web.de>2019-04-10 20:34:00 +0200
commit2846156e13b26ac566092e394e9900df52059039 (patch)
tree3df7699c9877e1bbf71431e5d30605ce8fe0a0be /tests
parentcb4e04d88e1bd24f148e410512eb9f9a7948f078 (diff)
downloadNim-2846156e13b26ac566092e394e9900df52059039.tar.gz
newruntime: raising an exception works but currently leaks memory because currentException global is not an 'owned' ref
Diffstat (limited to 'tests')
-rw-r--r--tests/destructor/tv2_raise.nim38
1 files changed, 38 insertions, 0 deletions
diff --git a/tests/destructor/tv2_raise.nim b/tests/destructor/tv2_raise.nim
new file mode 100644
index 000000000..75ccadd49
--- /dev/null
+++ b/tests/destructor/tv2_raise.nim
@@ -0,0 +1,38 @@
+discard """
+  cmd: '''nim c --newruntime $file'''
+  output: '''OK 2
+4 1'''
+"""
+
+import strutils, math
+import system / ansi_c
+import core / allocators
+
+proc mainA =
+  var e: owned(ref ValueError)
+  new(e)
+  e.msg = "message"
+  raise e
+
+proc main =
+  raise newException(ValueError, "argh")
+
+var ok = 0
+try:
+  mainA()
+except ValueError:
+  inc ok
+except:
+  discard
+
+try:
+  main()
+except ValueError:
+  inc ok
+except:
+  discard
+
+echo "OK ", ok
+
+let (a, d) = allocCounters()
+discard cprintf("%ld %ld\n", a, d)