summary refs log blame commit diff stats
path: root/tests/destructor/tdestructor2.nim
blob: 34fa466af17401023bdde3026adf6cbb13dc45d7 (plain) (tree)
1
2
3
4
5
6
7
8
           

                                                                            

   

                
    


                 

                                
                            
 





                                          




                               
 
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()