Skip to content

Commit e9e66b5

Browse files
committed
fix: prevent parser crash on invalid colon prefix in expressions
1 parent 9c1dde4 commit e9e66b5

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

argon/lang/parser2/parser2.cpp

+5-3
Original file line numberDiff line numberDiff line change
@@ -975,9 +975,11 @@ Node *Parser::ParseFuncNameParam(Context *context, bool parse_pexpr) {
975975

976976
bool identifier = false;
977977

978-
if (parse_pexpr)
978+
if (parse_pexpr) {
979979
id = this->ParseExpression(context, PeekPrecedence(TokenType::COMMA));
980-
else if (this->CheckIDExt()) {
980+
if (!id)
981+
throw ParserException(TKCUR_LOC, kStandardError[0]);
982+
} else if (this->CheckIDExt()) {
981983
id = Parser::ParseIdentifierSimple(&this->tkcur_);
982984
identifier = true;
983985

@@ -2637,7 +2639,7 @@ Node *Parser::ParsePrefix(Context *context) {
26372639
this->Eat(true);
26382640

26392641
auto *right = this->ParseExpression(context, PeekPrecedence(TokenType::ASTERISK));
2640-
if(right == nullptr)
2642+
if (right == nullptr)
26412643
throw ParserException(this->tkcur_.loc, kStandardError[0]);
26422644

26432645
auto *unary = NewNode<Unary>(type_ast_prefix_, false, NodeType::PREFIX);

0 commit comments

Comments
 (0)