You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I expect destructors to be called in reverse creation order, inherited first then base - this is important for lots of reasons, ie all the way from multiple locks being released in the correct order to prevent deadlocks to pointers to the base class being valid during deconstruction etc.
This order of destruction is already imposed for local variables, ie reverse declaration order - there's no reason objects shouldn't work the same...
typeAaaa {.inheritable.} =object
vvvv: intBbbb=objectofAaaa
c: Cccc
d: DdddCccc=objectDddd=objectHolder=object
member: refAaaaproc`=destroy`(v: Cccc) =echo"destroying c"proc`=destroy`(v: Dddd) =echo"destroying d"proc`=destroy`(v: Aaaa) =echo"destroying a ", v.vvvv
funcmakeHolder(vvvv: int): refHolder=
(refHolder)(member: (refBbbb)(vvvv: vvvv))
block:
var v =makeHolder(1)
var v2 =makeHolder(2)
Nim Version
2.2
Current Output
destroying a 2
destroying c
destroying d
destroying a 1
destroying c
destroying d
Expected Output
destroying d
destroying c
destroying a 2
destroying d
destroying c
destroying a 1
Known Workarounds
No response
Additional Information
No response
The text was updated successfully, but these errors were encountered:
While the effect of a well-defined destruction order indeed can be achieved manually, this issue is about bringing the feature in line with other "evaluation order" features in the language so as to reduce surprises and contextual complexity.
While the effect of a well-defined destruction order indeed can be achieved manually, this issue is about bringing the feature in line with other "evaluation order" features in the language so as to reduce surprises and contextual complexity.
I second this. If it's not well defined and changes between Nim versions it'd cause a lot of painful headaches.
Description
I expect destructors to be called in reverse creation order, inherited first then base - this is important for lots of reasons, ie all the way from multiple locks being released in the correct order to prevent deadlocks to pointers to the base class being valid during deconstruction etc.
This order of destruction is already imposed for local variables, ie reverse declaration order - there's no reason objects shouldn't work the same...
Nim Version
2.2
Current Output
Expected Output
Known Workarounds
No response
Additional Information
No response
The text was updated successfully, but these errors were encountered: