Can you publicly alias a private type?

Nick Sabalausky a at a.a
Tue Jun 21 11:59:28 PDT 2011


"Peter Alexander" <peter.alexander.au at gmail.com> wrote in message 
news:itq945$2ag0$1 at digitalmars.com...
> Is the following legal D?
>
> // module A
> private class Foo;
> public alias Foo Bar;
>
> // module B
> import A;
> Bar b; // I can't use Foo, but can I use Bar?
>
>
> I'm adding module level protection for types into DMD and wondering if 
> this should be legal.
>

I'm no authority on this, but I'm pretty sure that's supposed to be legal. 
Access modifiers work non-transitively on just the given symbol. And it's a 
useful idiom in cases that are more complex than that (ex: Using a templated 
alias to provide a cleaner public interface to a private implementation that 
has a more complex interface).

Your code above is analogous to this, which *definitely* is supposed to be 
legal:

// module A
private foo() {}
public bar()
{
    foo();
}

// module B
import A;
bar(); // I can't use foo(), but can I use bar(). Nothin' wrong with that.





More information about the Digitalmars-d mailing list