www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 15310] New: [dmd-internal] TemplateDeclaration should be

https://issues.dlang.org/show_bug.cgi?id=15310

          Issue ID: 15310
           Summary: [dmd-internal] TemplateDeclaration should be converted
                    to TemplateExp always
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: k.hara.pg gmail.com

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.

--
Nov 09 2015