Open
Description
=destroy
is not called in VM=destroy
is not called at runtime depending on compile time code that should've run the destructor
Example
when true:
type Foo = object
proc `=destroy`*(x: var Foo) = echo "destroy Foo"
proc fun() =
echo "create Foo"
var a: Foo
static: fun()
fun()
Current Output
# compile time:
create Foo
# run time:
create Foo
Expected Output
# compile time:
create Foo
destroy Foo
# run time:
create Foo
destroy Foo
Additional Information
-
Your Nim version (output of
nim -v
).
fails in 0.20 and nim devel d72edfb -
Was it working in the previous Nim releases?
works in 0.19.6 -
if you comment out
static: fun()
, the run time works, producing:
create Foo
destroy Foo
note
Using when nimvm
as follows also fails:
when true:
type Foo = object
proc `=destroy`*(x: var Foo) = echo "destroy Foo"
proc fun() =
proc funAux() =
echo "create Foo"
var a: Foo
when nimvm:
echo "in nimvm"
else:
echo "in rt"
funAux()
static: fun()
fun()
# compile time
in nimvm
# run time
in rt
create Foo
=> destroy Foo
is missing at runtime here as well
This latter point seems to be a consequence of #9696 (Destructors are injected for variables that never come into scope), whereby a
would never become in scope at CT (guarded by when nimvm
) yet would still affect the runtime version