Skip to content

Commit

Permalink
Fix compiler crash on non-existent field reference in constructor.
Browse files Browse the repository at this point in the history
Resolves #1932.
  • Loading branch information
jemc authored and SeanTAllen committed Jun 3, 2017
1 parent d5e1966 commit 19118c0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/libponyc/pass/refer.c
Original file line number Diff line number Diff line change
Expand Up @@ -633,7 +633,9 @@ static bool is_lvalue(pass_opt_t* opt, ast_t* ast, bool need_value)
if(ast_id(left) == TK_THIS)
{
ast_t* def = (ast_t*)ast_data(ast);
pony_assert(def != NULL);

if(def == NULL)
return false;

switch(ast_id(def))
{
Expand Down
13 changes: 13 additions & 0 deletions test/libponyc/badpony.cc
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,19 @@ TEST_F(BadPonyTest, CallArgTypeErrorInsideTuple)
TEST_ERRORS_1(src, "argument not a subtype of parameter");
}

TEST_F(BadPonyTest, NonExistFieldReferenceInConstructor)
{
// From issue #1932
const char* src =
"actor Main\n"
" new create(env: Env) =>\n"
" this.x = None";

TEST_ERRORS_2(src,
"can't find declaration of 'x'",
"left side must be something that can be assigned to");
}

TEST_F(BadPonyTest, TypeArgErrorInsideReturn)
{
const char* src =
Expand Down

0 comments on commit 19118c0

Please sign in to comment.