[Issue 15011] New: can override public method with protected method

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Fri Sep 4 01:26:13 PDT 2015


https://issues.dlang.org/show_bug.cgi?id=15011

          Issue ID: 15011
           Summary: can override public method with protected method
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Windows
            Status: NEW
          Severity: minor
          Priority: P1
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: yosikawa at altalk.com

following code prints 'Foo2'
expected result is compile error.
DMD32 D Compiler v2.068.0

file main.d:
import foo;
void main() {
    Foo1 foo = new Foo2();
    foo.bar();
}

file foo.d:
import std.stdio;
class Foo1 {
    void bar() {
        writeln("Foo1");
    }
};
class Foo2 : Foo1 {
    protected override void bar() {
        writeln("Foo2");
    }
};

--


More information about the Digitalmars-d-bugs mailing list