summary refs log tree commit diff stats
path: root/tests/destructor/tdestructor2.nim
blob: 34fa466af17401023bdde3026adf6cbb13dc45d7 (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
27
discard """
  line: 23
  nimout: " usage of a type with a destructor in a non destructible context"
"""

{.experimental.}

type
  TMyObj = object
    x, y: int
    p: pointer

proc `=destroy`(o: var TMyObj) =
  if o.p != nil: dealloc o.p

proc open: TMyObj =
  result = TMyObj(x: 1, y: 2, p: alloc(3))


proc `$`(x: TMyObj): string = $x.y

proc foo =
  discard open()

# XXX doesn't trigger this yet:
#echo open()