www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Private static inheritance

reply David Ferenczi <raggae ferenczi.net> writes:
I've come accross with the following:

test.d
-------------8<------------------

module test;

static private import testAA: AA;
static private import std.cstream: dout;

int main(char[][] args)
{
    dout.writeLine(AA.text);
    return 0;
}

-------------8<------------------



testA.d
-------------8<------------------

module testA;

class A
{
private:
    static const char[] text = "text";
}

-------------8<------------------



testAA.d
-------------8<------------------

module testAA;

static private import testA: A;

class AA : A
{
}

-------------8<------------------


Running the program the output is: "text"


I don't know what would be the correct behaviour, but I presume that a 
private member (even if it's static) can't be accessed either from outside,
neither from a subclass. Am I wrong?

Regards,
David
Sep 23 2007
next sibling parent reply Matti Niemenmaa <see_signature for.real.address> writes:
David Ferenczi wrote:
 I've come accross with the following:
 
 test.d
 -------------8<------------------
 
 module test;
 
 static private import testAA: AA;
 static private import std.cstream: dout;
 
 int main(char[][] args)
 {
     dout.writeLine(AA.text);
     return 0;
 }
 
 -------------8<------------------
 
 
 
 testA.d
 -------------8<------------------
 
 module testA;
 
 class A
 {
 private:
     static const char[] text = "text";
 }
 
 -------------8<------------------
 
 
 
 testAA.d
 -------------8<------------------
 
 module testAA;
 
 static private import testA: A;
 
 class AA : A
 {
 }
 
 -------------8<------------------
 
 
 Running the program the output is: "text"
 
 
 I don't know what would be the correct behaviour, but I presume that a 
 private member (even if it's static) can't be accessed either from outside,
 neither from a subclass. Am I wrong?
Looks like good old bug 314 to me: http://d.puremagic.com/issues/show_bug.cgi?id=314 -- E-mail address: matti.niemenmaa+news, domain is iki (DOT) fi
Sep 23 2007
parent David Ferenczi <raggae ferenczi.net> writes:
Matti Niemenmaa wrote:
 Looks like good old bug 314 to me:
 http://d.puremagic.com/issues/show_bug.cgi?id=314
 
This is funny. I tried it out with pure imports wihtout any qualifiers. I got the same result. So summerising the problem: if a private member qualified as static or const (or both), it won't remain private after import. And as far as I can judge the import qualifier doesn't matter. So the problem is surely related to 314, but it may introduce some new aspects.
Sep 23 2007
prev sibling parent reply Kirk McDonald <kirklin.mcdonald gmail.com> writes:
David Ferenczi wrote:
[snip]
 static private import testAA: AA;
 static private import std.cstream: dout;
[snip] Though this has nothing to do with your question, this is not valid code. A selective import cannot also be a static import. When you say: import std.stdio : writefln; Then the only symbol which is inserted into the module's namespace is 'writefln' (and not 'std'). Putting 'static' in front of this import causes the compiler to give this error: test.d(1): static import std cannot have an import bind list -- Kirk McDonald http://kirkmcdonald.blogspot.com Pyd: Connecting D and Python http://pyd.dsource.org
Sep 23 2007
parent David Ferenczi <raggae ferenczi.net> writes:
Kirk McDonald wrote:

 David Ferenczi wrote:
 [snip]
 static private import testAA: AA;
 static private import std.cstream: dout;
[snip] Though this has nothing to do with your question, this is not valid code. A selective import cannot also be a static import. When you say: import std.stdio : writefln; Then the only symbol which is inserted into the module's namespace is 'writefln' (and not 'std'). Putting 'static' in front of this import causes the compiler to give this error: test.d(1): static import std cannot have an import bind list
Hi Kirk, tnank you for pointing this out. I will correct it. Nevertheless the code compiles with dmd-1.20 under linux. Regards, David
Sep 23 2007