mirror of
https://github.com/nim-lang/Nim.git
synced 2025-12-31 02:12:11 +00:00
27 lines
415 B
Nim
27 lines
415 B
Nim
discard """
|
|
output: '''some text
|
|
Destructor called!'''
|
|
"""
|
|
|
|
type
|
|
TMyObj = object
|
|
x, y: int
|
|
p: pointer
|
|
|
|
proc destruct(o: var TMyObj) {.destructor.} =
|
|
if o.p != nil: dealloc o.p
|
|
echo "Destructor called!"
|
|
|
|
proc open: TMyObj =
|
|
# allow for superfluous ()
|
|
result = (TMyObj(x: 1, y: 2, p: alloc(3)))
|
|
|
|
|
|
proc `$`(x: TMyObj): string = $x.y
|
|
|
|
proc main() =
|
|
var x = open()
|
|
echo "some text"
|
|
|
|
main()
|