From 9d10647f3f01fd38b260a4c2308cadaa1bc43248 Mon Sep 17 00:00:00 2001 From: Matthias Wahl Date: Mon, 19 Mar 2018 17:07:28 +0100 Subject: [PATCH 1/2] add NULL check to array inference code that can possibly return null. fixes #2602 --- src/libponyc/expr/array.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/libponyc/expr/array.c b/src/libponyc/expr/array.c index 5821a435fa..e8f30e93e9 100644 --- a/src/libponyc/expr/array.c +++ b/src/libponyc/expr/array.c @@ -250,8 +250,9 @@ static bool infer_element_type(pass_opt_t* opt, ast_t* ast, { ast_t* dot = ast_parent(ast); antecedent_type = find_antecedent_type(opt, dot, NULL); - find_possible_iterator_element_types(opt, antecedent_type, - &possible_element_types); + if (antecedent_type != NULL) + find_possible_iterator_element_types(opt, antecedent_type, + &possible_element_types); } } From 836b42518fdf6598de532ebce036d41224ce7656 Mon Sep 17 00:00:00 2001 From: Matthias Wahl Date: Wed, 21 Mar 2018 22:17:32 +0100 Subject: [PATCH 2/2] add a badpony test case for Issue #2602 to ensure pony properly reports the error and does not assert --- test/libponyc/badpony.cc | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/test/libponyc/badpony.cc b/test/libponyc/badpony.cc index ddffc23c35..e6f5186a1c 100644 --- a/test/libponyc/badpony.cc +++ b/test/libponyc/badpony.cc @@ -988,3 +988,19 @@ TEST_F(BadPonyTest, IsComparingCreateSugar) DO(test_expected_errors(src, "refer", errs)); } } + +TEST_F(BadPonyTest, TypeErrorDuringArrayLiteralInference) +{ + // From issue 2602 + const char* src = + "class C\n" + "trait X\n" + "class ExpectX[T: X]\n" + " fun trigger(arg: Iterator[T]) =>\n" + " None\n" + + "actor Main\n" + " new create(env: Env) =>\n" + " ExpectX[C].trigger([C; C].values())"; + TEST_ERRORS_1(src, "type argument is outside its constraint"); +}