public aliases to private/package symbols

Peter Alexander peter.alexander.au at gmail.com
Tue Jan 24 16:59:57 PST 2012


On Wednesday, 25 January 2012 at 00:08:25 UTC, Timon Gehr wrote:
> Accessibility-raising aliases are trivially safe, because the 
> alias declaration must have access to the aliased symbol.

You are probably right about not introducing holes, but I can 
imagine this getting tricky, and perhaps confusing in some cases. 
Here are some off the top of my head.

module A;
private class Foo {}
public alias Foo Bar;

In other modules that import A:

Bar b = new typeof(b)(); // typeof(b) is Foo. Is this allowed?

T foo(T)(T x) { return new T(); }
Bar b;
b = foo(b); // T is deduced to Foo, should this work?

Bar b = new Bar();
mixin("b = new " ~ typeof(b).stringof ~ "();"); // This fails, 
the string is "Foo"


Just thinking about this has made me change my position. 
Accessibility raising aliases should not be allowed. It's a 
minefield.


More information about the Digitalmars-d mailing list