Skip to content

Commit

Permalink
Fix compiler crash when a field is used in a default argument.
Browse files Browse the repository at this point in the history
This was broken as a side effect the placement of a check
introduced in #1858, and was fixed by just changing the order
of the checks so that we don't expect to be in a method body frame
if we are in a default argument frame.
  • Loading branch information
jemc committed Jun 3, 2017
1 parent d5e1966 commit 59e2a5d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/libponyc/expr/reference.c
Original file line number Diff line number Diff line change
Expand Up @@ -624,17 +624,17 @@ bool expr_digestof(pass_opt_t* opt, ast_t* ast)

bool expr_this(pass_opt_t* opt, ast_t* ast)
{
if(ast_id(ast_child(opt->check.frame->method)) == TK_AT)
if(opt->check.frame->def_arg != NULL)
{
ast_error(opt->check.errors, ast,
"can't reference 'this' in a bare method");
"can't reference 'this' in a default argument");
return false;
}

if(opt->check.frame->def_arg != NULL)
if(ast_id(ast_child(opt->check.frame->method)) == TK_AT)
{
ast_error(opt->check.errors, ast,
"can't reference 'this' in a default argument");
"can't reference 'this' in a bare method");
return false;
}

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

TEST_ERRORS_1(src, "not enough type arguments");
}

TEST_F(BadPonyTest, FieldReferenceInDefaultArgument)
{
const char* src =
"actor Main\n"
" let _env: Env\n"
" new create(env: Env) =>\n"
" _env = env\n"
" foo()\n"
" fun foo(env: Env = _env) =>\n"
" None";

TEST_ERRORS_1(src, "can't reference 'this' in a default argument");
}

0 comments on commit 59e2a5d

Please sign in to comment.