diff --git a/src/expression.c b/src/expression.c index 2fdfdec7cad6..9ee0fa798bfb 100644 --- a/src/expression.c +++ b/src/expression.c @@ -988,8 +988,14 @@ Type *functionParameters(Loc loc, Scope *sc, TypeFunction *tf, for (size_t u = i; u < nargs; u++) { Expression *a = (*arguments)[u]; - if (tret && !((TypeArray *)tb)->next->equals(a->type)) - a = a->toDelegate(sc, tret); + TypeArray *ta = (TypeArray *)tb; + if (tret && !ta->next->equals(a->type)) + { if (tret->toBasetype()->ty == Tvoid || + a->implicitConvTo(tret)) + { + a = a->toDelegate(sc, tret); + } + } Expression *e = new VarExp(loc, v); e = new IndexExp(loc, e, new IntegerExp(u + 1 - nparams)); diff --git a/src/mtype.c b/src/mtype.c index 5cdc0272fad7..259b87416811 100644 --- a/src/mtype.c +++ b/src/mtype.c @@ -6009,7 +6009,6 @@ MATCH TypeFunction::callMatch(Expression *ethis, Expressions *args, int flag) { Expression *arg = (*args)[u]; assert(arg); -#if 1 if (arg->op == TOKfunction) { arg = ((FuncExp *)arg)->inferType(tb->nextOf(), 1); @@ -6024,23 +6023,19 @@ MATCH TypeFunction::callMatch(Expression *ethis, Expressions *args, int flag) if (tret) { if (ta->next->equals(arg->type)) - { m = MATCHexact; - } + m = MATCHexact; + else if (tret->toBasetype()->ty == Tvoid) + m = MATCHconvert; else { m = arg->implicitConvTo(tret); if (m == MATCHnomatch) - { - if (tret->toBasetype()->ty == Tvoid) - m = MATCHconvert; - } + m = arg->implicitConvTo(ta->next); } } else m = arg->implicitConvTo(ta->next); -#else - m = arg->implicitConvTo(ta->next); -#endif + if (m == MATCHnomatch) goto Nomatch; if (m < match) diff --git a/test/runnable/lazy.d b/test/runnable/lazy.d index 54d0d506be1e..18fbb3cc4a70 100644 --- a/test/runnable/lazy.d +++ b/test/runnable/lazy.d @@ -6,37 +6,38 @@ import std.stdio; void ifthen(bool cond, lazy void dg) { if (cond) - dg(); + dg(); } void ifthen(bool cond, lazy void dgthen, lazy void dgelse) { if (cond) - dgthen(); + dgthen(); else - dgelse(); + dgelse(); } void dotimes(int i, lazy int dg) { for (int j = 0; j < i; j++) - dg(); + dg(); } void switcher(bool delegate()[] cases...) { foreach (c; cases) { - if (c()) - break; + if (c()) + break; } } bool scase(bool b, lazy void dg) { if (b) - { dg(); - return true; + { + dg(); + return true; } return false; } @@ -50,7 +51,7 @@ bool sdefault(lazy void dg) void whiler(lazy bool cond, lazy void bdy) { while (cond()) - bdy(); + bdy(); } void test1() @@ -66,14 +67,14 @@ void test1() int v = 2; switcher( - scase(v == 1, printf("it is 1\n")), - scase(v == 2, printf("it is 2\n")), - scase(v == 3, printf("it is 3\n")), - sdefault( printf("it is default\n")) + scase(v == 1, printf("it is 1\n")), + scase(v == 2, printf("it is 2\n")), + scase(v == 3, printf("it is 3\n")), + sdefault( printf("it is default\n")) ); whiler( x < 100, - (printf("%d\n", x), x *= 2) + (printf("%d\n", x), x *= 2) ); } @@ -111,7 +112,6 @@ void abc3(int* p) void test3() { - int x = 3; dotimes3(10, abc3(&x)); dotimes3(10, write(++x)); @@ -143,8 +143,8 @@ void test4() { void *abc() { - writeln(cast(void*)&p4); - return cast(void*)&p4; + writeln(cast(void*)&p4); + return cast(void*)&p4; } foo4(&abc, cast(void* delegate())&abc, null, cast(void* delegate())null); @@ -154,18 +154,18 @@ void test4() bool nextis(void delegate() dgpositive = {}) { - return true; + return true; } bool looping(lazy bool condition) { - return true; + return true; } void test5() { - looping(nextis({})); - looping(nextis({})); + looping(nextis({})); + looping(nextis({})); } /*********************************************************/ @@ -182,7 +182,7 @@ int bar6() { return 3; } void test6() { - foo6(bar6(),"food_for_thought"); + foo6(bar6(),"food_for_thought"); } /*********************************************************/ @@ -232,6 +232,21 @@ void test6682() assert(purefunc6682() == 1); } +/*********************************************************/ +// 9109 + +void test9109() +{ + void foo(int delegate()[] dgs ...) + { + assert(dgs[0]() + dgs[1]() == 1 + 13); + } + + int x = 10; + int delegate() dg; + foo({ return 1; }, { return 3+x; }, dg, null); +} + /*********************************************************/ int main() @@ -246,6 +261,7 @@ int main() test5750a(); test5750b(); test6682(); + test9109(); printf("Success\n"); return 0;