2
0
Fork 0

GDScript: Properly catch error when missing index in subscript

4.0
George Marques 2021-09-17 14:31:51 +07:00
parent b8fdeb6467
commit 651319de11
No known key found for this signature in database
GPG Key ID: 046BD46A3201E43D
3 changed files with 9 additions and 0 deletions

@ -2592,6 +2592,10 @@ GDScriptParser::ExpressionNode *GDScriptParser::parse_subscript(ExpressionNode *
subscript->base = p_previous_operand;
subscript->index = parse_expression(false);
if (subscript->index == nullptr) {
push_error(R"(Expected expression after "[".)");
}
pop_multiline();
consume(GDScriptTokenizer::Token::BRACKET_CLOSE, R"(Expected "]" after subscription index.)");

@ -0,0 +1,3 @@
func test():
var array = [1, 2, 3]
array[] = 4

@ -0,0 +1,2 @@
GDTEST_PARSER_ERROR
Expected expression after "[".