diff options
-rw-r--r-- | compiler.c | 7 | ||||
-rw-r--r-- | tests/custom/04_bugs/37_compiler_unexpected_unary_op | 21 |
2 files changed, 28 insertions, 0 deletions
@@ -372,6 +372,13 @@ uc_compiler_parse_precedence(uc_compiler_t *compiler, uc_precedence_t precedence rule = uc_compiler_parse_rule(compiler->exprstack->token); + if (!rule->infix) { + uc_compiler_syntax_error(compiler, compiler->parser->curr.pos, "Expecting ';' or binary operator"); + uc_compiler_parse_advance(compiler); + + return; + } + /* allow reserved words in property accessors */ if (rule->infix == uc_compiler_compile_dot) compiler->parser->lex.no_keyword = true; diff --git a/tests/custom/04_bugs/37_compiler_unexpected_unary_op b/tests/custom/04_bugs/37_compiler_unexpected_unary_op new file mode 100644 index 0000000..e652319 --- /dev/null +++ b/tests/custom/04_bugs/37_compiler_unexpected_unary_op @@ -0,0 +1,21 @@ +When compiling expressions followed by a unary operator, the compiler +triggered a segmentation fault due to invoking an unset infix parser +routine. + +-- Testcase -- +1~1 +-- End -- + +-- Args -- +-R +-- End -- + +-- Expect stderr -- +Syntax error: Expecting ';' or binary operator +In line 1, byte 2: + + `1~1` + ^-- Near here + + +-- End -- |