This commit is contained in:
parent
e2886eebb4
commit
0d8942d45e
7 changed files with 175 additions and 15 deletions
47
tests/destructor/tdestructor3.nim
Normal file
47
tests/destructor/tdestructor3.nim
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
discard """
|
||||
output: '''assign
|
||||
destroy
|
||||
destroy
|
||||
destroy Foo: 5
|
||||
5
|
||||
destroy Foo: 123
|
||||
123'''
|
||||
"""
|
||||
|
||||
# bug #2821
|
||||
{.experimental.}
|
||||
|
||||
type T = object
|
||||
|
||||
proc `=`(lhs: var T, rhs: T) =
|
||||
echo "assign"
|
||||
|
||||
proc `=destroy`(v: var T) =
|
||||
echo "destroy"
|
||||
|
||||
block:
|
||||
var v1 : T
|
||||
var v2 : T = v1
|
||||
|
||||
|
||||
# bug #1632
|
||||
|
||||
type
|
||||
Foo = object of RootObj
|
||||
x: int
|
||||
|
||||
proc `=destroy`(a: var Foo) =
|
||||
echo "destroy Foo: " & $a.x
|
||||
|
||||
template toFooPtr(a: int{lit}): ptr Foo =
|
||||
var temp = Foo(x:a)
|
||||
temp.addr
|
||||
|
||||
proc test(a: ptr Foo) =
|
||||
echo a[].x
|
||||
|
||||
proc main =
|
||||
test(toFooPtr(5))
|
||||
test(toFooPtr(123))
|
||||
|
||||
main()
|
||||
Loading…
Add table
Add a link
Reference in a new issue