www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Private alias escaping -- is this a bug?

reply "rcorre" <ryan rcorre.net> writes:
I ran into this infuriatingly confusing situation just now:

static assert(is(typeof(Parent.init.new Child) == Parent.Child)); 
// fine

alias P = Parent;
alias T = Parent.Child;

static assert(is(typeof(P.init.new T) == T)); // nope!

Wat???

After much confusion, I finally discovered this in my class:

class Parent {
     class Child { }
     mixin MyMixin;
}

mixin Template MyMixin() {
     private alias T = ...; // the culprit!
}

Should the private alias be able to escape? Is this a bug or 
expected behavior?

Also, is there a nice way to create template-level aliases in 
mixin templates that don't leak into the class? MyMixin generates 
multiple functions that all use T.
Apr 25 2015
parent "Vlad Levenfeld" <vlevenfeld gmail.com> writes:
On Saturday, 25 April 2015 at 23:51:05 UTC, rcorre wrote:
 I ran into this infuriatingly confusing situation just now:

 static assert(is(typeof(Parent.init.new Child) == 
 Parent.Child)); // fine

 alias P = Parent;
 alias T = Parent.Child;

 static assert(is(typeof(P.init.new T) == T)); // nope!

 Wat???

 After much confusion, I finally discovered this in my class:

 class Parent {
     class Child { }
     mixin MyMixin;
 }

 mixin Template MyMixin() {
     private alias T = ...; // the culprit!
 }

 Should the private alias be able to escape? Is this a bug or 
 expected behavior?

 Also, is there a nice way to create template-level aliases in 
 mixin templates that don't leak into the class? MyMixin 
 generates multiple functions that all use T.
You could namespace them in a sense by defining a nested struct that contains the aliases.
Apr 25 2015