Skip to content

Commit

Permalink
fix Issue 8836 - function called with argument types ((void function(…
Browse files Browse the repository at this point in the history
…))) matches both f(void function() fn) and f(void delegate() dg)
  • Loading branch information
9rnsr committed Oct 19, 2012
1 parent dafb742 commit b927f98
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
13 changes: 6 additions & 7 deletions src/cast.c
Original file line number Diff line number Diff line change
Expand Up @@ -767,21 +767,20 @@ MATCH FuncExp::implicitConvTo(Type *t)
{
//printf("FuncExp::implicitConvTo type = %p %s, t = %s\n", type, type ? type->toChars() : NULL, t->toChars());
Expression *e = inferType(t, 1);
if (e)
if (e &&
(t->ty == Tdelegate ||
t->ty == Tpointer && t->nextOf()->ty == Tfunction))
{
if (e != this)
return e->implicitConvTo(t);

/* MATCHconst: Conversion from implicit to explicit function pointer
* MATCHconvert: Conversion from impliict funciton pointer to delegate
*/
if (tok == TOKreserved && type->ty == Tpointer &&
(t->ty == Tpointer || t->ty == Tdelegate))
if (fd->tok == TOKreserved && // fbody doesn't have a frame pointer
(type->equals(t) || type->nextOf()->covariant(t->nextOf()) == 1))
{
if (type == t)
return MATCHexact;
if (type->nextOf()->covariant(t->nextOf()) == 1)
return t->ty == Tpointer ? MATCHconst : MATCHconvert;
return t->ty == Tpointer ? MATCHconst : MATCHconvert;
}
}
return Expression::implicitConvTo(t);
Expand Down
7 changes: 7 additions & 0 deletions test/runnable/funclit.d
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,8 @@ void tfun4c(T)(T f){}
void test4()
{
int v;
static void sfoo() {}
void nfoo() {}

// parameter type inference + overload resolution
assert(foo4((a) => a * 2) == 20);
Expand All @@ -158,8 +160,13 @@ void test4()
// function/delegate inference + overload resolution
assert(nbaz4({ }) == 1);
assert(nbaz4({ v = 1; }) == 2);
assert(nbaz4({ sfoo(); }) == 1); // Bugzilla 8836
assert(nbaz4({ nfoo(); }) == 2);

assert(tbaz4({ }) == 1);
assert(tbaz4({ v = 1; }) == 2);
assert(tbaz4({ sfoo(); }) == 1);
assert(tbaz4({ nfoo(); }) == 2);

// template function deduction
static assert(is(typeof(thoo4({ })) : void function()));
Expand Down

0 comments on commit b927f98

Please sign in to comment.