summary refs log tree commit diff stats
path: root/tests/destructor/tv2_raise.nim
diff options
context:
space:
mode:
Diffstat (limited to 'tests/destructor/tv2_raise.nim')
-rw-r--r--tests/destructor/tv2_raise.nim53
1 files changed, 53 insertions, 0 deletions
diff --git a/tests/destructor/tv2_raise.nim b/tests/destructor/tv2_raise.nim
new file mode 100644
index 000000000..66b0aec30
--- /dev/null
+++ b/tests/destructor/tv2_raise.nim
@@ -0,0 +1,53 @@
+discard """
+  valgrind: true
+  cmd: '''nim c -d:nimAllocStats --newruntime $file'''
+  output: '''OK 3
+(allocCount: 7, deallocCount: 4)'''
+"""
+
+import strutils, math
+import system / ansi_c
+
+proc mainA =
+  try:
+    var e: owned(ref ValueError)
+    new(e)
+    e.msg = "message"
+    raise e
+  except Exception as e:
+    raise
+
+
+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
+
+#  bug #11577
+
+proc newError*: owned(ref Exception) {.noinline.} =
+  new(result)
+
+proc mainC =
+  raise newError()
+
+try:
+  mainC()
+except:
+  inc ok
+
+echo "OK ", ok
+echo getAllocStats()