Thread overview
[Issue 17298] Wrong deprecation warnings about derived class accessing private method
[Issue 17298] Templates cause wrong deprecation warnings about derived class accessing private method
Apr 05, 2017
ag0aep6g@gmail.com
Apr 05, 2017
Maksim Zholudev
Dec 17, 2022
Iain Buclaw
May 18, 2023
RazvanN
April 05, 2017
https://issues.dlang.org/show_bug.cgi?id=17298

ag0aep6g@gmail.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |ag0aep6g@gmail.com

--- Comment #1 from ag0aep6g@gmail.com ---
The test case doesn't need templates.

a.d:
----
import b: Derived;

class Base
{
    private void func() {}
}

void foo() { new Derived().func(); }
----

b.d:
----
import a: Base;
class Derived : Base {}
----

`dmd -c a b`:
----
a.d(8): Deprecation: a.Base.func is not visible from class Derived
----

--
April 05, 2017
https://issues.dlang.org/show_bug.cgi?id=17298

Maksim Zholudev <maximzms@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|Templates cause wrong       |Wrong deprecation warnings
                   |deprecation warnings about  |about derived class
                   |derived class accessing     |accessing private method
                   |private method              |

--
December 17, 2022
https://issues.dlang.org/show_bug.cgi?id=17298

Iain Buclaw <ibuclaw@gdcproject.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Priority|P1                          |P3

--
May 18, 2023
https://issues.dlang.org/show_bug.cgi?id=17298

RazvanN <razvan.nitu1305@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |razvan.nitu1305@gmail.com
         Resolution|---                         |INVALID

--- Comment #2 from RazvanN <razvan.nitu1305@gmail.com> ---
This bug report is not valid. In D, the encapsulation unit is the module. Therefore, since Derived is defined in a different module than Base, the private method cannot be accessed through it. If you want derived to have access to `func` just define it in the same module as `Base`.

Otherwise, you can just access `func` through Base: `new T().Base.func()`.

--