[Issue 14187] New: Wrong overload resolution when one of the parameters to a function is an interface

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Mon Feb 16 00:59:52 PST 2015


https://issues.dlang.org/show_bug.cgi?id=14187

          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 at puremagic.com
          Reporter: monkeyworks12 at 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)

--


More information about the Digitalmars-d-bugs mailing list