* fix #16722

* fix spacing

* spacing
This commit is contained in:
cooldome 2021-01-15 18:16:24 +00:00 • committed by GitHub
commit fc9cf2088d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 49 additions and 4 deletions

View file

@ -125,4 +125,46 @@ proc main =
let rankdef = avals
echo avals.len, " ", rankdef.len
main()
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)