Skip to content

Commit

Permalink
Merge pull request #82004 from dalexeev/4.1-gds-fix-pot-gen-crash-on-…
Browse files Browse the repository at this point in the history
…assignee-with-index

[4.1] GDScript: Fix POT generator crash on assignee with index
  • Loading branch information
akien-mga authored Sep 20, 2023
2 parents f2c8eea + 676013c commit daedd12
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions modules/gdscript/editor/gdscript_translation_parser_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,18 +218,23 @@ void GDScriptEditorTranslationParserPlugin::_assess_assignment(GDScriptParser::A
if (p_assignment->assignee->type == GDScriptParser::Node::IDENTIFIER) {
assignee_name = static_cast<GDScriptParser::IdentifierNode *>(p_assignment->assignee)->name;
} else if (p_assignment->assignee->type == GDScriptParser::Node::SUBSCRIPT) {
assignee_name = static_cast<GDScriptParser::SubscriptNode *>(p_assignment->assignee)->attribute->name;
const GDScriptParser::SubscriptNode *subscript = static_cast<const GDScriptParser::SubscriptNode *>(p_assignment->assignee);
if (subscript->is_attribute && subscript->attribute) {
assignee_name = subscript->attribute->name;
} else if (subscript->index && subscript->index->type == GDScriptParser::Node::LITERAL) {
assignee_name = static_cast<GDScriptParser::LiteralNode *>(subscript->index)->value;
}
}

if (assignment_patterns.has(assignee_name) && p_assignment->assigned_value->type == GDScriptParser::Node::LITERAL) {
if (assignee_name != StringName() && assignment_patterns.has(assignee_name) && p_assignment->assigned_value->type == GDScriptParser::Node::LITERAL) {
// If the assignment is towards one of the extract patterns (text, tooltip_text etc.), and the value is a string literal, we collect the string.
ids->push_back(static_cast<GDScriptParser::LiteralNode *>(p_assignment->assigned_value)->value);
} else if (assignee_name == fd_filters && p_assignment->assigned_value->type == GDScriptParser::Node::CALL) {
// FileDialog.filters accepts assignment in the form of PackedStringArray. For example,
// get_node("FileDialog").filters = PackedStringArray(["*.png ; PNG Images","*.gd ; GDScript Files"]).

GDScriptParser::CallNode *call_node = static_cast<GDScriptParser::CallNode *>(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) {
GDScriptParser::ArrayNode *array_node = static_cast<GDScriptParser::ArrayNode *>(call_node->arguments[0]);

// Extract the name in "extension ; name" of PackedStringArray.
Expand Down

0 comments on commit daedd12

Please sign in to comment.