[Issue 3276] Recursion broken by alias template parameter

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Nov 2 22:11:02 PDT 2010


http://d.puremagic.com/issues/show_bug.cgi?id=3276


Shin Fujishiro <rsinfu at gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |rsinfu at gmail.com


--- Comment #2 from Shin Fujishiro <rsinfu at gmail.com> 2010-11-02 22:09:58 PDT ---
The bug happens if a recursive template is instantiated via an alias:

  alias Bug3276 W;
  alias W!true w;

In template.c, the following if at the line 4304 tries to get the relevant
TemplateDeclaration for doing recursion:

TemplateDeclaration *TemplateInstance::findTemplateDeclaration(Scope *sc)
{
    ...
        TemplateInstance *ti;
        if (s->parent &&
            (ti = s->parent->isTemplateInstance()) != NULL)
        {
            if (
                (ti->name == id ||
                 ti->toAlias()->ident == id)    // <-- the cause
                &&
                ti->tempdecl)
    ...
}

Here 'this' refers to the recursive instantiation "Bug3276!(false)" and
id="Bug3276" is its identifier.  'ti' is the enclosing TemplateInstance (i.e.
"W!(true)").

The test sees if the identifier 'id' used in the instantiation
"Bug3276!(false)" is the same as the one of enclosing 'ti'.  But 'ti' was
instantiated with the aliased identifier (ti->name="W"), so the first condition
isn't met.

Then it tests the next condition: ti->toAlias()->ident.  It dives into the
following code in TemplateInstance::toAlias():

    if (aliasdecl)
    {
        return aliasdecl->toAlias();
    }

Here 'aliasdecl' is the "result" of the eponymous template "Bug3276!(true)",
and it's exactly the "alias Bug3276!(false)" analyzing now. 
AliasDeclaration::toAlias() does the follownig check:

    if (inSemantic)
    {   error("recursive alias declaration");
        aliassym = new TypedefDeclaration(loc, ident, Type::terror, NULL);
    }

Since it's in semantic, the compiler raises the error.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list