www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Shouldn't duplicate functions be caught by DMD?

reply Andrej Mitrovic <none none.none> writes:
I'm not talking about function overloading, but functions with the same
parameters inside the same class definition:

class Foo
{
    int foo(int i)
    {
        return 1;
    }
    
    int foo(int i)
    {
        return 1;
    }    
    
    void bar()
    {
        foo(1);
    }
}

void main()
{
    auto foo = new Foo();
}

Errors:
test.d(19): Error: function test.Foo.foo called with argument types:
        ((int))
matches both:
        test.Foo.foo(int i)
and:
        test.Foo.foo(int i)

If you comment out the call to foo(), and compile via -c -w -wi, no errors will
be emitted. Only later when you try to use the object file you'll get a linker
error:

fset 003C4H Record Type 00C3
 Error 1: Previous Definition Different : _D4test3Foo3fooMFiZi
--- errorlevel 1

I think the compiler should check catch these mistakes at compile-time.
May 07 2011
parent reply bearophile <bearophileHUGS lycos.com> writes:
Andrej Mitrovic:

 I think the compiler should check catch these mistakes at compile-time.
I suggest to add an enhancement request in Bugzilla. Bugzilla entries are a form of "voting" by themselves too. Bye, bearophile
May 08 2011
parent Stewart Gordon <smjg_1998 yahoo.com> writes:
On 08/05/2011 09:41, bearophile wrote:
 Andrej Mitrovic:

 I think the compiler should check catch these mistakes at compile-time.
I suggest to add an enhancement request in Bugzilla. Bugzilla entries are a form of "voting" by themselves too.
<snip> One should not file stuff in Bugzilla without first looking to see whether it's already there. And this one is: http://d.puremagic.com/issues/show_bug.cgi?id=1003 Stewart.
May 08 2011