From c7511de02e9123aadf4b81d3bef934fab27649e3 Mon Sep 17 00:00:00 2001 From: George Marques Date: Fri, 23 Apr 2021 15:42:33 -0300 Subject: [PATCH] GDScript: Fix resolution of dictionary keys There was a mixup between String and StringName keys. Now they're clearly separated. This also means you have to consider which type you're using for the dictionary keys and how you are accessing them. --- modules/gdscript/gdscript_analyzer.cpp | 24 ++++-------------------- modules/gdscript/gdscript_compiler.cpp | 4 ++-- 2 files changed, 6 insertions(+), 22 deletions(-) diff --git a/modules/gdscript/gdscript_analyzer.cpp b/modules/gdscript/gdscript_analyzer.cpp index bdca64c146e..5da2bb5cc18 100644 --- a/modules/gdscript/gdscript_analyzer.cpp +++ b/modules/gdscript/gdscript_analyzer.cpp @@ -2621,25 +2621,6 @@ void GDScriptAnalyzer::reduce_subscript(GDScriptParser::SubscriptNode *p_subscri GDScriptParser::DataType result_type; - // Reduce index first. If it's a constant StringName, use attribute instead. - if (!p_subscript->is_attribute) { - if (p_subscript->index == nullptr) { - return; - } - reduce_expression(p_subscript->index); - - if (p_subscript->index->is_constant && p_subscript->index->reduced_value.get_type() == Variant::STRING_NAME) { - GDScriptParser::IdentifierNode *attribute = parser->alloc_node(); - // Copy location for better error message. - attribute->start_line = p_subscript->index->start_line; - attribute->end_line = p_subscript->index->end_line; - attribute->leftmost_column = p_subscript->index->leftmost_column; - attribute->rightmost_column = p_subscript->index->rightmost_column; - p_subscript->is_attribute = true; - p_subscript->attribute = attribute; - } - } - if (p_subscript->is_attribute) { if (p_subscript->attribute == nullptr) { return; @@ -2682,7 +2663,10 @@ void GDScriptAnalyzer::reduce_subscript(GDScriptParser::SubscriptNode *p_subscri } } } else { - // Index was already reduced before. + if (p_subscript->index == nullptr) { + return; + } + reduce_expression(p_subscript->index); if (p_subscript->base->is_constant && p_subscript->index->is_constant) { // Just try to get it. diff --git a/modules/gdscript/gdscript_compiler.cpp b/modules/gdscript/gdscript_compiler.cpp index 7429e3cc0b2..060ee7b058e 100644 --- a/modules/gdscript/gdscript_compiler.cpp +++ b/modules/gdscript/gdscript_compiler.cpp @@ -680,9 +680,9 @@ GDScriptCodeGenerator::Address GDScriptCompiler::_parse_expression(CodeGen &code name = subscript->attribute->name; named = true; } else { - if (subscript->index->type == GDScriptParser::Node::LITERAL && static_cast(subscript->index)->value.get_type() == Variant::STRING) { + if (subscript->index->is_constant && subscript->index->reduced_value.get_type() == Variant::STRING_NAME) { // Also, somehow, named (speed up anyway). - name = static_cast(subscript->index)->value; + name = subscript->index->reduced_value; named = true; } else { // Regular indexing.