April 25, 2015 Private alias escaping -- is this a bug? | ||||
---|---|---|---|---|
| ||||
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. |
April 25, 2015 Re: Private alias escaping -- is this a bug? | ||||
---|---|---|---|---|
| ||||
Posted in reply to rcorre | 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.
|
Copyright © 1999-2021 by the D Language Foundation