I was just working a bit on gintro for latest GTK4 and got a really confusing 
error message.

Luckely I was just able to generate a minimal example, but I have still no real 
idea what the problem may be. I guess there must be something special in this 
code, because I have used similar constructs before and it was working fine...
    
    
    type
      Event* = ref object of RootRef
        impl*: pointer
        ignoreFinalizer*: bool
    
    template fnew*(a: untyped; finalizer: untyped) =
      when defined(gcDestructors):
        new(a)
      else:
        new(a, finalizer)
    
    proc `ref`*(self: Event): Event =
      fnew(result, generic_gdk_event_unref)
      echo "result.impl = gdk_event_ref(cast[ptr Event00](self.impl))"
    
    proc generic_gdk_event_unref*[T](self: ref T) =
      if not self.ignoreFinalizer:
        echo "gdk_event_unref(self.impl)"
    
    when defined(gcDestructors):
      proc `=destroy`*(self: var typeof(Event()[])) =
        if not self.ignoreFinalizer and self.impl != nil:
          echo "gdk_event_unref(self.impl)"
          self.impl = nil
    
    proc main =
      var x: Event
      fnew(x, generic_gdk_event_unref)
    
    main()
    
    
    Run
    
    
    $ nim c --gc:arc t2.nim
    
    /tmp/hhh/t2.nim(21, 3) Error: cannot bind another '=destroy' to: 
Event:ObjectType; previous declaration was constructed here implicitly: 
/tmp/hhh/t2.nim(13, 3)
    
    
    
    Run
    
    
    $ nim -v
    Nim Compiler Version 1.3.3 [Linux: amd64]
    Compiled at 2020-05-11
    Copyright (c) 2006-2020 by Andreas Rumpf
    
    git hash: 7c24250a575b4d441ba6d7301714cbb246425fb6
    active boot switches: -d:release
    
    
    Run

Reply via email to