2
0
Эх сурвалжийг харах

Merge pull request #52792 from vnen/gdscript-subscript-missing-index

Rémi Verschelde 4 жил өмнө
parent
commit
424ddcba37

+ 4 - 0
modules/gdscript/gdscript_parser.cpp

@@ -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.)");
 

+ 3 - 0
modules/gdscript/tests/scripts/parser/errors/subscript_without_index.gd

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

+ 2 - 0
modules/gdscript/tests/scripts/parser/errors/subscript_without_index.out

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