[Issue 3258] New: Calling private or package override methods calls the base implementation

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Aug 18 23:31:26 PDT 2009


           Summary: Calling private or package override methods calls the
                    base implementation
           Product: D
           Version: 1.045
          Platform: x86
        OS/Version: Linux
            Status: NEW
          Keywords: accepts-invalid, wrong-code
          Severity: major
          Priority: P2
         Component: DMD
        AssignedTo: nobody at puremagic.com
        ReportedBy: diggory.hardy at gmail.com

(Same as: http://www.dsource.org/projects/ldc/ticket/355
Exactly the same problem with dmd 1.045, dmd 2.031, ldc 0.9.1.)

Probably related to #354, when overriding methods with an implementation in a
base class, from a reference of type base class, the wrong implementations get

OK, so overriding private functions is illegal according to the spec, but since
the compiler doesn't complain, I included those to show the similarity between
package and private functions (same error with both).

// Declare and define some methods...
class A {
    private void iPriv ()    { assert(false, "iPriv"); }
    protected void iProt ()    { assert(false, "iProt"); }
    package void iPack ()    { assert(false, "iPack"); }
    public void iPub ()        { assert(false, "iPub"); }

// ... but override them all here:
class B : A {
    private override void iPriv() {}    // (lesser issue: shouldn't the
compiler complain here?)
    protected override void iProt() {}
    package override void iPack() {}
    public override void iPub() {}

void main() {
    // None of these assert of course (overriden functions are called):
    B b = new B;

    // But when we call from a base class with an implementation:
    A a = b;
    a.iPriv;    // This calls A.iPriv and asserts
    a.iPack;    // This calls A.iPack and asserts
Unless the {{{a.iPriv;}}} and {{{a.iPack;}}} calls are removed, the program
asserts when run.

 1. With private functions this is nearly OK, but the compiler should complain
about trying to override them instead of silently calling the base
 2. With package protection, the wrong implementation of iPack() is called.

Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------

More information about the Digitalmars-d-bugs mailing list