Oh, seems the **\--newruntime** compiler flag is needed for destructors to work.
> I am on Windows 10, Nim Compiler Version 0.18.0 [Windows: i386], MinGW GCC.
I don't know if that is just for windows 10, I am on ubuntu with 0.18.0 and I
am getting the same thing though my code is a little different
{.experimental.}
type thing = object
x:int
p:poi
Hi,
Is there a regression in the compiler, because the above example doesn't
execute the destructor:
{.experimental.}
type
MyObj = object
a: int
proc `=destroy`(m: MyObj) =
echo "Destruct"
proc works() =
let x = MyObj(a: 5)
@sendell Not necessarily. Global scope can be unique in some ways, although I
agree it could be quite confusing in Nim specifically. That's the way things
are in some languages, for example:
* in C, global variables can't be initialized in a function call (they can in
C++)
* in Fortran, glo
Global scope should work as any scope, and call destructors when ending.
> adianv said: why should it be called ? x is global and gets never out of
> scope.
The whole point on RAII is to be abble to bind the lifetime of a resource to
the lifetime of an object, to make sure the resource is relea
Oh yeah, good to know this doesn't work.
adrianv, that makes better sense now. Udiknedormin, I agree here. I think that
a block should lead to deconstruction.
Well, it is not an issue but I don't get why it doesn't work for a block:
{.experimental.}
type MyObj = object
a: int
proc `=destroy`(m: MyObj) =
echo "Destruct"
block:
let x = MyObj(a: 5)
I find it misleading as a block should creat
why should it be called ? x is global and gets never out of scope.
Hello, I have a question about destructors. I am not sure if I am
misunderstanding something, or if this is a bug. When I declare a constructor
for a type, it is not called if an instance of the object is created free in
the main module (as opposed to within a proc).
For example, the destructor
10 matches
Mail list logo