From fb3dc2670a7d086933d056096cefd26362951e93 Mon Sep 17 00:00:00 2001 From: George Marques Date: Wed, 25 Nov 2020 11:35:07 -0300 Subject: [PATCH 1/2] GDScript: Fix range() being treated as array when optimized out The call of range() in a for loop is optimized to use int or vectors, to avoid allocating an array, however the type was set as array still. With the new typed VM this is an issue as the type mismatch the actual value, resulting in wrong instructions to be selected. --- modules/gdscript/gdscript_analyzer.cpp | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/modules/gdscript/gdscript_analyzer.cpp b/modules/gdscript/gdscript_analyzer.cpp index 6b23ab1616..851994eff3 100644 --- a/modules/gdscript/gdscript_analyzer.cpp +++ b/modules/gdscript/gdscript_analyzer.cpp @@ -978,7 +978,7 @@ void GDScriptAnalyzer::resolve_for(GDScriptParser::ForNode *p_for) { if (!call->arguments[i]->is_constant) { all_is_constant = false; - } else { + } else if (all_is_constant) { args.write[i] = call->arguments[i]->reduced_value; } @@ -1011,11 +1011,15 @@ void GDScriptAnalyzer::resolve_for(GDScriptParser::ForNode *p_for) { } } - GDScriptParser::DataType list_type; - list_type.type_source = GDScriptParser::DataType::ANNOTATED_EXPLICIT; - list_type.kind = GDScriptParser::DataType::BUILTIN; - list_type.builtin_type = Variant::ARRAY; - p_for->list->set_datatype(list_type); + if (p_for->list->is_constant) { + p_for->list->set_datatype(type_from_variant(p_for->list->reduced_value, p_for->list)); + } else { + GDScriptParser::DataType list_type; + list_type.type_source = GDScriptParser::DataType::ANNOTATED_EXPLICIT; + list_type.kind = GDScriptParser::DataType::BUILTIN; + list_type.builtin_type = Variant::ARRAY; + p_for->list->set_datatype(list_type); + } } } } From ed3d8f31df143337f43bb219da12f68f1d620df7 Mon Sep 17 00:00:00 2001 From: George Marques Date: Wed, 25 Nov 2020 11:37:51 -0300 Subject: [PATCH 2/2] GDScript: Fix return of cast expression on compilation It was mistakenly returning the source instead of the result. --- modules/gdscript/gdscript_compiler.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/gdscript/gdscript_compiler.cpp b/modules/gdscript/gdscript_compiler.cpp index 69fe6d27cc..499cd09b4e 100644 --- a/modules/gdscript/gdscript_compiler.cpp +++ b/modules/gdscript/gdscript_compiler.cpp @@ -437,7 +437,7 @@ GDScriptCodeGenerator::Address GDScriptCompiler::_parse_expression(CodeGen &code gen->pop_temporary(); } - return source; + return result; } break; case GDScriptParser::Node::CALL: { const GDScriptParser::CallNode *call = static_cast(p_expression);