[Issue 3379] [tdpl] Parameter names not visible in the if clause of a template

d-bugmail at puremagic.com d-bugmail at puremagic.com
Fri Oct 16 00:33:38 PDT 2009


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


Don <clugdbug at yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |clugdbug at yahoo.com.au
           Platform|Other                       |All
            Version|unspecified                 |2.032
         OS/Version|Linux                       |All
           Severity|normal                      |enhancement


--- Comment #1 from Don <clugdbug at yahoo.com.au> 2009-10-16 00:33:37 PDT ---
I've convinced myself that this isn't too difficult, but it contains a lot of
subtlties. I don't have a complete patch, but I've got basic cases working.
Basically in deduceFunctionTemplateMatch() you need to create variables for
each of the parameters (by analogy to func.c line 904).

    for (i = 0; i < nfparams; i++)
    {
    Argument *fparam = Argument::getNth(fparameters, i);
    if (!fparam->ident) continue; // don't add it, if it has no name
    Type *vtype = // get the type, not sure how to do this properly
    ... deal with pure, etc.
    VarDeclaration *v = new VarDeclaration(loc, vtype, fparam->ident, NULL);

... set the storage class

    v->semantic(paramscope);
    if (!paramscope->insert(v)) error("parameter %s.%s is already defined",
toChars(), v->toChars());
}

Not sure how to deal with deal with the different flavours of variadics,
though.
I originally thought that in TemplateDeclaration::matchWithInstance() you'd be
able avoid checking the constraint again if it's a function template, but you
can't because of cases like:

T1[] find(T1, T2)(T1[] longer, T2[] shorter) if (false) 
{
   assert(0);
   return longer;
}

void main() {
   double[] d1 = [ 6.0, 1.5, 2.4, 3 ];
   double[] d2 = [ 1.5, 2.4 ];
   assert(find!(double, double)(d1, d2) == d1[1 .. $]); // THIS MUST NOT
COMPILE.
}

So it needs to have the same thing, wrapped in a 
     FuncDeclaration *fd = onemember->toAlias()->isFuncDeclaration();
     if (fd) {
   ...
}

-- 
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