[Issue 2789] New: Compiler allows for method with the same signature

d-bugmail at puremagic.com d-bugmail at puremagic.com
Fri Apr 3 06:35:41 PDT 2009


http://d.puremagic.com/issues/show_bug.cgi?id=2789

           Summary: Compiler allows for method with the same signature
           Product: D
           Version: 2.025
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Severity: major
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla at digitalmars.com
        ReportedBy: baryluk at smp.if.uj.edu.pl


cclass A {
        int m() {
                return 1;
        }

        float m() {
                return 2.0;
        }
}

class B {
        int m() {
                return 1;
        }

        int m() {
                return 2;
        }
}

void main() {
        auto a = new A();
        assert(a.m() == 1);
        auto b = new B();
        assert(b.m() == 1);
}

/+
 dmd -c bugcopy.d
bugcopy.d(23): function bugcopy.A.m called with argument types:
        ()
matches both:
        bugcopy.A.m()
and:
        bugcopy.A.m()
bugcopy.d(25): function bugcopy.B.m called with argument types:
        ()
matches both:
        bugcopy.B.m()
and:
        bugcopy.B.m()
Exit 1

+/


Without main this program compiles without any warning or error. This connected
with for example overloding over aliases/or const can lead to problems.

class B {
        int m(S[] c) {
                return 1;
        }

        int m(invariant(S)[] c) {
                return 2;
        }
}

If S is already invariant, then this code is erratic, but compiler will not
report it to user.


-- 



More information about the Digitalmars-d-bugs mailing list