Skip to content

Destructor not consistently called for different init forms #21244

@arnetheduck

Description

@arnetheduck

Description

type X = object
  v: int

type Y = object
  x: X
  y: X

proc `=destroy`(x: var X) =
  echo "Destroying X"
  
  
proc f() =
  var y: Y = Y()
  echo y
  

proc g() =
  var y: Y
  echo y
  

echo "calling f"
f()

echo "calling g"
g()
calling f
(x: (v: 0), y: (v: 0))
Destroying X
Destroying X
calling g
(x: (v: 0), y: (v: 0))

In f, we initialize y to its defaults and destructors get called - in g we do the same but implicitly and the destructors are not called - I would expect the behavior to be the same in both cases so as to maintain semantic equivalence for both forms of default-init.

Nim Version

https://play.nim-lang.org/#ix=4kHG - latest on play

Current Output

No response

Expected Output

No response

Possible Solution

No response

Additional Information

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions