I'm dealing with a type definition and some code in Nim, and everything was 
working smoothly before the transition to Nim 2.0. Here's the setup:
    
    
    type
      MenuItem = ref object
        text: string
      
      Menu = ref object
        items: seq[MenuItem]
    
    proc `=destroy`(self: var type(MenuItem()[])) =
      echo "=destroy MenuItem"
    
    proc `=destroy`(self: var type(Menu()[])) =
      echo "=destroy Menu"
      self.items.setLen(0)
    
    when isMainModule:
      var menu = Menu()
      menu.items.add MenuItem(text: "item")
    
    
    Run

In Nim 2.0, I had to make changes to the destructors:
    
    
    proc `=destroy`(self: type(MenuItem()[])) =
      echo "=destroy MenuItem"
    
    proc `=destroy`(self: type(Menu()[])) =
      echo "=destroy Menu"
      # self.items.setLen(0) <- error: type mismatch (not a var)
    
    
    Run

However, I noticed that the destructor for MenuItem is not being called. I 
found a somewhat hacky solution in `(self.addr)[].items.setLen(0)`, but I'm 
wondering if there's a more elegant way to handle this situation without 
resorting to a workaround. Any suggestions would be greatly appreciated!

Reply via email to