www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue XXX] ToBeFiled: 'this' can't be used as an alias parameter

[I'll file this for real once Bugzill is back]

This may not be a bug for some technical reason unbeknownst to me that 
the spec mentions, but I found it unexpected.  You can't use 'this' as 
an alias paramter to a mixin in a class member function.  The workaround 
is pretty easy, you just assign it to a local dummy variable, and use 
that instead.

import std.stdio : writefln;

template printer_mix(alias T)
     void print() {

class Foo
     void dump() {
         // Error: mixin printer_mix!(this) does not match any template 
         mixin printer_mix!(this);

         // this version ok:
         //Foo x = this;
         //mixin printer_mix!(x);

     char[] toString() { return "I'm Batman"; }

void main()
     Foo f = new Foo();
Dec 16 2006