www.digitalmars.com         C & C++   DMDScript  

D - A bug that I like

reply Matthias Becker <Matthias_member pathlink.com> writes:
The specification says: 
"In D, function overloading is simple. It matches exactly, it matches with
implicit conversions, or it does not match. If there is more than one match, it
is an error."

But this isn't true. There are "better matches" (to speak in terms of C++):

class Foo {}
class Bar : Foo {}
class Baz : Bar {}

void func (Foo foo) 
printf ("Foo");
void func (Bar bar) 
printf ("Bar");

int main ()
Baz baz = new Baz();
func (baz);
return 0;

This calles 'void func(Bar)'. So 'void func(Bar)' is a Better match than 'void
func(Foo)' as both don't match exactly.

So I'd like you to change the specification rather than fixing the "bug".
Feb 16 2004
parent "Walter" <walter digitalmars.com> writes:
When I compile the example, I get the expected:

test.d(18): function func overloads void(Foo foo) and void(Bar bar) both
match a
rgument list for func

I'm going to leave it as is, due to the quagmire of going down the path of
deciding what constitutes a better match <g>.
Feb 22 2004