Skip to content

Commit

Permalink
fix(fe): fix crash caught by fuzzing
Browse files Browse the repository at this point in the history
  • Loading branch information
strager committed Dec 29, 2023
1 parent c96f1a6 commit 540f7dd
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/quick-lint-js/fe/parse-type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -595,11 +595,17 @@ void Parser::parse_and_visit_typescript_type_expression_no_scope(
// | | Type // Invalid.
case Token_Type::ampersand:
case Token_Type::pipe:
this->diag_reporter_->report(
Diag_Missing_Type_Between_Intersection_Or_Union{
.left_operator = leading_binary_operator.value(),
.right_operator = this->peek().span(),
});
if (leading_binary_operator.has_value()) {
this->diag_reporter_->report(
Diag_Missing_Type_Between_Intersection_Or_Union{
.left_operator = leading_binary_operator.value(),
.right_operator = this->peek().span(),
});
} else {
// ? | Type
// NOTE(strager): We get here if we reported
// Diag_TypeScript_Question_In_Type_Expression_Should_Be_Void.
}
break;

// typeof varname
Expand Down
6 changes: 6 additions & 0 deletions test/test-parse-typescript-type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1071,6 +1071,12 @@ TEST_F(Test_Parse_TypeScript_Type, no_question_in_type_expression) {
u8"?Type"_sv, //
u8"^ Diag_TypeScript_Question_In_Type_Expression_Should_Be_Void"_diag, //
typescript_options);

// This used to crash quick-lint-js:
test_parse_and_visit_typescript_type_expression(
u8"? & Type"_sv, //
u8"^ Diag_TypeScript_Question_In_Type_Expression_Should_Be_Void"_diag, //
typescript_options);
}

TEST_F(Test_Parse_TypeScript_Type, generic_arrow_function) {
Expand Down

0 comments on commit 540f7dd

Please sign in to comment.