summary refs log tree commit diff stats
path: root/tests/destructor/turn_destroy_into_finalizer.nim
blob: 1409c1c5768a469b50081de2c4d3d3579a1c94cc (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
discard """
  output: "turn_destroy_into_finalizer works"
  joinable: false
"""

type
  Foo = object
    id: int

var destroyed: int

proc `=destroy`(x: var Foo) =
  #echo "finally ", x.id
  inc destroyed

proc main =
  var r: ref Foo
  for i in 1..50_000:
    new(r)
    r.id = i
  if destroyed > 30_000:
    echo "turn_destroy_into_finalizer works"
  else:
    echo "turn_destroy_into_finalizer failed: ", destroyed

main()