Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #809 from 9rnsr/fix_funclit
Issue 7705 - lambda syntax doesn't allow some valid signatures
  • Loading branch information
WalterBright committed Mar 14, 2012
2 parents c59df76 + a0b91bf commit dc89c64
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/parse.c
Expand Up @@ -1377,8 +1377,10 @@ Parameters *Parser::parseParameters(int *pvarargs, TemplateParameters **tpl)
error("scope cannot be ref or out");

Token *t;
if (tpl && !stc && token.value == TOKidentifier &&
(t = peek(&token), (t->value == TOKcomma || t->value == TOKrparen)))
if (tpl && token.value == TOKidentifier &&
(t = peek(&token), (t->value == TOKcomma ||
t->value == TOKrparen ||
t->value == TOKdotdotdot)))
{ Identifier *id = Lexer::uniqueId("__T");
at = new TypeIdentifier(loc, id);
if (!*tpl)
Expand Down
17 changes: 17 additions & 0 deletions test/runnable/funclit.d
Expand Up @@ -486,6 +486,22 @@ void test7650()
assert(aa4[2](10) == 30);
}

/***************************************************/
// 7705

void test7705()
{
void foo1(void delegate(ref int ) dg){ int x=10; dg(x); }
foo1((ref x){ pragma(msg, typeof(x)); assert(x == 10); });
static assert(!__traits(compiles, foo1((x){}) ));

void foo2(void delegate(int, ...) dg){ dg(20, 3.14); }
foo2((x,...){ pragma(msg, typeof(x)); assert(x == 20); });

void foo3(void delegate(int[]...) dg){ dg(1, 2, 3); }
foo3((x ...){ pragma(msg, typeof(x)); assert(x == [1,2,3]); });
}

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

int main()
Expand Down Expand Up @@ -513,6 +529,7 @@ int main()
test7582();
test7649();
test7650();
test7705();

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

0 comments on commit dc89c64

Please sign in to comment.