Strange template alias behaviour

Jack Applegame japplegame at gmail.com
Sun Nov 18 00:58:29 PST 2012


I wrote about strange thing here 
http://forum.dlang.org/thread/xftbyifuuubxhhsolgpv@forum.dlang.org
And now another very strange thing appears when we pass mixin 
identifier as template alias parameter.
Look at this code:

import std.stdio;

mixin template Foo() {
   char[] data = "default".dup;
}

class Bar {
   char[] data;
   mixin Foo F1;
   mixin Foo F2;
}

void check_data(alias M, T)(T obj) {
   assert(obj.data == "Bar");
   assert(obj.F1.data == "F1");
   assert(obj.F2.data == "F2");
}

void main() {
   Bar bar = new Bar;

   bar.data = "Bar".dup;
   bar.F1.data = "F1".dup;
   bar.F2.data = "F2".dup;

   assert(bar.data == "Bar");
   assert(bar.F1.data == "F1");
   assert(bar.F2.data == "F2");

   check_data!(bar)(bar);
}

Everything works ok, no assertions.
But after changing "check_data!(bar)(bar)" to 
"check_data!(Bar.F1)(bar)" or "check_data!(Bar.F2)(bar)", you 
will get assertions.
Seems like bug.


More information about the Digitalmars-d-learn mailing list