[Issue 20002] New: Cannot access derived protected method in another module

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Jun 25 06:44:16 UTC 2019


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

          Issue ID: 20002
           Summary: Cannot access derived protected method in another
                    module
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: andrej.mitrovich at gmail.com

This is similar to https://issues.dlang.org/show_bug.cgi?id=2417.

Test-case:

base.d:
```
import derived;

class Base
{
    protected void func() { }
}

void main()
{
    auto derived = new Derived;
    derived.func();
}
```

derived.d:
```
import base;

class Derived : Base
{
    protected override void func() { }
}
```

~/dev/d master * $ dmd -run base.d
base.d(11): Deprecation: derived.Derived.func is not visible from module base
base.d(11): Error: class `derived.Derived` member func is not accessible


The fix is to change:
auto derived = new Derived;

to:
Base derived = new Derived;

But I don't see why the compiler can't access it in the first case, it's still
a virtual call after all..

--


More information about the Digitalmars-d-bugs mailing list