Mixin declarations not showing up in ModuleInfo

Daniel Kozak via Digitalmars-d digitalmars-d at puremagic.com
Sun Nov 30 14:27:07 PST 2014


Dne Sun, 30 Nov 2014 19:34:52 +0100 bitwise via Digitalmars-d  
<digitalmars-d at puremagic.com> napsal(a):

> On Sunday, 30 November 2014 at 08:00:20 UTC, Daniel Kozak wrote:
>> On Sunday, 30 November 2014 at 02:10:13 UTC, bitwise wrote:
>>> In the following program, the output does not contain "SomeClass". Is  
>>> this a bug?
>>
>> Maybe yes, as a workaround this works:
>>
>> module main;
>> import std.stdio;
>>
>> template Test()
>> {
>>     enum Test = q{
>>         class SomeClass {
>>             int n = 123;
>>         }
>>     };
>> }
>>
>> mixin(Test!());
>>
>> void main() {
>>
>>     auto sc = new SomeClass;
>>     writeln(sc.n);
>>
>>     foreach(m; ModuleInfo)
>>     {
>>         foreach(c; m.localClasses())
>>         {
>>             writeln(c.name);
>>         }
>>     }
>> }
>>
>> Btw. you can use just template, IIRC there is no difference between  
>> template and mixin template
>
> Hey, thanks for the q{} trick. I knew I had seen it somewhere... but  
> couldn't find it.
>
> That trick only really helps when there is minimal concatenation going  
> on though. When you have to splice a bunch of stuff together, a  
> TokenString doesn't provide much relief.
>
> Docs for template mixins explicitly support the behaviour that I'm  
> after, so I'm gonna file a bug.
>
> " TemplateMixin takes an arbitrary set of declarations from the body of  
> a TemplateDeclaration and inserts them into the current context."
>

Yes, thats true. It is a bug. But I just try to say you can omit mixin  
word in template declaration. Because it doesn't have any effect.


More information about the Digitalmars-d mailing list