From 79578a5625f297dae632edc2a3aa385ccdb26ab3 Mon Sep 17 00:00:00 2001 From: Louis Dumont Date: Wed, 25 Aug 2021 18:32:24 +0200 Subject: Fixed crash when parsing an empty assignment. Resolves #51620. --- modules/gdscript/gdscript_parser.cpp | 3 +++ .../gdscript/tests/scripts/parser/errors/assignment_empty_assignee.gd | 3 +++ .../gdscript/tests/scripts/parser/errors/assignment_empty_assignee.out | 2 ++ 3 files changed, 8 insertions(+) create mode 100644 modules/gdscript/tests/scripts/parser/errors/assignment_empty_assignee.gd create mode 100644 modules/gdscript/tests/scripts/parser/errors/assignment_empty_assignee.out (limited to 'modules/gdscript') diff --git a/modules/gdscript/gdscript_parser.cpp b/modules/gdscript/gdscript_parser.cpp index af872e49e2..029e30080b 100644 --- a/modules/gdscript/gdscript_parser.cpp +++ b/modules/gdscript/gdscript_parser.cpp @@ -2365,6 +2365,9 @@ GDScriptParser::ExpressionNode *GDScriptParser::parse_assignment(ExpressionNode } assignment->assignee = p_previous_operand; assignment->assigned_value = parse_expression(false); + if (assignment->assigned_value == nullptr) { + push_error(R"(Expected an expression after "=".)"); + } #ifdef DEBUG_ENABLED if (has_operator && source_variable != nullptr && source_variable->assignments == 0) { diff --git a/modules/gdscript/tests/scripts/parser/errors/assignment_empty_assignee.gd b/modules/gdscript/tests/scripts/parser/errors/assignment_empty_assignee.gd new file mode 100644 index 0000000000..17c65ad60a --- /dev/null +++ b/modules/gdscript/tests/scripts/parser/errors/assignment_empty_assignee.gd @@ -0,0 +1,3 @@ +func test(): + var a = 0 + a = diff --git a/modules/gdscript/tests/scripts/parser/errors/assignment_empty_assignee.out b/modules/gdscript/tests/scripts/parser/errors/assignment_empty_assignee.out new file mode 100644 index 0000000000..1369a7a0dc --- /dev/null +++ b/modules/gdscript/tests/scripts/parser/errors/assignment_empty_assignee.out @@ -0,0 +1,2 @@ +GDTEST_PARSER_ERROR +Expected an expression after "=". -- cgit v1.2.3