Skip to content

Commit

Permalink
fix Issue 13484 - Template type deduction from delegate parameter fails
Browse files Browse the repository at this point in the history
The implicit conversion of expressions to delegates was added in 0.165 (a2b1fa4, http://www.digitalmars.com/d/1.0/changelog2.html#new0165), but it was replaced with lazy parameter.
  • Loading branch information
9rnsr committed Sep 17, 2014
1 parent 9bbe770 commit bfa9a00
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 33 deletions.
47 changes: 14 additions & 33 deletions src/template.c
Expand Up @@ -1568,39 +1568,20 @@ MATCH TemplateDeclaration::deduceFunctionTemplateMatch(
if (m == MATCHnomatch && prmtype->deco)
m = farg->implicitConvTo(prmtype);

/* If no match, see if there's a conversion to a delegate
*/
if (m == MATCHnomatch)
{
Type *tbp = prmtype->toBasetype();
Type *tba = farg->type->toBasetype();
if (tbp->ty == Tdelegate)
{
TypeDelegate *td = (TypeDelegate *)prmtype->toBasetype();
TypeFunction *tf = (TypeFunction *)td->next;

if (!tf->varargs && Parameter::dim(tf->parameters) == 0)
{
m = deduceType(farg->type, paramscope, tf->next, parameters, dedtypes);
if (m == MATCHnomatch && tf->next->toBasetype()->ty == Tvoid)
m = MATCHconvert;
}
//printf("\tm2 = %d\n", m);
}
else if (AggregateDeclaration *ad = isAggregate(tba))
AggregateDeclaration *ad = isAggregate(farg->type);
if (ad && ad->aliasthis)
{
if (ad->aliasthis)
/* If a semantic error occurs while doing alias this,
* eg purity(bug 7295), just regard it as not a match.
*/
unsigned olderrors = global.startGagging();
Expression *e = resolveAliasThis(sc, farg);
if (!global.endGagging(olderrors))
{
/* If a semantic error occurs while doing alias this,
* eg purity(bug 7295), just regard it as not a match.
*/
unsigned olderrors = global.startGagging();
Expression *e = resolveAliasThis(sc, farg);
if (!global.endGagging(olderrors))
{
farg = e;
goto Lretry;
}
farg = e;
goto Lretry;
}
}
}
Expand Down Expand Up @@ -1872,10 +1853,10 @@ MATCH TemplateDeclaration::deduceFunctionTemplateMatch(
}

#if 0
for (i = 0; i < dedargs->dim; i++)
for (size_t i = 0; i < dedargs->dim; i++)
{
Type *t = (*dedargs)[i];
printf("\tdedargs[%d] = %d, %s\n", i, t->dyncast(), t->toChars());
RootObject *o = (*dedargs)[i];
printf("\tdedargs[%d] = %d, %s\n", i, o->dyncast(), o->toChars());
}
#endif

Expand Down Expand Up @@ -3513,7 +3494,7 @@ MATCH deduceType(RootObject *o, Scope *sc, Type *tparam, TemplateParameters *par
fparam->type = fparam->type->addStorageClass(fparam->storageClass);
fparam->storageClass &= ~(STC_TYPECTOR | STCin);
}
//printf("\t-> this = %d, ", ty); print();
//printf("\t-> this = %d, ", t->ty); t->print();
//printf("\t-> tparam = %d, ", tparam->ty); tparam->print();

/* See if tuple match
Expand Down
13 changes: 13 additions & 0 deletions test/runnable/template9.d
Expand Up @@ -4216,6 +4216,18 @@ void test13417()
f13417(V13417!(4, float, "ijka")());
}

/******************************************/
// 13484

int foo13484()(void delegate() hi) { return 1; }
int foo13484(T)(void delegate(T) hi) { return 2; }

void test13484()
{
assert(foo13484({}) == 1); // works
assert(foo13484((float v){}) == 2); // works <- throws error
}

/******************************************/

int main()
Expand Down Expand Up @@ -4321,6 +4333,7 @@ int main()
test13374();
test13378();
test13379();
test13484();

printf("Success\n");
return 0;
Expand Down

0 comments on commit bfa9a00

Please sign in to comment.