www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - Protection modifiers not honored in nested struct/class/union

I know nested classes (and probably structs and unions) will be getting an 
overhaul soon, so this is maybe one of the things that can be worked on:

Protection modifiers (public, private, package) are ignored in nested 
structs, classes, and unions.

Code:

[dtest.d]
----------------------
import mymod;

void main()
{
 A a=new A;

 // this line is illegal
 //a.mX=5;

 // but this line is OK
 a.B.mY=10;
}

[mymod.d]
-----------------------
module mymod;

class A
{
 private int mX;

 private struct B
 {
  private static int mY;
 }
}

Uncommenting the commented code in dtest.d shows that regular members have 
their protection modifiers honored.  However, the private mY in the private 
struct B is as accessible as if it were public.  This happens if B is a 
class or struct as well. 
May 30 2005