diff options
author | cooldome <ariabushenko@gmail.com> | 2021-01-15 18:16:24 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-01-15 18:16:24 +0000 |
commit | fc9cf2088d8ba969115a335239d57c05fbee9ad4 (patch) | |
tree | 657b04a36bac4bb1ffdf9993cb2f183571bf2554 /tests | |
parent | 52cf7280019c943dd7df33d0dd693931e6a116ee (diff) | |
download | Nim-fc9cf2088d8ba969115a335239d57c05fbee9ad4.tar.gz |
Fix 16722 (#16730)
* fix #16722 * fix spacing * spacing
Diffstat (limited to 'tests')
-rw-r--r-- | tests/arc/t14383.nim | 44 |
1 files changed, 43 insertions, 1 deletions
diff --git a/tests/arc/t14383.nim b/tests/arc/t14383.nim index 85f90d1c8..c5f0e08ac 100644 --- a/tests/arc/t14383.nim +++ b/tests/arc/t14383.nim @@ -125,4 +125,46 @@ proc main = let rankdef = avals echo avals.len, " ", rankdef.len -main() \ No newline at end of file +main() + + +#------------------------------------------------------------------------------ +# Issue #16722, ref on distinct type, wrong destructors called +#------------------------------------------------------------------------------ + +type + Obj = object of RootObj + ObjFinal = object + ObjRef = ref Obj + ObjFinalRef = ref ObjFinal + D = distinct Obj + DFinal = distinct ObjFinal + DRef = ref D + DFinalRef = ref DFinal + +proc `=destroy`(o: var Obj) = + doAssert false, "no Obj is constructed in this sample" + +proc `=destroy`(o: var ObjFinal) = + doAssert false, "no ObjFinal is constructed in this sample" + +var dDestroyed: int +proc `=destroy`(d: var D) = + dDestroyed.inc + +proc `=destroy`(d: var DFinal) = + dDestroyed.inc + +func newD(): DRef = + DRef ObjRef() + +func newDFinal(): DFinalRef = + DFinalRef ObjFinalRef() + +proc testRefs() = + discard newD() + discard newDFinal() + +testRefs() + +doAssert(dDestroyed == 2) |