In DsymbolExp.resolve, a TemplateDeclaration is converted to TemplateExp.
extern (C++) final class DsymbolExp : Expression
{
...
static Expression resolve(Loc loc, Scope *sc, Dsymbol s, bool hasOverloads)
{
...
if (TemplateDeclaration td = s.isTemplateDeclaration())
{
auto p = td.toParent2();
auto fdthis = hasThis(sc);
auto ad = p ? p.isAggregateDeclaration() : null;
if (...)
{
...
}
else
e = new TemplateExp(loc, td); // here
e = e.semantic(sc);
return e;
}
However in DotIdExp.semanticY, the found TemplateDeclaration is converted to ScopeExp.
extern (C++) final class DotIdExp : UnaExp
{
...
Expression semanticY(Scope* sc, int flag)
{
...
if (eright.op == TOKimport)
{
Dsymbol s = ie.sds.search(loc, ident, ...);
if (s)
{
...
ScopeDsymbol sds = s.isScopeDsymbol();
if (sds)
{
// here, because TemplateDeclaration is derived from ScopeDsymbol
//printf("it's a ScopeDsymbol %s\n", ident->toChars());
e = new ScopeExp(loc, sds);
e = e.semantic(sc);
if (eleft)
e = new DotExp(loc, eleft, e);
return e;
}
By this, a TemplateDeclaration handling code should consider both TOKtemplate (TemplateExp) and TOKimport (ScopeExp) in everywhere. It's problematic and bug-prone.
Comment #1 by k.hara.pg — 2015-11-10T02:50:09Z
Today, TOKimport is not properly handled for TemplateDeclaration in some places.
Issue 14603 and issue 14604 have been casued by this dmd-internal issue.