DMD tries to evaluate alias this'ed symbols. It causes a compile error on instantiating templates with alias this'ed symbols.
-------------------- test1.d
alias Test!(S.square) test;
struct S
{
struct F
{
int square(int n) { return n*n; }
real square(real n) { return n*n; }
}
F forward;
alias forward this;
}
template Test(alias k) {}
--------------------
% dmd -o- -c test1.d
test1.d(1): Error: function test1.S.F.square (int n) is not callable using argument types ()
test1.d(1): Error: expected 1 function arguments, not 0
% _
--------------------
TemplateInstance::semanticTiargs() (or TypeQualified::resolveHelper()) resolves forwarded symbols as dotvar expressions and tries to evaluate them at compile time. Apparently, it causes the problem.
The error does not occur if the symbol is forwarded directly:
-------------------- test2.d
alias Test!(S.square) test;
struct S
{
struct F
{
int square(int n) { return n*n; }
real square(real n) { return n*n; }
}
F forward;
alias forward.square square; // okay
}
template Test(alias k) {}
--------------------
% dmd -o- -c test2.d
% _
--------------------
Comment #1 by rsinfu — 2010-08-10T22:39:48Z
The bug also causes a false negative of __traits(isSame), becuase isSame reuses the same algorithm as template instantiation:
-------------------- test3.d
static assert( __traits(isSame, S.square, S.forward.square) );
struct S
{
struct F
{
int square(int n) { return n*n; }
real square(real n) { return n*n; }
}
F forward;
alias forward this;
}
--------------------
% dmd -o- -c test3.d
test3.d(1): Error: static assert (__traits(isSame,forward.square,square)) is false
--------------------