Nim/tests/destructor/tv2_raise.nim
Andreas Rumpf fb641483f0
arc optimizations (#13325)
* scope based destructors
* handle 'or' and 'and' expressions properly, see the new test arc/tcontrolflow.nim
* make this branch mergable, logic is disabled for now
2020-03-18 16:57:34 +01:00

53 lines
696 B
Nim

discard """
valgrind: true
cmd: '''nim c -d:nimAllocStats --newruntime $file'''
output: '''OK 3
(allocCount: 8, deallocCount: 5)'''
"""
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()