When casting, a procedure is not properly selected when two procedures with 
different signatures have the same name.

The examples below use types from the __iup__ and __nimpy__ libraries. I 
included all the relevant parts from the libraries and shortened the code a 
bit: 
    
    
    # types imported from the iup library
    type
        Ihandle = object
        PtrIhandle* = ptr Ihandle
        
        Icallback* = proc (arg: PtrIhandle): cint {.cdecl.}
    
    # types imported from the nimpy library
    type
        PPyObject* = distinct pointer
        
        PyObject* = ref object
            rawPyObj: PPyObject
    
    
    
    Run
    
    
    # mymodule.nim
    
    proc turn_on*(bulb: PyObject) =
        discard
    
    
    Run
    
    
    # main.nim
    import mymodule
    
    proc turn_on(button: PtrIhandle): cint =
        discard
    
    def main() =
        #[
            some code
        ]#
        # Setting a callback for a button from the iup library
        btn_on.setCallback("ACTION", cast[Icallback](turn_on)) # Error line
    
    
    Run

The following error is thrown when compiling with nim c main.nim: 
    
    
    main.nim(9, 34) Error: expression cannot be cast to Icallback=proc (arg: 
PtrIhandle): cint{.cdecl.}
    
    
    Run

The compiler selects the mymodule.turn_on proc instead of main.turn_on in the 
line: 
    
    
    btn_on.setCallback("ACTION", cast[Icallback](turn_on))
    
    
    Run

First off, I didn't know that you can reference the module you are inside in. 
Cool. I tried it, and it works: 
    
    
    btn_on.setCallback("ACTION", cast[Icallback](main.turn_on))
    
    
    Run

But my feeling is that the compiler should know which is the correct procedure 
based on the signature or at least say that it doesn't know which one it should 
pick.

Should I report this issue or am I missing something? 

Reply via email to