www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - visibility of private Class C in module named "C"; private variables

reply kdevel <kdevel vogtner.de> writes:
~~~Private.d
module Private;

class A {}
private class B {}
package class Private {
    void foo () { __PRETTY_FUNCTION__.writeln; }
}
~~~

~~~main.d
void main ()
{
    import Private: A; // okay
//   import Private: B; // main.d(4): Error: module Private 
member B
                         // is not visible from module main
                         // okay

//   import Private: Private; // main.d(8): Error: module Private 
member
                             // Private is not visible from module 
main
                             // oh-kay, but

    import Private;
    auto p = new Private; // works, but Private.Private is private 
?!?
    p.foo;
}
~~~

I don't get it. Furthermore according to

    https://wiki.dlang.org/Access_specifiers_and_visibility#private

there is always external linkage on private variables and 
functions.
Does D not provide a means to stop symbols from going into the 
object file?
Dec 26 2020
parent reply Mike Parker <aldacron gmail.com> writes:
On Saturday, 26 December 2020 at 15:58:30 UTC, kdevel wrote:

 package class Private {
    void foo () { __PRETTY_FUNCTION__.writeln; }
 }
    import Private;
    auto p = new Private; // works, but Private.Private is 
 private ?!?
You've declared `Private` as `package`.
Dec 26 2020
parent reply kdevel <kdevel vogtner.de> writes:
On Saturday, 26 December 2020 at 17:48:17 UTC, Mike Parker wrote:
 On Saturday, 26 December 2020 at 15:58:30 UTC, kdevel wrote:

 package class Private {
    void foo () { __PRETTY_FUNCTION__.writeln; }
 }
    import Private;
    auto p = new Private; // works, but Private.Private is 
 private ?!?
You've declared `Private` as `package`.
Hit but not sunk. It makes no difference: ~~~Private.d module Private; import std.stdio: writeln; class A {} private class B {} private class Private { void foo () { __PRETTY_FUNCTION__.writeln; } } ~~~ $ dmd main.d $ ./main void Private.Private.foo()
Dec 26 2020
parent reply kdevel <kdevel vogtner.de> writes:
On Saturday, 26 December 2020 at 18:43:19 UTC, kdevel wrote:
 $ dmd main.d
$ dmd -i main
Dec 26 2020
parent kdevel <kdevel vogtner.de> writes:
bugreport filed https://issues.dlang.org/show_bug.cgi?id=21508
Dec 27 2020