Skip to content

Commit

Permalink
Fix assert failure on lambda parameter missing type. (#2011)
Browse files Browse the repository at this point in the history
  • Loading branch information
jemc authored and Benoit Vey committed Jul 5, 2017
1 parent 6ebdc7e commit 23d278e
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 8 deletions.
29 changes: 21 additions & 8 deletions src/libponyc/pass/syntax.c
Original file line number Diff line number Diff line change
Expand Up @@ -1063,12 +1063,13 @@ static ast_result_t syntax_lambda(pass_opt_t* opt, ast_t* ast)
pony_assert((ast_id(ast) == TK_LAMBDA) || (ast_id(ast) == TK_BARELAMBDA));
AST_GET_CHILDREN(ast, receiver_cap, name, t_params, params, captures,
ret_type, raises, body, reference_cap);
bool r = true;

if(ast_id(reference_cap) == TK_QUESTION)
{
ast_error(opt->check.errors, ast,
"lambda ... end is no longer supported syntax; use {...} for lambdas");
return AST_ERROR;
r = false;
}

switch(ast_id(ret_type))
Expand All @@ -1084,7 +1085,7 @@ static ast_result_t syntax_lambda(pass_opt_t* opt, ast_t* ast)
ast_print_type(ret_type));
ast_error_continue(opt->check.errors, ret_type, "lambda return type "
"cannot be capability");
return AST_ERROR;
r = false;
}
default: {}
}
Expand All @@ -1095,21 +1096,21 @@ static ast_result_t syntax_lambda(pass_opt_t* opt, ast_t* ast)
{
ast_error(opt->check.errors, receiver_cap, "a bare lambda cannot specify "
"a receiver capability");
return AST_ERROR;
r = false;
}

if(ast_id(t_params) != TK_NONE)
{
ast_error(opt->check.errors, t_params, "a bare lambda cannot specify "
"type parameters");
return AST_ERROR;
r = false;
}

if(ast_id(captures) != TK_NONE)
{
ast_error(opt->check.errors, captures, "a bare lambda cannot specify "
"captures");
return AST_ERROR;
r = false;
}

switch(ast_id(reference_cap))
Expand All @@ -1121,23 +1122,35 @@ static ast_result_t syntax_lambda(pass_opt_t* opt, ast_t* ast)
default:
ast_error(opt->check.errors, reference_cap, "a bare lambda can only "
"have a 'val' capability");
return AST_ERROR;
r = false;
}
}

ast_t* param = ast_child(params);
while(param != NULL)
{
if(ast_id(ast_childidx(param, 1)) == TK_NONE)
{
ast_error(opt->check.errors, param,
"a lambda parameter must specify a type");
r = false;
}
param = ast_sibling(param);
}

ast_t* capture = ast_child(captures);
while(capture != NULL)
{
if(ast_id(capture) == TK_THIS)
{
ast_error(opt->check.errors, capture,
"use a named capture to capture 'this'");
return AST_ERROR;
r = false;
}
capture = ast_sibling(capture);
}

return AST_OK;
return r ? AST_OK : AST_ERROR;
}


Expand Down
11 changes: 11 additions & 0 deletions test/libponyc/badpony.cc
Original file line number Diff line number Diff line change
Expand Up @@ -631,3 +631,14 @@ TEST_F(BadPonyTest, GenericMain)

TEST_ERRORS_1(src, "the Main actor cannot have type parameters");
}

TEST_F(BadPonyTest, LambdaParamNoType)
{
// From issue #2010
const char* src =
"actor Main\n"
" new create(e: Env) =>\n"
" {(x: USize, y): USize => x }";

TEST_ERRORS_1(src, "a lambda parameter must specify a type");
}

0 comments on commit 23d278e

Please sign in to comment.