parent
1655103d83
commit
58e88dbf12
1 changed files with 52 additions and 0 deletions
52
tests/destructor/t9440.nim
Normal file
52
tests/destructor/t9440.nim
Normal file
|
|
@ -0,0 +1,52 @@
|
||||||
|
discard """
|
||||||
|
matrix: "--gc:refc; --gc:orc; --gc:arc"
|
||||||
|
output: '''
|
||||||
|
()
|
||||||
|
Destroyed
|
||||||
|
()
|
||||||
|
Destroyed
|
||||||
|
()
|
||||||
|
Destroyed
|
||||||
|
end
|
||||||
|
-------------------------
|
||||||
|
()
|
||||||
|
Destroyed
|
||||||
|
end
|
||||||
|
'''
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
# bug #9440
|
||||||
|
block:
|
||||||
|
type
|
||||||
|
X = object
|
||||||
|
|
||||||
|
proc `=destroy`(x: var X) =
|
||||||
|
echo "Destroyed"
|
||||||
|
|
||||||
|
proc main() =
|
||||||
|
for x in 0 .. 2:
|
||||||
|
var obj = X()
|
||||||
|
echo obj
|
||||||
|
# The destructor call is invoked after "end" is printed
|
||||||
|
echo "end"
|
||||||
|
|
||||||
|
main()
|
||||||
|
|
||||||
|
echo "-------------------------"
|
||||||
|
|
||||||
|
block:
|
||||||
|
type
|
||||||
|
X = object
|
||||||
|
|
||||||
|
proc `=destroy`(x: var X) =
|
||||||
|
echo "Destroyed"
|
||||||
|
|
||||||
|
proc main() =
|
||||||
|
block:
|
||||||
|
var obj = X()
|
||||||
|
echo obj
|
||||||
|
# The destructor is not called when obj goes out of scope
|
||||||
|
echo "end"
|
||||||
|
|
||||||
|
main()
|
||||||
Loading…
Add table
Add a link
Reference in a new issue