Skip to content

Commit

Permalink
fix(fe): don't report missing else for bad if expression
Browse files Browse the repository at this point in the history
  • Loading branch information
arieldon committed Oct 29, 2023
1 parent 640b5e7 commit 1bbf3f5
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/quick-lint-js/fe/parse.h
Original file line number Diff line number Diff line change
Expand Up @@ -1172,7 +1172,7 @@ void Parser::parse_and_visit_parenthesized_expression(

const Char8 *expression_begin = this->peek().begin;

Expression *ast = this->parse_expression(v);
Expression *ast = this->parse_expression(v, {.trailing_identifiers = true});
this->visit_expression(ast, v, Variable_Context::rhs);

if constexpr (check_for_sketchy_conditions) {
Expand Down
19 changes: 19 additions & 0 deletions test/test-parse-statement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -717,6 +717,25 @@ TEST_F(Test_Parse_Statement, else_without_if) {
"visit_exit_block_scope",
}));
}

{
Test_Parser p(
u8"if (e isntanceof DataNotLoadedError) { } else { throw e; }"_sv,
capture_diags);
p.parse_and_visit_statement();
EXPECT_THAT(p.visits,
ElementsAreArray({"visit_variable_use", // e
"visit_variable_use", // typoed instanceof
"visit_variable_use", // DataNotLoadedError
"visit_enter_block_scope", //
"visit_exit_block_scope", //
"visit_enter_block_scope", //
"visit_variable_use", // e
"visit_exit_block_scope"}));
EXPECT_THAT(
p.errors,
::testing::Not(::testing::Contains(DIAG_TYPE(Diag_Else_Has_No_If))));
}
}

TEST_F(Test_Parse_Statement, missing_if_after_else) {
Expand Down
5 changes: 3 additions & 2 deletions test/test-parse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -320,8 +320,9 @@ TEST_F(Test_Parse, utter_garbage) {
assert_diagnostics(
p.code, p.errors,
{
u8" ^ Diag_Expected_Parentheses_Around_If_Condition"_diag, //
u8" ^ Diag_Unexpected_Token"_diag,
u8" ^ Diag_Unexpected_Token"_diag, //
u8" ^^^^^^^^ Diag_Unexpected_Identifier_In_Expression"_diag, //
u8" ^^^^^^^^^^^ Diag_Expected_Parentheses_Around_If_Condition"_diag,
});
}
}
Expand Down

0 comments on commit 1bbf3f5

Please sign in to comment.