Skip to content

Commit

Permalink
Properly report default argument inference errors (ponylang#2504)
Browse files Browse the repository at this point in the history
* Properly report default argument inference errors

errors for default arguments could leave the AST in an illegal state
which was causing assertions when evaluating default args during TK_CALL evaluation in the expr pass.

This PR makes those errors stop compilation immediately, so they are properly reported.

* use ast_passes_subtree instead of expr_seq for default arguments

as this does not result in double error messages when evaluating default args for function definitions and function calls
  • Loading branch information
mfelsche authored and dipinhora committed Jun 5, 2018
1 parent 8f3168d commit ad91145
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/libponyc/expr/call.c
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ static bool apply_default_arg(pass_opt_t* opt, ast_t* param, ast_t** argp)
ast_replace(argp, def_arg);
}

if(!expr_seq(opt, *argp))
if(!ast_passes_subtree(argp, opt, PASS_EXPR))
return false;

return true;
Expand Down
19 changes: 18 additions & 1 deletion test/libponyc/literal_inference.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
#define TEST_ERROR(src) DO(test_error(src, "expr"))
#define TEST_COMPILE(src) DO(test_compile(src, "expr"))

#define TEST_ERRORS_1(src, err1) \
{ const char* errs[] = {err1, NULL}; \
DO(test_expected_errors(src, "expr", errs)); }

class LiteralTest : public PassTest
{
Expand Down Expand Up @@ -243,7 +246,21 @@ TEST_F(LiteralTest, CantInfer_Let_InsufficientlySpecifiedGeneric)
" new create() =>\n"
" let x: A = 17";

TEST_ERROR(src);
TEST_ERRORS_1(src, "could not infer literal type, no valid types found");
}

TEST_F(LiteralTest, CantInfer_DefaultArg_InsufficientlySpecifiedGeneric)
{
const char* src =
"class Foo[A]\n"
" new create(field: A = 0) =>\n"
" None\n"
"\n"
"class Bar\n"
" new create() =>\n"
" let foo = Foo[U16]()";

TEST_ERRORS_1(src, "could not infer literal type, no valid types found");
}


Expand Down

0 comments on commit ad91145

Please sign in to comment.