Wrong overload resolution
Meta via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Mon Feb 16 01:00:08 PST 2015
On Sunday, 15 February 2015 at 23:48:50 UTC, rumbu wrote:
>
> 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 I found 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)
I have submitted a bug report here:
https://issues.dlang.org/show_bug.cgi?id=14187
More information about the Digitalmars-d-learn
mailing list