diff options
Diffstat (limited to 'tests/destructor')
-rw-r--r-- | tests/destructor/tdestructor3.nim | 47 | ||||
-rw-r--r-- | tests/destructor/tdictdestruct.nim | 20 |
2 files changed, 47 insertions, 20 deletions
diff --git a/tests/destructor/tdestructor3.nim b/tests/destructor/tdestructor3.nim new file mode 100644 index 000000000..0968f1fd7 --- /dev/null +++ b/tests/destructor/tdestructor3.nim @@ -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() diff --git a/tests/destructor/tdictdestruct.nim b/tests/destructor/tdictdestruct.nim deleted file mode 100644 index 17ded4853..000000000 --- a/tests/destructor/tdictdestruct.nim +++ /dev/null @@ -1,20 +0,0 @@ - -type - TDict[TK, TV] = object - k: TK - v: TV - PDict[TK, TV] = ref TDict[TK, TV] - -proc fakeNew[T](x: var ref T, destroy: proc (a: ref T) {.nimcall.}) = - discard - -proc destroyDict[TK, TV](a: PDict[TK, TV]) = - return -proc newDict[TK, TV](a: TK, b: TV): PDict[TK, TV] = - fakeNew(result, destroyDict[TK, TV]) - -# Problem: destroyDict is not instantiated when newDict is instantiated! - -discard newDict("a", "b") - - |