From 8d3d38f27fabeddaedb9fed7893f807fc5f09503 Mon Sep 17 00:00:00 2001 From: Joe Eli McIlvain Date: Fri, 2 Jun 2017 23:58:54 -0700 Subject: [PATCH] Fix compiler crash on non-existent field reference in constructor. Resolves #1932. --- src/libponyc/pass/refer.c | 4 +++- test/libponyc/badpony.cc | 13 +++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/libponyc/pass/refer.c b/src/libponyc/pass/refer.c index 0482e84b34..bddfcd550c 100644 --- a/src/libponyc/pass/refer.c +++ b/src/libponyc/pass/refer.c @@ -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)) { diff --git a/test/libponyc/badpony.cc b/test/libponyc/badpony.cc index 26385cb12b..1e364738a6 100644 --- a/test/libponyc/badpony.cc +++ b/test/libponyc/badpony.cc @@ -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 =