From d991cc49985cfa62f69f27b20989db1d10477f89 Mon Sep 17 00:00:00 2001 From: Danil Alexeev Date: Thu, 14 Sep 2023 17:41:05 +0300 Subject: [PATCH] GDScript: Fix POT generator crash on assignee with index --- .../editor/gdscript_translation_parser_plugin.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/modules/gdscript/editor/gdscript_translation_parser_plugin.cpp b/modules/gdscript/editor/gdscript_translation_parser_plugin.cpp index 064143f40005..becc2876f9ca 100644 --- a/modules/gdscript/editor/gdscript_translation_parser_plugin.cpp +++ b/modules/gdscript/editor/gdscript_translation_parser_plugin.cpp @@ -225,10 +225,15 @@ void GDScriptEditorTranslationParserPlugin::_assess_assignment(const GDScriptPar if (p_assignment->assignee->type == GDScriptParser::Node::IDENTIFIER) { assignee_name = static_cast(p_assignment->assignee)->name; } else if (p_assignment->assignee->type == GDScriptParser::Node::SUBSCRIPT) { - assignee_name = static_cast(p_assignment->assignee)->attribute->name; + const GDScriptParser::SubscriptNode *subscript = static_cast(p_assignment->assignee); + if (subscript->is_attribute && subscript->attribute) { + assignee_name = subscript->attribute->name; + } else if (subscript->index && _is_constant_string(subscript->index)) { + assignee_name = subscript->index->reduced_value; + } } - if (assignment_patterns.has(assignee_name) && _is_constant_string(p_assignment->assigned_value)) { + if (assignee_name != StringName() && assignment_patterns.has(assignee_name) && _is_constant_string(p_assignment->assigned_value)) { // If the assignment is towards one of the extract patterns (text, tooltip_text etc.), and the value is a constant string, we collect the string. ids->push_back(p_assignment->assigned_value->reduced_value); } else if (assignee_name == fd_filters && p_assignment->assigned_value->type == GDScriptParser::Node::CALL) { @@ -236,7 +241,7 @@ void GDScriptEditorTranslationParserPlugin::_assess_assignment(const GDScriptPar // get_node("FileDialog").filters = PackedStringArray(["*.png ; PNG Images","*.gd ; GDScript Files"]). const GDScriptParser::CallNode *call_node = static_cast(p_assignment->assigned_value); - if (call_node->arguments[0]->type == GDScriptParser::Node::ARRAY) { + if (!call_node->arguments.is_empty() && call_node->arguments[0]->type == GDScriptParser::Node::ARRAY) { const GDScriptParser::ArrayNode *array_node = static_cast(call_node->arguments[0]); // Extract the name in "extension ; name" of PackedStringArray.