www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 14187] New: Wrong overload resolution when one of the


          Issue ID: 14187
           Summary: Wrong overload resolution when one of the parameters
                    to a function is an interface
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P1
         Component: DMD
          Assignee: nobody puremagic.com
          Reporter: monkeyworks12 hotmail.com

This problem appears only if one of the parameters is an 
interface. Without it or using any other type as a second 
parameter instead of the interface, it compiles. Also it compiles 
if the passed interface is null. The example below uses 
short/ushort, but there is the same behaviour for any combination 
of integral types of the same bitsize (byte/ubyte/char, 
ushort/short/wchar, int/uint/dchar, long/ulong)

D 2.066.1

interface I {}
class C: I {}

void func(ushort s, I i)
    writeln("ushort overload");

void func(short s, I i)
    writeln("short overload");

void call(short s)
    C c = new C();
    I d = new C();
    func(s, c); // ---- ERROR ---- see below

    //but these are ok

    func(s, cast(I)c) //ok
    func(s, d) //ok
    func(s, null) //ok


main.func called with argument types (short, C) matches both:    
main.func(short s, I i)    
main.func(ushort s, I i)

Feb 16 2015